Friday, March 21, 2014

Background Processes

Background Processes


The relationship between the physical and memory structures is maintained and enforced by Oracle’s background processes.

• Mandatory background processes
DBWn PMON CKPT
LGWR SMON RECO

• Optional background processes
ARCn LMON Snnn
QMNn LMDn
CJQ0 Pnnn
LCKn Dnnn


Background Processes

The Oracle architecture has five mandatory background processes that are discussed further in this lesson. In addition to the mandatory list, Oracle has many optional background process that are started when their option is being used. These optional processes are not within the scope of this course, with the exception of the ARCn background process. Following is a list of some optional background processes:

• RECO: Recoverer
• QMNn: Advanced Queuing
• ARCn: Archiver
• LCKn: RAC Lock Manager—Instance Locks
• LMON: RAC DLM Monitor—Global Locks
• LMDn: RAC DLM Monitor—Remote Locks
• CJQ0: Snapshot Refresh
• Dnnn: Dispatcher
• Snnn: Shared Server

• Pnnn: Parallel Query Slaves



Database Writer (DBWn)


DBWn writes when:
• Checkpoint
• Dirty buffers threshold reached
• No free buffers
• Timeout
• RAC ping request
• Tablespace offline
• Tablespace read only
• Table DROP or TRUNCATE
• Tablespace BEGIN

BACKUP


Database Writer:

The server process records changes to rollback and data blocks in the buffer cache. Database Writer (DBWn) writes the dirty buffers from the database buffer cache to the data files. It ensures that a sufficient number of free buffers—buffers that can be overwritten when server processes need to read in blocks from the data files—are available in the database buffer cache. Database performance is improved because server processes make changes only in the buffer cache.

DBWn defers writing to the data files until one of the following events occurs:

• Incremental or normal checkpoint
• The number of dirty buffers reaches a threshold value
• A process scans a specified number of blocks when scanning for free buffers and cannot fine any.
• Timeout occurs.
• A ping request in Real Application Clusters environment.
• Placing a normal or temporary tablespace offline.
• Placing a tablespace in read only mode.
• Dropping or Truncating a table.

• ALTER TABLESPACE tablespace name BEGIN BACKUP


Log Writer (LGWR)


LGWR writes:
• At commit
• When one-third full
• When there is 1 MB of redo
• Every 3 seconds
• Before DBWn writes

LOG Writer

LGWR performs sequential writes from the redo log buffer cache to the redo log file under
the following situations:
• When a transaction commits
• When the redo log buffer cache is one-third full
• When there is more than a megabyte of changes records in the redo log buffer cache
• Before DBWn writes modified blocks in the database buffer cache to the data files
• Every 3 seconds.
Because the redo is needed for recovery, LGWR confirms the commit only after the redo is
written to disk.
LGWR can also call on DBWn to write to the data files.

Note: DBWn does not write to the online redo logs.


System Monitor (SMON)

Responsibilities:
• Instance recovery:
– Rolls forward 
changes in the 
redo logs
– Opens the 
database for 
user access
– Rolls back 
uncommitted 
transactions
• Coalesces free 
space ever 3 sec
• Deallocates 
temporary segments

System Monitor

If the Oracle instance fails, any information in the SGA that has not been written to disk is lost. For example, the failure of the operating system causes an instance failure. After the loss of the instance, the background process SMON automatically performs instance recovery when the database is reopened. Instance recovery consists of the following steps:

1. Rolling forward to recover data that has not been recorded in the data files but that has been recorded in the online redo log. This data has not been written to disk because of the loss of the SGA during instance failure. During this process, SMON reads the redo log files and applies the changes recorded in the redo log to the data blocks. Because all committed transactions have been written to the redo logs, this process completely recovers these transactions.
2. Opening the database so that users can log on. Any data that is not locked by unrecovered transactions is immediately available.
3. Rolling back uncommitted transactions. They are rolled back by SMON or by the individual server processes as they access locked data.

SMON also performs some space maintenance functions:

• It combines, or coalesces, adjacent areas of free space in the data files.
• It deallocates temporary segments to return them as free space in data files. Temporary

segments are used to store data during SQL statement processing.


Process Monitor (PMON)


Cleans up after 
failed processes by:
• Rolling back the 
transaction
• Releasing locks
• Releasing other 
resources
• Restarts dead
 dispatchers

Process Monitor
The background process PMON cleans up after failed processes by:
• Rolling back the user’s current transaction
• Releasing all currently held table or row locks
• Freeing other resources currently reserved by the user
• Restarts dead dispatchers

Checkpoint (CKPT)

Responsible for:
• Signalling DBWn 
at checkpoints
• Updating datafile 
headers with 
checkpoint 
information
• Updating control 
files with 
checkpoint 
information

Checkpoint:

An event called a checkpoint occurs when the Oracle background process DBWn writes all the modified database buffers in the SGA, including both committed and uncommitted data, to the data files.

Checkpoints are implemented for the following reasons:
• Checkpoints ensure that data blocks in memory that change frequently are written to data files regularly. Because of the least recently used algorithm of DBWn, a data block that changes frequently might never qualify as the least recently used block and thus might never be written to disk if checkpoints did not occur.
• Because all database changes up to the checkpoint have been recorded in the data files, redo log entries before the checkpoint no longer need to be applied to the data files if instance recovery is required. Therefore, checkpoints are useful because they can expedite instance recovery.

Checkpoint(continued):
At a checkpoint, the following information is written:
• Checkpoint number into the data file headers
• Checkpoint number, log sequence number, archived log names, and system change 
numbers into the control file.
CKPT does not write data blocks to disk or redo blocks to the online redo logs.


Archiver (ARCn)

• Optional background process
• Automatically archives online redo logs when 
ARCHIVELOG mode is set
• Preserves the record of all changes made to the 
database

The Archiver Process:

All other background processes are optional, depending on the configuration of the database;however, one of them, ARCn, is crucial to recovering a database after the loss of a disk. As online redo log files fill, the Oracle server begins writing to the next online redo log file. The process of switching from one redo log to another is called a log switch. The ARCn process initiates backing up, or archiving, of the filled log group at every log switch. It automatically archives the online redo log before the log can be reused, so that all of the changes made to the database are preserved. This enables the DBA to recover the database to the point of
failure, even if a disk drive is damaged.

Archiving Redo Log Files
One of the important decisions that a DBA has to make is whether to configure the database
to operate in ARCHIVELOG or in NOARCHIVELOG mode.

NOARCHIVELOG Mode: In NOARCHIVELOG mode, the online redo log files are overwritten each time a log switch occurs. LGWR does not overwrite a redo log group until the checkpoint for that group is complete. This ensures that committed data can be recovered if there is an instance crash. During the instance crash, only the SGA is lost. There is no loss of disks, only memory. For example, an operating system crash causes an instance crash.

Archiving Redo Log Files (continued):

ARCHIVELOG Mode: If the database is configured to run in ARCHIVELOG mode, inactive groups of filled online redo log files must be archived before they can be used again. Since changes made to the database are recorded in the online redo log files, the database administrator can use the physical backup of the data files and the archived online redo log files to recover the database without losing any committed data because of any single point of failure, including the loss of a disk. Usually, a production database is configured to run in ARCHIVELOG mode.