How are dirty buffers managed?

How are dirty buffers managed?

In the Oracle ecosystem, a "Dirty Buffer" is simply a data block in the memory (SGA) that has been modified by a user but hasn't been written back to the physical disk yet.

Managing these buffers is a delicate balancing act. If Oracle writes them to disk too often, the database slows down due to heavy I/O. If it waits too long, a crash recovery will take hours. Here is how Oracle manages this "dirty work" behind the scenes.


1. The Life of a Dirty Buffer

When you update a row, Oracle doesn't touch the disk. Instead:

  1. It finds the data block in the Buffer Cache.

  2. It changes the data in RAM.

  3. It marks that block as "Dirty."

  4. It moves the block to a special internal list called the Write Queue (or Checkpoint Queue).

The block stays "dirty" in memory until a specific process decides it’s time to sync it with the physical data files.


2. The Role of DBWn (The Lazy Writer)

The Database Writer (DBWn) is the process responsible for cleaning these buffers. Unlike the Log Writer (LGWR), which is aggressive and fast, DBWn is deliberately "lazy." It uses a Least Recently Used (LRU) algorithm to decide when to write.

By staying lazy, DBWn allows multiple users to update the same block in memory many times, but it only performs one physical write to the disk eventually. This saves massive amounts of system resources.


3. What Triggers the "Cleanup"?

DBWn doesn't just wake up at random. It manages dirty buffers based on these specific triggers:

A. Threshold Reached (The "Full" Trigger)

If the Buffer Cache fills up with so many dirty buffers that there is no "clean" space left for new data being read from the disk, DBWn is forced to write some dirty blocks to make room.

B. The Checkpoint (The "Safety" Trigger)

When a Checkpoint occurs (like during a Log Switch), Oracle demands that all dirty buffers up to a certain point in time be written to disk. This ensures that the physical files aren't too far behind the memory.

C. Every 3 Seconds (The "Timer" Trigger)

To prevent a massive backlog of work, DBWn performs small, incremental writes every three seconds to keep the write queue manageable.


4. The Write-Ahead Rule

Oracle has a strict rule: LGWR must finish before DBWn can start.

Before a dirty buffer can be written to a data file, the corresponding Redo Log entry (the record of the change) must already be safely on the disk. This ensures that if the system crashes while DBWn is halfway through writing, the database can still be recovered.


5. Summary: Dirty Buffer Management

ComponentResponsibility
Buffer CacheHolds the dirty blocks in RAM.
Write QueueThe "to-do list" of blocks waiting to be written.
DBWnThe process that physically moves dirty blocks to disk.
LRU AlgorithmEnsures frequently used blocks stay in memory while "cold" dirty blocks are written first.

Why does this matter for performance?

If your dirty buffers aren't being managed fast enough, you will see a wait event called free buffer waits. This means your users are literally stuck waiting for DBWn to finish cleaning up the "mess" in memory before they can read any more data.

In high-performance 19c systems, you can increase the number of writers (e.g., DB_WRITER_PROCESSES = 4) to help clear the dirty buffers faster.

Looking for servers Rental ?

Call Our Expert :


  • (call for rental enquiries)

Email us :