Memory Architecture-SGA-Database Buffer Cache

启动instance:1、分配内存空间SGA

2、启动后台进程

内存结构:1、SGA

2、PGA

3、UGA

4、Software code areas

SGA components:1、Database Buffer Cache

2、Redo Log Buffer

3、Shared Pool

4、Large Pool

5、Java Pool

6、Streams Pool

7、Fixed SGA

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Database Buffer Cache(数据库高速缓存):

Database Buffer Cache存储data files中data blocks的copies.所有并行连接同一个数据库instance的用户可以共享访问buffer Cache.

1、Database Buffer Cache的优点:

a、Optimize Physical I/O(优化物理I/O)

数据库将数据更新写到buffer cache中,将进行更新的SQL语句写入redo log buffer中,当执行commit之后,不立即把buffer cache中的数据写入disk,而是将redo log buffer中的数据写入磁盘。Database writer(DBW) performslazy writes in the background.

b、Keep frequently accessed blocks in the buffer cache and write infrequently accessed blocks to disk(保持频繁使用的blocks在buffer cache,不频繁使用的写进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 a flash disk device,
which is a solid state storage device that uses flash memory. The database can improve performance by caching buffers in flash memory instead of reading from magnetic disk.

2、Buffer States(缓冲区状态):

a、Unused

当前没有被使用的buffer,可以被database使用。

b、Clean

buffer之前被使用,现在存在一个时间点的一致性读版本,database可以pin缓存中的块并且reuse
it.

c、Dirty

The buffer contain modified data that has not yet been written to disk. The database must checkpoint the block before reusing it.

----------------

每个buffer都有access mode:pined或者free(即unpined),多个session不能同时修改同一个pined buffer.

The database uses a sophisticated algorithm to make buffer access efficient. Pointers to dirty and nondirty buffers exist on the same
least recently used (LRU) list, which has a hot end and cold end. A
cold buffer is one that has not been recently used. A
hot buffer is frequently accessed and has been recently used.

3、Buffer Modes:

a、Current Mode

A current mode get, also called a
db block get, is a retrieval of a block as it currently appears in the buffer cache.

b、Consistent Mode

A
consistent read get is a retrieval of a read-consistent version of a block. This retrieval may use undo data.

4、Buffer I/O(logical I/O&physical I/O):

logical I/O即buffer I/O,读取或写入buffer cache中的buffers。当在buffer cache中找不到数据时就会发生physical I/O,physical I/O 把flash cache或者disk中的数据copy到cache buffer,再通过logical I/O从cache buffer中读取数据。

a、Buffer Writes

database writer(DBW)进程会定期地将cold、dirty buffers写入disk(即:将LRU队列的cold end的buffers写入disk)。

DBWn在以下情况下会把buffers写入disk:

1:服务进程在把new blocks读入database buffer cache中时找不到clean buffer.

如果unused buffers数量降到小于内部临界值,并且clean buffers被请求时,DBWn会将cold、dirty buffers写入disk。

数据库用LRU算法来决定把哪个dirty buffer中的数据写入disk。数据库把LRU 队列cold end的dirty buffer 从LRU队列移除,并移到write queue。DBWn 将write queue的buffer写入到disk(using multiblock writes if possible)。这种机制使得dirty buffers和clean buffers变得可用。

2:The database must advance the checkpoint,which is the position in the redo thread from which instance recovery must begin.

3:Tablespace are changed to read-only status or taken offline.

b、Buffer Reads

1:Flash casche disabled

The database re-uses each clean buffer as needed, overwriting it. If the overwritten buffer is needed later, then the database must read it from magnetic disk.

2:Flash cache enabled

DBWn可以把clean buffer的body写入flash cache,这样可以使cache buffer中的空间重用。数据库把buffer header放入LRU list中。当buffer再次被请求的时候,数据库可以从flash cache中读取,而不是磁盘。

当一个客户端进程请求buffer时,The search order is as follows:

1:服务器进程search整个buffer cache

2:服务器进程search flah cache LRU list中的buffer header

3:将disk数据copy到buffer cache(物理读),从buffer cache读取数据(逻辑读)

注:如果在步骤1或2找到buffer则称为cache hit,没有找到称为cache miss

data file 和 temp file都可以发生physical reads。data file物理读之后还要进行logical I/O。temp file绕过buffer cache,物理读之后不发生logical I/O。(当内存不够时数据库强制将数据写入temporary table)

c、Buffer Touch Count

如果一个buffer is pinned并且上次增加计数是在3秒钟以前,则touche count增加一个计数。如果一个buffer is pinned,但上次增加计数没有超过3秒,则touche count不曾加计数,保持原值(即看做一次touch)。

如果LRU list cold端的buffer的touch count值比较大,则次cold buffer会被移到hot end。如果LRU list cold端的touch count值比较小,then the buffer ages out of the cache.

d、Buffers and Full Table Scans

当从disk把数据写入buffers时,数据库会把buffers插入到the middle of the LRU list。这种情况下,full table scan可能会引发一个问题:假设表中的total block size比buffer cache的size大,全表扫描会clean out the buffer cache,preventing the database from maintaining a cache of frequently accessed blocks。所以full table
scan这种情况和其他的处理方式不一样,当为full table scan时,buffer cache中的blocks可以立即被reuse。

5、Buffer Pools:

A
buffer pool is a collection of buffers. The database buffer cache is divided into one or more buffer pools.

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.

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.

  • 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 goal of the keep buffer pool is to retain objects in memory, thus avoiding I/O operations.

  • Recycle pool

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

数据库有标准的block size。在创建tablespace的时候可以指定和标准块大小不一样的block size。每一个不是默认block size的tablespace有自己的pool。这些pool的管理和default pool的管理方式相同。

Memory Architecture-SGA-Database Buffer Cache

时间: 2024-10-03 07:36:38

Memory Architecture-SGA-Database Buffer Cache的相关文章

Oracle优化 -- 关于Database Buffer Cache相关参数DB_CACHE_SIZE的优化设置

select size_for_estimate, buffers_for_estimate ,ESTD_PHYSICAL_READ_factor,ESTD_PHYSICAL_READS from v$db_cache_advice    2      where block_size='8192' and advice_status='ON'; 中,size_for_estimate表示预计的数据库高速缓冲区的大小(即:db_cache_size的值).ESTD_PHYSICAL_READS表

[转载]Buffer cache的调整与优化

Buffer Cache是SGA的重要组成部分,主要用于缓存数据块,其大小也直接影响系统的性能.当Buffer Cache过小的时候,将会造成更多的free buffer waits事件.下面将具体描述Buffer Cache的作用.调整与优化. 一.SGA的所有组件 从动态视图v$sga_dynamic_components获取SGA的相关信息 SELECT component, current_size, min_size FROM v$sga_dynamic_components; COM

Buffer cache 的调整与优化

Buffer cache 的调整与优化 -============================== -- Buffer cache 的调整与优化(一) --============================== Buffer Cache是SGA的重要组成部分,主要用于缓存数据块,其大小也直接影响系统的性能.当Buffer Cache过小的时候,将会造成更多的free buffer waits事件. 下面将具体描述Buffer Cache的作用,调整与优化. 一.SGA的所有组件 从动态

buffer cache —— buffer busy waits/read by other session

oracle提供非常精确.有效的row level lock机制,多个用户同时修改数据时,为了保护数据,以块为单位挂起锁的情况不会发生.但这不太正确.以块为单位的锁虽然不存在,但正因为oracle I/O以块为单位组成,所以块单位锁是必要的.假设row1.row2两个行位于同一个块内,两名用户(用户1.用户2)各自对row1.row2执行update,逻辑上两个被更新行之间不存在需要相互保护的数据.因为oracle提供row level lock机制,所以修改互相不用的行完全不成问题.但是若两个

相克军_Oracle体系_随堂笔记005-Database buffer cache

本章主要阐述SGA中的Database buffer cache. Buffer cache { 1.pin (读写瞬间的状态) 2.clean 3.dirty 4.unused } --Database buffer cache 概述: 1.段.区.块的概念: create table t2 ( id int, name varchar2(30) ); 建立一个表,同时建立一个段, 建立段的同时,会给段分配一个区, 区是物理上连续的几个块. 区是oracle给段分配的最小单位. 块是oracl

buffer cache 和shared pool 详解(之三,shared pool原理)

[深入解析--eygle] 学习笔记 1.2 shared pool原理 Shared Pool是Oracle SGA设置中最复杂也是最重要的一部分内容,Oracle通过Shared Pool来实现SQL共享.减少代码硬解析等,从而提高数据库的性能.在某些版本中,如果设置不当,Shared Pool可能会极大影响数据库的正常运行. 在Oracle 7之前,Shared Pool并不存在,每个Oracle连接都有一个独立的Server进程与之相关联,Server进程负责解析和优化所有SQL和PL/

调优4(buffer cache 调整)

第四章. buffer cache 调整 1.buffer cache 功能 buffer cache: 用于存放从datafile 里读出的数据块的镜像,并共享这些数据块,采用LRU算法 buffer cache 数据块状态: pending:数据块正在使用,状态未决dirty: 被修改过的块,还未写入到datafilefree: 已经从cache里写入到datafile的块,可以被覆盖 LRU LIST :链接从datafile里读出的块的头部信息,一般用于free 状态的块Checkpoi

BUFFER CACHE之调整buffer cache的大小

Buffer Cache存放真正数据的缓冲区,shared Pool里面存放的是sql指令(LC中一次编译,多次运行,加快处理性能,cache hit ratio要高),而buffer cache里面存放真正的查询结果.Buffer Cache:由彼此独立的三个子cache(subcaches,也叫主buffer cache:keep,recycle,default)组成支持多种数据块的多缓冲池.注意system表空间只能用主数据块 Step1: 查看各个组件size(看buffer cache

查看buffer cache命中率

SQL> select name,value from v$sysstat where name in('db block gets','consistent gets','physical reads'); NAME                                                                  VALUE---------------------------------------------------------------- -----