Posts Tagged ‘dbw’

Background Processes

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 background process, ARCn. 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: Coordinator Job Queue background process
  • Dnnn: Dispatcher
  • Snnn: Shared Server
  • Pnnn: Parallel Query Slaves

 Database Writer (DBWn)

The server process records changes to undo and data blocks in the Database Buffer Cache. DBWn writes the dirty buffers from the Database Buffer Cache to the datafiles. It ensures that a sufficient number of free buffers (buffers that can be overwritten when server processes need to read in blocks from the datafiles) are available in the Database Buffer Cache. Database performance is improved because server processes make changes only in the Database Buffer Cache.

DBWn defers writing to the datafiles 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 find any
  • Timeout occurs
  • A ping request in Real Application Clusters (RAC) 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 performs sequential writes from the Redo Log Buffer to the redo log file under the following situations:

  • When a transaction commits
  • When the Redo Log Buffer is one-third full
  • When there is more than 1 MB of changes recorded in the Redo Log Buffer
  • Before DBWn writes modified blocks in the Database Buffer Cache to the datafiles
  • Every three seconds

Because the redo is needed for recovery, LGWR confirms the commit operation only after the redo is written to disk.

LGWR can also call on DBWn to write to the datafiles.

System Monitor (SMON)

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 datafiles 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 datafiles.
  • It deallocates temporary segments to return them as free space in datafiles.

Process Monitor (PMON)

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)

A data structure that defines an SCN in the redo thread of a database. Checkpoints are recorded in the control file and each datafile header, and are a crucial element of recovery.

Every three seconds the CKPT process stores data in the control file to identify that place in the redo log file where recovery is to begin, this being called a checkpoint. The purpose of a checkpoint is to ensure that all of the buffers in the Database Buffer Cache that were modified prior to a point in time have been written to the datafiles. This point in time (called the checkpoint position) is where database recovery is to begin in the event of an instance failure. DBWn will already have written all of the buffers in the Database Buffer Cache that were modified prior to that point in time. Prior to Oracle9i, this was done at the end of the redo log. In the event of a log switch CKPT also writes this checkpoint information to the headers of the datafiles.

A checkpoint is the highest system change number (SCN) such that all data blocks less than or equal to that SCN are known to be written out to the data files. If a failure occurs, then only the redo records containing changes at SCNs higher than the checkpoint need to be applied during recovery.

A checkpoint performs the following three operations:

  1. Every dirty block in the buffer cache is written to the data files. That is, it synchronizes the data blocks in the buffer cache with the datafiles on disk.
    It’s the DBWR that writes all modified database blocks back to the datafiles.
  2. The latest SCN is written (updated) into the datafile header.
  3. The latest SCN is also written to the controlfiles.

When checkpoint occurs?

Checkpoint occurs

1) At redo log switch

2) LOG_CHECKPOINT_TIMEOUT has expired

3) LOG_CHECKPOINT_INTERVAL has reached.

4) Forcefully by DBA ALTER SYSTEM CHECKPOINT

Checkpoint information written by CKPT includes checkpoint position, system change number, location in the redo log to begin recovery, information about logs, and so on.

Note: CKPT does not write data blocks to disk or redo blocks to the online redo logs.

Archiver (ARCn)

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 get filled, 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.