【内存结构】[SGA]之Database buffer cache

来源:互联网 发布:桃源网络硬盘 编辑:程序博客网 时间:2024/05/30 22:52
关键词: block、buffers、buffer poolbuffer cache、database buffer cache、 Database Buffer Cache
The Database Buffer Cache, also called the buffer cache, is the memory area that stores copies of data blocks read from data files. A buffer is a main memory address in which the buffer manager temporarily caches a currently or recently used data block. All users concurrently connected to a database instance share access to the buffer cache.
Database Buffer Cache 也叫 buffer cache ,它是一块用来存放从数据文件中读取出来的数据块的内存区域。该缓冲区主要是一个内存地址,用来临时缓存一些最近或当前使用过的数据块。所有用户同连接到实例,共享访问着这个buffer cache。
1.1 Purpose of the Database Buffer Cache
Oracle Database uses the buffer cache to achieve the following goals:
ORACLE 数据库使用buffer cache 达到以下目的:
Optimize physical I/O
The database updates data blocks in the cache and stores metadata about the changes in the redo log buffer. After a COMMIT, the database writes the redo buffers to the online redo log but does not immediately write data blocks to the data files. Instead, database writer(DBW) performs lazy writes in the background.
a、优化物理 I/O
数据库在缓存中更新数据块,并且将改变的元数据存储在redo log buffer中。在一个COMMIT之后,数据库会写redo buffer到online redo log中,但是不会立即写到数据文件中.。另一方面,DBW进程将慢慢的在后台执行写操作(这个COMMIT的改变)。
Keep frequently accessed blocks in the buffer cache and write infrequently accessed blocks to disk
(When Database Smart Flash Cache (flash cache) is enabled, part of the buffer cache can reside in the flash cache. This buffer cache extension is stored on one or more flash disk devices, which are solid state storage devices that uses flash memory. The database can improve performance by caching buffers in flash memory instead of reading from magnetic disk.)
Use the DB_FLASH_CACHE_FILE and DB_FLASH_CACHE_SIZE initialization parameters to configure multiple flash devices. The buffer cache tracks each device and distributes buffers to the devices uniformly.
b、保持频繁访问的数据块在buffer cache中,将极少使用的数据块写入磁盘。
(当数据库开启了闪存缓存,一部分buffer cache能暂时分给闪存缓存使用,这个buffer cache能扩展存储在一个或多个闪存设备上,并使用闪存设别作为存储设备。这样这个数据库就能通过“闪存的buffer cache”来提高数据库性能,而不是通过物理的读磁盘。
使用DB_FLASH_CACHE_FILE 和 DB_FLASH_CACHE_SIZE初始化参数来配置多闪存设备,这个buffer cache 跟踪每个设备然后将buffer均匀分部到每个设备上。)
注意:Database Smart Flash Cache is available only in Solaris and Oracle Linux.
oracle database reference to learn about the DB_FLASH_CACHE_FILE initialization parameter
1.2Buffer States
The database uses internal algorithms to manage buffers in the cache. A buffer can be in any of the following mutually exclusive states:
数据库使用内部算法来管理在缓存中的buffer。缓冲区只能是以下3种任意一个状态:
Unused
The buffer is available for use because it has never been used or is currently unused. This type of buffer is the easiest for the database to use.
未被使用的缓冲区
这个缓冲区是可用的,因为它从来没有被使用过,或者当前未被使用,这个类型的缓冲区是容易被数据库所使用的。
Clean
This buffer was used earlier and now contains a read-consistent version of a block as of a point in time. The block contains data but is "clean" so it does not need to be checkpointed. The database can pin the block and reuse it.
干净的缓冲区
   该缓冲区在早前已经被使用并且目前的数据块和磁盘中的数据块保持读一致性。这些数据块包含一些数据,但是是“干净的”,因此它不需要放到检查点队列中,数据库可以pin或者重利用这个数据块。
Dirty
The buffer contain modified data that has not yet been written to disk. The database must checkpoint the block before reusing it.
脏缓冲区
这种缓冲区放着,被改变的数据块但又没有被写入到磁盘的数据块(称为脏块),数据库必须发生检查点才能重用它。
1.3Buffer Modes
When a client requests data, Oracle Database retrieves buffers from the database buffer cache in either of the following modes:
当客户端请求数据,oracle就取回从database buffer cache下列其中之一的模型缓冲区:
Current mode 当前模型
Consistent mode 一致性模型

1.4Buffer I/O
A logical I/O, also known as a buffer I/O, refers to reads and writes of buffers in the buffer cache. When a requested buffer is not found in memory, the database performs a physical I/O to copy the buffer from either the flash cache or disk into memory, and then a logical I/O to read the cached buffer.
逻辑的I/O 也称缓存I/O,指在缓存中读和写的缓冲区。当一个缓冲区请求未在内存中找到时,数据库执行一个物理的I/O将缓冲区复制到闪存缓存或内存中,然后就逻辑的I/O去读这个缓存缓冲区了。

1.5Buffer WritesThe database writer (DBW) process periodically writes cold, dirty buffers to disk. DBW writes buffers in the following circumstances:
    1、A server process cannot find clean buffers for reading new blocks into the database buffer cache.
    2、The database must advance the checkpoint, which is the position in the redo thread from which instance recovery must begin.
    3、Tablespaces are changed to read-only status or taken offline

数据库DBW进程定期写冷、脏数据缓冲到磁盘。在下列3种情况下,DBW会写缓冲到磁盘:
    1、服务进程在database buffer cache中找不到干净的buffer存放将要从磁盘读过来的数据块。
    2、该数据库必须预先发生检查点。
    3、表空间变为read-only或者offine时。



注意:数据块写进程DBW,是先找数据块是否已经存在buffer cache中,不在的话再找是否有干净的块,都没有的话触发dbwr写脏数据,有的话latch LRU,从磁盘读取数据块到buffer cache


1.6Buffer Reads
When the number of clean or unused buffers is low, the database must remove buffers from the buffer cache. The algorithm depends on whether the flash cache is enabled:
    Flash cache disabled
    Flash cache enabled
当干净或未使用的缓冲区的数量较低时,数据库必须从缓存中删除一些缓冲区,该算法取决于是否启用闪存:

     闪存禁用

     闪存启用
1. 5Buffer Pools
A 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.
缓冲区池是一个缓冲区的集合。data buffer cache 分为一个或多个缓冲池,以相同的方式管理着数据块,这个缓冲池从根本上没有不同的算法对于老化或者缓存数据块。
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.
你可以手动的配置划分缓冲池,保存数据在buffer cache中,或者让缓冲区对新的数据变得可用。然后你可以指定明确的schema对象,使用缓冲池这样来控制一些数据块退出缓存。例如,你可以隔离某些segment到热端或者冷端。
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.
默认池
该池是数据块通常缓存的位置,除非你手动的划分池,那么默认池就是唯一的缓冲池。可选的配置其它池对默认池没有影响。

从12.1.0.2开始,大表缓存成为一个可选部分的 (缺省池可使用温度估计法、对象级的替换法来存放)。在单实例或者RAC环境中,并行度查询可以使用大表缓存,当DB_BIG_TABLE_CACHE_PERCENT_TARGET时初始化参数设置为非零值,PARALLEL_DEGREE_POLICY是设置为auto或adaptive。仅在在单实例的配置:当DB_BIG_TABLE_CACHE_PERCENT_TARGET被设置时,连续的查询可以使用大表缓存。

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.
Keep 缓冲池
如果缺省池缺乏空间了,这里为频繁访问的块计划Keep 池。Keep池目的是保持对象在内存中,从而避免频繁的I/O操作。
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.
注意:
Keep池的管理方式和其他池一样:它没有使用特别的算法来pin buffer,“Keep”只是一个昵称。你可以将表保持在较大的Keep池,或者你不希望将表保持在较小的recycle缓冲池。

Recycle pool
This pool is intended for blocks that are used infrequently. A recycle pool prevent objects from consuming unnecessary space in the cache.
Recycle池
该池为不经常使用的块设计的,回收池防止缓存中的对象从消耗不必要的空间。
A database has a standard block size (see "Database 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.
一个数据库有一个标准的数据块大小(“database block size”)。你可以创建一个表空间,但block的尺寸和标准大小不同(DB_nk_CACHE_SIZE参数)。每个非默认的数据块尺寸有自己缓冲池,但Oracle管理这些块方式与默认池是一样的。
注意:这里配置了DB_nk_CACHE_SIZE后,便可创建表空间时指定blocksize。但默认还是8k。
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.

下图显示了当多个池被使用时,buffer cache的结构。缓存包括默认池、keep池、回收池。默认池的默认块大小为8k,缓存里包含不同标准2k\4k\8k数据块的表空间。

图片

1.6Buffers and Full Table Scans

The database uses a complicated algorithm to manage table scans. By default, when buffers must be read from disk, the database inserts the buffers into the middle of the LRU list. In this way, hot blocks can remain in the cache so that they do not need to be read from disk again.
数据库使用复杂的算法来管理全表扫表。默认当缓冲区从disk读,数据库缓冲插入到LRU列表里,热块可以保留在缓存里以便不在从disk中读取他们。

-------------------------------------------------------------------------------------------------------------------------------------------
纯属
学习分享个人爱好,最终解释权以oracle官方文档为准。

0 0
原创粉丝点击