Oracle Memory Structure

2
© Copy Right: Rai University 3E.672/3B.581 21 ORACLE DA T ABASE ADMINISTRA TION UNIT 2 LESSON 8: ORACLE MEMORY STRUCTURE This lesson provides an insight into Overview of Oracle Memory Structures System Global Area Programme Global Area Software Code Area Introduction The memory structures of any database are used to cache application data, data dictionary information which contains metadata etc, SQL commands, PL/SQL and Java program units, transaction information, data required for execution of individual database requests, and other control information. Memory structures are allocated to the Oracle instance when the instance is started. The two major memory structures are known as the System Global Area (also called the Shared Global Area) and the Program Global Area or the Process Global Area. Figure illustrates the various memory structures in Oracle. System Global Area The System Global Area is a shared memory area, the information of which is shared by all the users of the database. Oracle instance is constituted by the SGA and the background processes. Oracle allocates memory of the SGA when an Oracle instance is started and de-allocates it when the instance is shut down. The information stored in the SGA is divided into multiple memory structures that are allocated fixed space when the instance is started. The various components of SGA are as follows: 1. Database buffer cache The database buffer cache caches the database data, holding blocks from the data files that have been recently read. The database buffer cache is shared among all the users connected to the database. There are three types of buffers: Dirty buffers: Dirty buffers need to be written to the data file. The data in these buffers has changed and has not yet been written to the disk. Free buffers: Free buffers are the buffer blocks that do not contain any data or are free to be over-written. When Oracle reads data from disk, free buffers are used to hold this data. Pinned buffers: Pinned buffers are the buffers that are currently being accessed or explicitly retained for future use. For example, the KEEP buffer pool. To manage the buffer cache, two lists are maintained by Oracle: 1. The write list contains the buffers that are modified and need to be written to the disk (the dirty buffers). It is also called as dirty buffer list. 2. The least recently used (LRU) list contains free buffers, pinned buffers, and the dirty buffers that have not yet been moved to the write list. Consider the LRU list as a queue of blocks, where the most recently accessed blocks are always in the front(known as the most recently used , or MRU, end of the list; the other end, where the least recently accessed blocks are, is the LRU end). However the least used blocks are thrown out of the list when new blocks are accessed and are added to the list. When an Oracle process accesses a buffer, it is moved to MRU end of the list. So the most frequently accessed data is available in the buffers. When new data buffers are moved to the LRU list, they are copied to the MRU end of the list, pushing out the buffers from the LRU end. An exception to this occurs when a full table scan is done and the blocks from a full table scan are written to the LRU end of the list. When an Oracle process requests data, it searches the data in the buffer cache, and if it finds data, the result is a cached hit. If it cannot find the data, the result is a cache miss, and data then needs to be copied from disk to the buffer. Before reading a data into cached, the process must first find a free buffer. The server process on behalf of the process searched either until it finds a free buffer or until it has searched the threshold limit of buffers. If the server process finds a dirty buffer as it searches the LRU list, it moves that buffer to the write list and continues to search. When the process finds a free buffer, it reads the data block from the disk into the buffer and moves the buffer to the MRU end of the LRU list. If an Oracle server process searches the threshold limit of buffer without finding a free buffer, the process stops searching and signals the DBWn background process to write some of the dirty buffers to disk.

Transcript of Oracle Memory Structure

Page 1: Oracle Memory Structure

© Copy Right: Rai University3E.672/3B.581 21

OR

AC

LE D

ATA

BA

SE

AD

MIN

IST

RA

TIO

NUNIT 2

LESSON 8:ORACLE MEMORY STRUCTURE

This lesson provides an insight into• Overview of Oracle Memory Structures• System Global Area• Programme Global Area• Software Code Area

IntroductionThe memory structures of any database are used to cacheapplication data, data dictionary information which containsmetadata etc, SQL commands, PL/SQL and Java programunits, transaction information, data required for execution ofindividual database requests, and other control information.Memory structures are allocated to the Oracle instance when theinstance is started. The two major memory structures areknown as the System Global Area (also called the SharedGlobal Area) and the Program Global Area or the ProcessGlobal Area.

Figure illustrates the various memory structures in Oracle.

System Global AreaThe System Global Area is a shared memory area, theinformation of which is shared by all the users of the database.Oracle instance is constituted by the SGA and the backgroundprocesses. Oracle allocates memory of the SGA when an Oracleinstance is started and de-allocates it when the instance is shutdown. The information stored in the SGA is divided intomultiple memory structures that are allocated fixed space whenthe instance is started.The various components of SGA are as follows:

1. Database buffer cache

The database buffer cache caches the database data, holdingblocks from the data files that have been recently read. Thedatabase buffer cache is shared among all the users connected tothe database. There are three types of buffers:• Dirty buffers: Dirty buffers need to be written to the data

file. The data in these buffers has changed and has not yetbeen written to the disk.

• Free buffers: Free buffers are the buffer blocks that do notcontain any data or are free to be over-written. When Oraclereads data from disk, free buffers are used to hold this data.

• Pinned buffers: Pinned buffers are the buffers that arecurrently being accessed or explicitly retained for future use.For example, the KEEP buffer pool.

To manage the buffer cache, two lists are maintained by Oracle:1. The write list contains the buffers that are modified and

need to be written to the disk (the dirty buffers). It is alsocalled as dirty buffer list.

2. The least recently used (LRU) list contains free buffers,pinned buffers, and the dirty buffers that have not yet beenmoved to the write list. Consider the LRU list as a queue ofblocks, where the most recently accessed blocks are always inthe front(known as the most recently used , or MRU, endof the list; the other end, where the least recently accessedblocks are, is the LRU end). However the least used blocksare thrown out of the list when new blocks are accessed andare added to the list.

When an Oracle process accesses a buffer, it is moved to MRUend of the list. So the most frequently accessed data is availablein the buffers. When new data buffers are moved to the LRUlist, they are copied to the MRU end of the list, pushing out thebuffers from the LRU end. An exception to this occurs when afull table scan is done and the blocks from a full table scan arewritten to the LRU end of the list. When an Oracle processrequests data, it searches the data in the buffer cache, and if itfinds data, the result is a cached hit. If it cannot find the data,the result is a cache miss, and data then needs to be copied fromdisk to the buffer.Before reading a data into cached, the process must first find afree buffer. The server process on behalf of the processsearched either until it finds a free buffer or until it has searchedthe threshold limit of buffers. If the server process finds a dirtybuffer as it searches the LRU list, it moves that buffer to thewrite list and continues to search. When the process finds a freebuffer, it reads the data block from the disk into the buffer andmoves the buffer to the MRU end of the LRU list. If an Oracleserver process searches the threshold limit of buffer withoutfinding a free buffer, the process stops searching and signals theDBWn background process to write some of the dirty buffersto disk.

Page 2: Oracle Memory Structure

22 3E.672/3B.581© Copy Right: Rai University

OR

AC

LE D

ATA

BA

SE

AD

MIN

IST

RA

TIO

N

Oracle8i lets you divide the buffer pool into three areas:• The KEEP buffer pool retains the data blocks in memory;

they are not aged out.• The RECYCLE buffer pool removes the buffers from

memory as soon as they are not needed.• The DEFAULT buffer pool contains the blocks that are not

assigned to the other pools.

2. Redo log bufferThe redo log buffer is a circular buffer in the SGA. It holdsinformation about the changes, which are made to the databasedata. Such changes are known as redo entries or change vectorsand are used to redo the changes in case of any failure. Changesare made to the database through any of these commands:INSERT, UPDATE, DELETE, CREATE, ALTER, or DROP.The parameter LOG_BUFFER determines the size of the redolog buffer.

3. Shared PoolThis portion of the SGA holds information like SQL, PL/SQLprocedures and packages, the data dictionary, character setinformation, locks, security attributes, and so on. The parameterSHARED_POOL_SIZE is used to determine the size of theshared pool.The shared pool further consists of the library cache and thedictionary cache.

• Library Cache

The library cache contains the shared and private SQL areas, PL/SQL procedures and packages and control structures such aslocks and library cache handles. The shared SQL area maintainsrecently executed SQL commands and their execution plans.Each SQL statement executed is divided into a shared area and aprivate SQL area by Oracle.When two users are executing the same SQL, the informationin the shared SQL area is used for both. The shared SQL areacontains the parse tree and execution plan, whereas the privateSQL area contains values for the bind variables (persistent area)and runtime buffers (runtime area). Oracle creates the runtimearea as the first step of an execute request. For INSERT,UPDATE, and DELETE statements, Oracle frees the runtimearea after the statement has been executed. For queries, Oraclefrees the runtime area only after all rows have been fetched orthe query has been canceled.PL/SQL program units are processed the same way as SQLstatements by Oracle. When a PL/SQL program unit isexecuted, the code is moved to the shared PL/SQL area whilethe individual SQL commands within the program unit aremoved to the shared SQL area. Again, the shared program unitsare maintained in memory with an LRU algorithm.The third area of the library cache is maintained for internal useby the instance. Various locks, latched, and other controlstructures reside here and are freely accessed by any serverprocesses requiring this information.

• Data dictionary cacheThe data dictionary is nothing, but a collection of databasetables and views containing metadata about the database, its

structures, its privileges, and its users. Oracle accesses the datadictionary frequently during the parsing of SQL statements.The data dictionary cache holds the most recently used databasedictionary information. The data dictionary cache is also knownas the row cache because it holds data as rows instead of buffers(which hold entire blocks of data).

4. Large poolThe Large pool is a voluntary area in the SGA that can beconfigured by the database administrator to provide largememory allocations for specific database operations such as anOracle backup or restore. The large pool allows Oracle to requestlarge memory allocations from a separate pool to preventcontention from other applications for the same memory. Thelarge pool does not have an LRU list. The parameterLARGE_POOL_SIZE specifies the size of the large pool.

Programme Global AreaThis is another memory structure of Oracle. The ProgramGlobal Area (PGA) is the area in the memory that contains thedata and process information for one process. This area is non-shared memory. The PGA size is fixed and is dependent on theoperating system. The contents of the PGA vary depending onthe server configuration.• For a dedicated server configuration, the PGA holds stack

space and sessions information.• For multithreaded configurations (where user connections

go through a dispatcher, a smaller number of serverprocesses are required as they can be shared by multiple userprocesses), the PGA contains the stack space information.In that case the session information is in the SGA.

The memory allocated to hold variables, arrays, and otherinformation that belongs to the session is called stake space.PGA is allocated when the process is completed. Unlike theSGA that is shared by several processes, the PGA provides sortspace, session information, stack space, and cursor informationfor a single server process.

Sort areaThe memory area that Oracle uses to sort data is known as thesort area, which uses memory from the PGA for a dedicatedserver connection. For multithreaded server configurations, thesort area is allocated from the SGA. Sort area size can growdepending on the need. The parameterSORT_AREA_RETAINED_SIZE determines the size towhich the sort area is reduced after the sort operation. Thememory released from the sort area is kept with the serverprocess; it is not released to the operating system.

Software Code AreaThis is another portion of the memory. Software code areas arethe portions of memory that are used to store the code that isbeing executed. Software code areas are mostly static in size andare dependent on the operating system. These areas are read-only and can be shared (if the operating system allows), somultiple copies of the same code are not kept in memory. SomeOracle tools and utilities (such as SQL * Forms and SQL *Plus) can be installed shared, but some cannot. Multipleinstances of Oracle can use the same Oracle code area withdifferent databases if running on the same computer.