Wednesday, August 26, 2009

Oracle Server Architecture


An Oracle Server consists of an Oracle Database and an Oracle Instance. Everytime a database is started a System Global Area (SGA) is allocated in the memory and Oracle Background processes are started. The combination of background processes and SGA is called an Oracle Instance.
System Global Area (SGA) is a shared memory region that contains data and control information for an Oracle Instance. Oracle allocates the SGA when an Instance is started and deallocates it when the instance is shutdown. Users currently connected to an Oracle Server share the data in SGA. For optimal performance the entire SGA should be as large as possible, still it should fit in Real Memory(RAM), to minimize the Disk I/O.
Components of SGA:
1. Database Buffer Cache
2. Redo Log Buffer
3. Shared Pool
4. Large Pool
5. Java Pool

1> Database Buffer Cache: Database buffers store the most recently used blocks data. The set of database buffers in an Instance is the Database Buffer Cache. It holds the modified and unmodified blocks. The most recently used data is kept in memory, less Disk I/O is necessary and it improves the performance. Managed through (LRU) Least Recently Used algorithm.
2> Redo Log Buffer: It stores redo entries ( a log of changes made to the data). The redo entries stored in the redo log buffers are written to an Online redo log, which comes in use for database recovery. The size of the redo log is static.
3> Shared Pool: The shared pool portion of the SGA contains two major components. a)Library Cache & b) Data Dictionary Cache.
a) Library Cache: It consists of two structures, Shared SQL Area & Shared PL/SQL Area. It stores information about the most recently used SQL & PL/SQL statements. Is managed by (LRU) Least Recently Used Algortihm.
b) Data Dictionary Cache: It holds the information about the most recently used definitions in the database. During the parse phase, the server process looks at the data dictionary cache for information to resolve object names and validate access.
4> Large Pool: It is an optional area in the SGA, which can be configured to relieve the burden placed on the shared pool. It is used for Session memory (UGA) for the shared server, backup and restoration operations or RMAN. It does not use LRU algorithm.
5> Java Pool: Services parsing requirements for Java commands. It is required if installing and using Java.

PGA: Program Global Area is a memory buffer that contains data and control information for a server process. A PGA is created by oracle when a server process is started.

Process Structure
Oracle take advantage of various types of processes.
User Process: Started at the time a database user requests connection to the Oracle Server. It is a program that requests interaction with the Oracle Server. Must first establish a connection.
Server Process: Connects to the Oracle Instance and allocated when a user establishes a session. It directly interacts with the Oracle Server, it can be a dedicated or shared server. Fulfills calls generated and return results.
Background Processes: Started when an Oracle Instance is started. They are responsible for maintaining relationships between physical and memory structures.
Mandatory Background Processes: PMON, SMON, DBWn, LGWR & CKPT.
Optional Background Processes: ARCn, RECO, CJQ0, LCKn, etc.
PMON(Process Monitor): Performs process recovery when a user process fails. It is responsible for rolling back failed transactions, releasing locks, other resources and restarting dead dispatchers.
SMON(System Monitor): Perform Instance recovery when a failed instance starts up again. It is responsible to roll forward changes in redo logs, rollback uncommitted transactions, coalesces free space, deallocates temporary segments and open database for user access.
DBWn(Database Writer): It writes modified blocks from the database buffer cache to the datafiles. It writes when the checkpoint occurs, dirty buffers reach threshold, timeout occurs, there are no free buffers, etc.
LGWR(Log Writer): It writes redo log entries from redo log buffer in the SGA to the current redo log file on disk. It writes at commit, when the redo log buffer is one third 1/3 full, when there is 1 MB of redo, before DBWn writes and every three seconds.
CKPT(Checkpoint): It is responsible for signalling DBWn at checkpoints and updating all datafiles header and controlfiles with the checkpoint information.
ARCn(Archiver): It is an optional Background process, responisble for automatically archiving online redo logs when a log switch occurs. The database must be in archivelog mode.
RECO(Recoverer): It is used to resolve distributed transactions that are pending due to a network or system failure in a distributed database.