实例之内存体系结构(2)--- 数据库缓冲区(DB Buffer Cache)

1. 作用:用于存储从磁盘数据文件中读入的数据,为所有用户共享。服务器进程(server process)将读入的数据保存在数据缓冲区中,当后续的请求需要这些数据时可以在内存中找到,则不需要再从磁盘读取。数据缓冲区中被修改的数据块(脏块)由后台进程DBWR将其写入磁盘。数据缓冲区的大小对数据库的读取速度有直接的影响,一般来说,数据库缓冲区越大越好。

2. 数据库缓冲区包含标准内存区域和非标准内存区域。标准内存区域是存放默认标准块的内存空间(Oracle默认标准块大小为8K)。

SQL> show parameter block;

NAME           TYPE      VALUE
------------------------------------ ---------------------- ------------------------------
db_block_buffers            integer     0
db_block_checking           string      FALSE
db_block_checksum      string      TYPICAL
db_block_size        integer       8192
db_file_multiblock_read_count   integer              128

3. 关于数据块大小的定义

db_block_size磁盘上的标准块大小8k,对应的缓冲区里面就必须存在8k标准块空间来接纳这个数据,缓冲区标准块大小是参数db_cache_size来决定。

如果要定义16k的表空间(数据文件),前提是需要在数据库缓冲区里面定义好16k的空间大小,不然报错。

SQL> create tablespace tbs_16k datafile '/u01/app/oracle/oradata/PROD1/tbs_16.dbf' size 5m blocksize 16k;

create tablespace tbs_16k datafile '/u01/app/oracle/oradata/PROD1/tbs_16.dbf' size 5m blocksize 16k

*

ERROR at line 1:

ORA-29339: tablespace block size 16384 does not match configured block sizes

提前定义非标准块的db buffer

SQL> alter system set db_16k_cache_size=15m;

再次创建

SQL> create tablespace tbs_16k datafile '/u01/app/oracle/oradata/PROD1/tbs_16k.dbf' size 5m blocksize 16k;

总结:只要是使用非默认标准块(8k),都需要提前在内存里面提前定义相关参数。

4. 缓冲池(Buffer Pools)

buffer pool is a collection of buffers.

The database buffer cache is divided into one or more buffer pools, which manage blocks in mostly the same way. The pools do not have radically different algorithms for aging or caching blocks.

You can manually configure separate buffer pools that either keep data in the buffer cache or make the buffers available for new data immediately after using the data blocks. You can then assign specific schema objects to the appropriate buffer pool to control how blocks age out of the cache. For example, you can segregate segments into hot, warm, and cold buffer pools.

The possible buffer pools are as follows:

  • Default pool

    This pool is the location where blocks are normally cached. Unless you manually configure separate pools, the default pool is the only buffer pool. The optional configuration of the other pools has no effect on the default pool.

    Starting in Oracle Database 12c Release 1 (12.1.0.2), the big table cache is an optional section of the default pool that uses a temperature-based, object-level replacement algorithm. In single-instance and Oracle RAC databases, parallel queries can use the big table cache when the DB_BIG_TABLE_CACHE_PERCENT_TARGET initialization parameter is set to a nonzero value, and PARALLEL_DEGREE_POLICY is set to auto or adaptive. In single-instance configurations only, serial queries can use the big table cache when DB_BIG_TABLE_CACHE_PERCENT_TARGET is set.

  • Keep pool

    This pool is intended for blocks that were accessed frequently, but which aged out of the default pool because of lack of space. The purpose of the keep buffer pool is to retain objects in memory, thus avoiding I/O operations.

    Note:

    The keep pool manages buffers in the same way as the other pools: it does not use a special algorithm to pin buffers. The word "keep" is a naming convention. You can place tables that you want to keep in the larger keep pool, and place tables that you do not want to keep in the smaller recycle pool.

  • Recycle pool

    This pool is intended for blocks that are used infrequently. A recycle pool prevent objects from consuming unnecessary space in the cache.

A database has a standard block size. You can create a tablespace with a block size that differs from the standard size. Each nondefault block size has its own pool. Oracle Database manages the blocks in these pools in the same way as in the default pool.

The following figure shows the structure of the buffer cache when multiple pools are used. The cache contains default, keep, and recycle pools. The default block size is 8 KB. The cache contains separate pools for tablespaces that use the nonstandard block sizes of 2 KB, 4 KB, and 16 KB.

原文地址:https://www.cnblogs.com/eniniemand/p/14063865.html