Site icon Bugra Parlayan | Oracle Database Blog

Oracle Log Writer (LGWR) Process: In-Depth Technical Analysis

1. Oracle Log Writer (LGWR): Definition and Critical Role

The Oracle Log Writer (LGWR) is an essential, mandatory background process vital for the fundamental operation of an Oracle database instance. In the Oracle architecture, any change made to persistent storage areas like database blocks, password files, or control files is first recorded as “redo log entries” (change vectors) in a memory area within the System Global Area (SGA) called the Redo Log Buffer. LGWR’s primary and critical task is to take these redo log entries from the Redo Log Buffer and write them permanently to the Online Redo Log (ORL) files located on disk. This process works in conjunction with other core background processes like DBWn (Database Writer), SMON (System Monitor), PMON (Process Monitor), and CKPT (Checkpoint) to ensure database integrity and consistency.  

This function of LGWR is the cornerstone of ensuring Oracle database recoverability and durability. In the event of a system failure, such as an instance crash or power outage, changes resulting from committed transactions that haven’t yet been written to data files can be recovered using the information LGWR wrote to the online redo log files (instance recovery). This recovery is typically managed by the SMON process. LGWR’s timely and reliable writing of redo log entries to disk is crucial for preventing data loss and guaranteeing the “Durability” principle of ACID (Atomicity, Consistency, Isolation, Durability). Durability ensures that once a transaction is committed, its changes are permanent and protected against system failures; LGWR is central to this guarantee.  

The LGWR process can run as an operating system process or as a thread within an OS process, depending on the operating system. For instance, it’s typically a separate process on Linux/UNIX systems but might be a thread in Windows environments. LGWR operates not only in database instances but also in Oracle Automatic Storage Management (Oracle ASM) instances.  

The reliable and efficient operation of LGWR is a prerequisite for Oracle’s fundamental data protection and consistency mechanisms. Even the DBWn process, responsible for writing data blocks to data files, must wait for LGWR to permanently write the corresponding redo information to the ORL files (enforcing the Write-Ahead Logging – WAL protocol). This dependency highlights LGWR’s central role in Oracle’s data integrity strategy.  

2. LGWR’s Primary Function: Redo Log Persistence

LGWR’s main responsibility is to sequentially write redo log entries from the Redo Log Buffer to the active Online Redo Log file or group on disk. These entries contain the change vectors necessary to reconstruct every modification made to the database (INSERT, UPDATE, DELETE, DDL operations, etc.).  

3. LGWR Write Trigger Mechanisms

LGWR does not continuously write data from the Redo Log Buffer to disk. Instead, it is triggered by specific events or conditions designed to balance performance (avoiding unnecessary I/O) with data integrity and recoverability :  

  1. COMMIT Operation: When a user transaction issues a COMMIT, all redo log entries generated by that transaction must be written permanently to disk. This ensures the transaction’s durability. The user process (or server process) waits until it receives confirmation from LGWR that the relevant redo entries have been successfully written to the ORL files. This wait time is the primary cause of the common log file sync wait event in Oracle performance analysis.  
  2. Log Buffer Thresholds Exceeded: LGWR proactively triggers a write when the Redo Log Buffer reaches a certain occupancy level or accumulates a specific amount of redo data. This helps prevent the buffer from filling completely and stalling new redo generation (log buffer space wait event). Common thresholds include:
    • The buffer becoming one-third (1/3) full.  
    • Accumulation of a specific amount (e.g., 1 Megabyte (MB)) of redo data in the buffer. This threshold relates to Oracle’s internal _log_io_size mechanism, but it’s a triggering threshold, not a user-configurable I/O size parameter. (Note: These thresholds might be dynamically adjusted based on Oracle version, platform, or LOG_BUFFER size.)  
  3. Timeout: Approximately every three seconds, LGWR periodically writes the current contents of the Redo Log Buffer to disk. This ensures that redo entries are flushed regularly, even if no commits occur or buffer thresholds aren’t met. This limits the amount of redo data that could potentially be lost in an instance crash (though only committed data is guaranteed recoverable).  
  4. DBWR Signal (Write-Ahead Logging – WAL): Before the Database Writer (DBWR or DBWn) process can write modified (dirty) data blocks from the database buffer cache to the permanent data files, it must ensure that all redo entries corresponding to those changes have been written to the online redo log files on disk. This is the fundamental rule of the Write-Ahead Logging (WAL) protocol. If DBWn needs to write a block whose redo entries are still only in the Redo Log Buffer, DBWn signals LGWR to write those redo entries and waits for LGWR to complete the write before proceeding.  

These diverse triggers balance data durability, recoverability, and system performance. COMMIT ensures transaction durability; thresholds and timeouts manage buffer flow and limit potential loss; the DBWR signal enforces the critical WAL protocol for data consistency. The DBWR-LGWR dependency imposed by WAL means that LGWR performance can impact not only COMMIT latency but also the speed of writing to data files and thus buffer cache management, potentially leading to waits like free buffer waits if LGWR is slow.  

The table below summarizes these triggers:

Trigger EventPrimary PurposeMechanismSynchronization for User
COMMIT OperationDurabilityUser/Server process posts LGWRSynchronous (log file sync wait)
Buffer 1/3 Full ThresholdThroughput/EfficiencyInternal check by LGWRAsynchronous
Buffer 1MB Data ThresholdThroughput/EfficiencyInternal check by LGWRAsynchronous
~3 Second TimeoutBounded RecoveryTimer within LGWRAsynchronous
DBWR Signal (WAL)Consistency (WAL)DBWR process posts LGWRAsynchronous (but DBWR process waits)

4. LGWR Interactions and Log Management

LGWR interacts closely with other components of Oracle’s logging and recovery architecture:

These interactions ensure the integrity of Oracle’s recovery architecture. Log switching provides redo stream continuity, multiplexing protects against single disk failures, and ARCH processes enable long-term retention and advanced recovery scenarios. However, these interactions can also become wait points if ORL sizing or archiving performance is not configured correctly.

5. LGWR Performance: I/O Dependency and Bottlenecks

The performance of the LGWR process is heavily dependent on the I/O performance of the disk subsystem hosting the online redo log (ORL) files, particularly the write latency. Although LGWR performs sequential writes , the synchronous nature of COMMIT operations means the time taken to complete each write (latency) is often more critical than overall throughput.  

6. Methods to Improve LGWR Performance

Several strategies, spanning infrastructure and application levels, can be employed to enhance LGWR performance and consequently, COMMIT speed:

  1. Use Fastest Storage: Place Online Redo Log (ORL) files on the storage tier with the lowest write latency available (ideally NVMe or at least enterprise-grade SSD). This is the most direct way to reduce log file sync waits.  
  2. Appropriate RAID Level and Configuration: Use RAID levels with good write performance and redundancy for ORLs, such as RAID 1 or RAID 10. Avoid RAID 5/6 due to parity calculation overhead impacting write performance. Ensure the storage controller’s write cache (especially if battery-backed) is enabled and configured correctly.  
  3. Sufficient Number and Size of ORL Groups:
    • Size: Size ORL groups based on the system’s redo generation rate. Too small logs cause frequent log switches, increasing load on CKPT/ARCH and the risk of LGWR waiting for archiving. Aim for log switches every 15-30 minutes during peak load. Sizes like 1GB, 4GB, 8GB, or larger are common.  
    • Number: A minimum of 3 or 4 ORL groups is recommended. More groups increase the likelihood that LGWR finds a free group if ARCH is lagging.  
  4. Implement Multiplexing: Ensure each ORL group has at least two members, placed on physically separate disks and preferably different I/O controllers. This protects against single disk failures and can distribute I/O load.  
  5. Tune LOG_BUFFER Cautiously:
    • This parameter sets the Redo Log Buffer size in the SGA.  
    • Oracle typically auto-tunes this, and defaults are often sufficient.  
    • Consider increasing LOG_BUFFER only if significant log buffer space waits or constantly increasing redo buffer allocation retries are observed, and the underlying I/O subsystem (log file parallel write) is fast.  
    • Make increases cautiously (e.g., 50% or double). An excessively large buffer (hundreds of MBs or GBs) usually yields no extra performance, wastes SGA memory, and can starve other SGA components. Values between 8MB and 256MB are typically adequate. Enabling Flashback Database might require a larger log buffer.  
  6. Optimize COMMIT Frequency (Application Level): Applications committing excessively often (e.g., per row in a loop) overload LGWR and cause high log file sync waits. Grouping operations into larger logical units of work and reducing COMMIT frequency (batch commits) can significantly improve performance.  
  7. Use NOLOGGING / UNRECOVERABLE Selectively: For specific bulk load, CTAS, or index build operations where data loss risk is acceptable (and a backup follows), using NOLOGGING or UNRECOVERABLE can drastically reduce or eliminate redo generation, easing the load on LGWR. Remember this makes these operations unrecoverable via media recovery and prevents replication to standbys. FORCE LOGGING at the database/tablespace level overrides these options.  
  8. Improve Overall Disk I/O Subsystem: Optimizing the general I/O performance of the subsystem hosting the ORLs (faster disks, better controllers, optimized filesystem settings, I/O schedulers) indirectly benefits LGWR.  

7. LGWR in Exadata Environments

The Oracle Exadata platform incorporates specialized hardware and software components designed to optimize database performance, and LGWR performance benefits significantly from these optimizations.

8. LGWR-Related Parameters

Several Oracle initialization parameters can directly or indirectly influence LGWR’s behavior. However, in most cases, default settings suffice, and direct manipulation is often discouraged.

In summary, apart from potentially LOG_BUFFER in specific diagnosed scenarios, there are few parameters end-users should safely adjust to directly control LGWR behavior. Performance tuning should focus on optimizing the I/O subsystem (especially for ORLs), application COMMIT behavior, and leveraging platform-specific features like Exadata’s Smart Flash Log.

9. Can LGWR Write Amount Be Manually Determined?

It is not possible or recommended to manually set a fixed, specific amount of redo data that LGWR writes in each I/O operation via a parameter. The amount of data LGWR writes per flush is dynamic and depends entirely on the triggering mechanism, as detailed in Section 3:

The amount written per LGWR I/O is constantly variable based on database activity, COMMIT frequency, LOG_BUFFER size, and the specific trigger.

While internal mechanisms like _LOG_IO_SIZE or potential hidden parameters might influence the size of I/O requests LGWR makes to the OS, they do not dictate the total amount of redo flushed from the buffer in response to a trigger. Attempting to manually control this dynamic, adaptive process via unsupported parameters is highly risky and likely counterproductive. LGWR’s efficiency comes from its ability to intelligently batch redo entries based on these dynamic triggers.  

10. Conclusion

The Oracle Log Writer (LGWR) process is a fundamental component of the Oracle database architecture, indispensable for ensuring data durability and recoverability. By reliably writing redo log entries from the Redo Log Buffer to online redo log files, it guarantees the persistence of committed transactions and prevents data loss during instance failures.  

LGWR performance is critically linked to the write latency of the underlying storage subsystem hosting the online redo log files. Slow I/O can lead to significant log file sync waits, increasing OLTP transaction times and degrading overall database performance. Optimizing LGWR performance, therefore, primarily involves deploying online redo logs on the fastest available storage (SSD/NVMe) , optimizing application COMMIT frequency , and ensuring proper ORL sizing and management.  

On specialized platforms like Oracle Exadata, features such as Smart Flash Log (SFL) and XRMEM architecturally address the LGWR write bottleneck, dramatically reducing commit latency and providing a significant performance advantage over traditional systems. Understanding LGWR’s mechanisms, triggers, interactions, and performance factors is crucial for maximizing Oracle database performance while maintaining essential data integrity and recovery guarantees.  

Exit mobile version