Instance Architecture   «Prev  Next»

Lesson 13 The Log Writer (LGWR)
Objective Describe how Log Writer writes out redo log records.

Log Writer (LGWR)

Describe how the Log Writer writes out redo log records.
Every Oracle instance will have a Log Writer process (LGWR) that is responsible for writing out redo log entries to the redo log files. Unlike the database writer, an instance may have only one log writer.
The Log Writer writes redo log entries from an area in the SGA known as the redo log buffer. The redo log buffer is a circular buffer, and conceptually looks like this:
  1. Head of the log: Points to where new redo entries are added
  2. Tail of the log: Points to the next redo log entry that needs to be written to disk
  3. 113,112,111: Old redo log entries, long since written to disk
  4. 903,902,901: Redo log entries that have just recently been written to disk
  5. 998,997...906,905: Redo log entries that are waiting to be written to disk
  6. 904: This will be the next redo log entry written to the redo log files.
  7. 999: This is the most recently added redo log entry.

Oracle Logs
As changes are made to the database, redo log entries are added to the head of the log, and the head pointer is advanced. The LGWR process is constantly working from the other end of the log, the tail, and constantly writes redo log entries to disk. The next lesson explains this in more detail.

Log Writer Process (LGWR)

The log writer process (LGWR) is responsible for redo log buffer management.writing the redo log buffer to a redo log file on disk. LGWR writes all redo entries that have been copied into the buffer since the last time it wrote.
The redo log buffer is a circular buffer. When LGWR writes redo entries from the redo log buffer to a redo log file, server processes can then copy new entries over the entries in the redo log buffer that have been written to disk. LGWR normally writes fast enough to ensure that space is always available in the buffer for new entries, even when access to the redo log is heavy. LGWR writes one contiguous portion of the buffer to disk. LGWR writes:
  1. A commit record when a user process commits a transaction
  2. Redo log buffers
    1. Every three seconds
    2. When the redo log buffer is one-third full
    3. When a DBWn process writes modified buffers to disk, if necessary
LGWR writes synchronously to the active mirrored group of redo log files. If one of the files in the group is damaged or unavailable, LGWR continues writing to other files in the group and logs an error in the LGWR trace file and in the system alert log. If all files in a group are damaged, or the group is unavailable because it has not been archived, LGWR cannot continue to function. When a user issues a COMMIT statement, LGWR puts a commit record in the redo log buffer and writes it to disk immediately, along with the transaction's redo entries.
The corresponding changes to data blocks are deferred until it is more efficient to write them. This is called a fast commit mechanism. The atomic write of the redo entry containing the transaction's commit record is the single event that determines the transaction has committed. Oracle returns a success code to the committing transaction, although the data buffers have not yet been written to disk.