Search notes:

Oracle: Buffer cache

The Oracle database buffer cache is also referred to as buffer cache.
The buffer cache stores copies of data blocks in memory (the SGA). These copies are stored in what is called buffers by Oracle. Naturally, the size of such a buffer equals the data block size.
The buffer cache is shared among all sessions that are connected to an instance.
A notable distinction between the Shared Pool (which is also shared globally) and the buffer cache is that the shared pool primarily caches metadata while the buffer cache stores data.
The goal is to keep frequently used data blocks in the buffer cache in order to improve I/O by having less physical reads or writes.
The buffers in the cache are organized in linked chains under a hash value calculated for the buffer (DB block).
The linked list for a given hash is protected by a cache buffers chains latch.
When a dirty buffer is not used anymore, it is written to disk by the Database Writer background process.

Components of the buffer cache

The buffer is divided into

Least recently used (LRU) list

All blocks stored in the buffer cache are on a LRU list.
When a free buffer is needed, this list is scanned from the LRU end until a non-dirty buffer is found that can be freed.
When then the block is copied into the newly freed block moves other blocks down the LRU.
When a block is accessed that is already in the buffer cache, the block is moved up in the LRU list.
The cache buffers lru chain latch is used to serialize operations on the LRU list.
A table or materialized view can be created with the cache attribute.
Blocks of «cached» objects that are read into the buffer cache as part of a full table are placed at the most recently used end of the LRU list. Thus, they tend to stay longer in the buffer cache. Typically, objects are attributed with cache if they're small and used to look up data.
See also the tch (touch) counter in x$bh

Dirty blocks

A dirty block is a block whose content was modified but is not yet flushed back to the datafile by DBWR.

Cache hit vs cache miss

When a database needs data, Oracle checks with the buffer cache if the relevant data block is already copied into the buffer cache.
If this is the case, this is referred to as a cache hit.
If not, this is a cache miss. In this case, a copy from the data block needs to be copied into the buffer cache.

Bypassing the buffer cache with direct path insert and read

Oracle has the ability to write data into a data file without first writing them into the buffer cache. In such an operation, the data is appended behind the high water mark (HWM) of a table.
A direct path insert can be performed with NOLOGGING to reduce the amount of redo that is generated.
Similarly, a direct path read reads data from a data file directly into the PGA, again bypassing the buffer cache.
See also Conventional path vis direct path loads.

Emptying the buffer cache

The buffer cache can be emptied with
alter system flush buffer_cache;

Interesting hidden init-parameters

The values of some interesting (imho) hidden init parameters that are related to the buffer cache can be queried with the following query:
select
   par.ksppinm   name,
   par.ksppdesc  description,
   v.ksppstvl    value
from
   x$ksppi  par                      join 
   x$ksppsv v on par.indx = v.indx
where
-- par.ksppinm like '_db_block%'
   par.ksppinm in (
      '_db_block_buffers'               ,
      '_db_block_hash_buckets'          ,
      '_db_block_hash_latches'          ,
      '_db_block_lru_latches'           ,
      '_db_block_max_cr_dba'            ,
      '_db_block_table_scan_buffer_size',
      '_db_blocks_per_hash_latch'
    )
order by
   par.ksppinm;

TODO

MOS Note 947152.1 says that the buffer cache minum size is 4MB * num_cpus.

See also

Compare with SQL Server's buffer cache
The buffer cache should not be confused with the redo log buffer.
ratzeputz.sql
v$bh and x$bh
The events that are associated with reading buffer into the buffer cache include (or are?)
oradebug dump buffers
When executing cartesian joins, the buffer cache is bypassed and the blocks of the inner table are stored in the PGA, see the plan operation BUFFER SORT.
v$db_cache_advice (which is populated when the db_cache_advice parameter is enabled) shows the simulated miss rates for a range of potential buffer cache sizes (See MOS Note 148511.1)

Links

Craig Shallahamer's Buffer Cache Visualization Tool

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1741097644, '18.117.97.59', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/architecture/instance/SGA/database-buffer-cache/index(191): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78