RelationalDBDesign RelationalDBDesign



Instance Architecture   «Prev  Next»
Lesson 10 Writing out dirty buffers to make room for new data
Objective Explain how the database writer writes out buffers.

How Oracle finds Space to write to new Data

Reading new data from disk is one of the things that can indirectly trigger the database writer to write dirty buffers back to disk. When Oracle reads a block of data from the disk, it must place that data somewhere in the database buffer cache. If it can find an empty buffer, it uses that. Otherwise, it looks for an old buffer that has not been changed. If it finds one, it overwrites it with the new data. After checking a certain number of old buffers, if an unchanged one has not been found, the DBWR process will be asked to start writing some data back to disk in order to free up space for the new data. The following SlideShow demonstrates how this works.

  1. In the diagram above, all the buffers except one are full
  2. Oracle reads a block from disk, Oracle knows to place it in the empty buffer, causing it to become full.
  3. If Oracle reads another block, it will need to overwrite one of the unchanged buffers.
  4. It will check one buffer
  5. It will check another buffer
  6. It will check the next buffer until it finds an unmodified buffer that it can overwrite.
  7. If many buffers are modified, Oracle may not find an unmodified one right away.
  8. The database writer will be called upon to hurry up and write some modified blocks back to disk.
  9. This increases the number of unmodified blocks
  10. Oracle will use one to hold the block that was just read

Writing Out Buffers

Sequence for using Buffers

When Oracle is checking for unmodified buffers it always starts with the least recently used buffer and works its way forward to the most recently used.
Similarly when writing data, Oracle will write the least recently used blocks first.

Organization of the Database Buffer Cache

The buffers in the cache are organized in two lists:
  1. the write list and
  2. the least recently used (LRU) list.
The write list holds dirty buffers, which contain data that has been modified but has not yet been written to disk. The LRU list holds free buffers, pinned buffers, and dirty buffers that have not yet been moved to the write list. Free buffers do not contain any useful data and are available for use. Pinned buffers are currently being accessed.
When an Oracle process accesses a buffer, the process moves the buffer to the most recently used (MRU) end of the LRU list.
As more buffers are continually moved to the MRU end of the LRU list, dirty buffers age toward the LRU end of the LRU list. The first time an Oracle user process requires a particular piece of data, it searches for the data in the database buffer cache. If the process finds the data already in the cache (a cache hit), it can read the data directly from memory.
If the process cannot find the data in the cache (a cache miss), it must copy the data block from a datafile on disk into a buffer in the cache before accessing the data. Accessing data through a cache hit is faster than data access through a cache miss.
Before reading a data block into the cache, the process must first find a free buffer. The process searches the LRU list, starting at the least recently used end of the list. The process searches either until it finds a free buffer or until it has searched the threshold limit of buffers. If the user process finds a dirty buffer as it searches the LRU list, it moves that buffer to the write list and continues to search. When the process finds a free buffer, it reads the data block from disk into the buffer and moves the buffer to the MRU end of the LRU list. If an Oracle user process searches the threshold limit of buffers without finding a free buffer, the process stops searching the LRU list and signals the DBW0 background process to write some of the dirty buffers to disk.