设为首页 收藏本站
查看: 635|回复: 0

[经验分享] Oracle Buffer Cache 中的 Recycle Pool 说明

[复制链接]

尚未签到

发表于 2016-7-28 09:47:06 | 显示全部楼层 |阅读模式
  
  
  一. Recycle Pool 说明
  
  在我之前的Blog里对DB buffer 进行了一个说明,参考:
  Oracle Buffer Cache 原理
  http://blog.csdn.net/tianlesoftware/article/details/6573438
  
  Oracle Buffer Cache 中 Keep Pool 说明
  http://blog.csdn.net/tianlesoftware/article/details/6581159
  
  Oracle 的buffer cache 由三个部分组成: default pool,keep pool 和Recycle pool. 每个Pool 都有自己的LRU来管理.
  (1)The default pool is for everythingelse.
  (2)The recycle pool is for larger objects.
  (3)The keep pool's purpose is to takesmall objects that should always be cached, for example Look Up Tables.
  
  1.1 相关理论知识
  1.1.1 BUFFER_POOL
The BUFFER_POOL clause letsyou specify a default buffer pool (cache) for aschema object. All blocks for the object are stored in the specified cache.
-- 缓冲池子句可指定一个数据库对象的默认缓冲池。这个对象的所有数据块存储在指定的缓存中。
If you define a buffer poolfor a partitioned table or index, then the partitions inherit the buffer poolfrom the table or index definition, unless overridden by a partition-leveldefinition.
--如果给一个分区表或索引指定了缓冲池,那么该表或索引的分区也同样使用指定的缓冲池,除非在分区的定义中指定分区使用的缓冲池。

For an index-organized table,you can specify a buffer pool separately for the index segment and the overflowsegment.
--对于一个索引组织表,可以为索引段和溢出段分别指定缓冲池。
  
  (1)Restrictions on BUFFER_POOL
You cannot specify this clausefor a cluster table. However, you can specify it for a cluster.
--不能在聚集表上指定缓冲池,但是,可以在一个聚集上指定缓冲池。
You cannot specify this clausefor a tablespace or for a rollback segment.
--不能在表空间或回滚段上指定缓冲池。
(2)KEEP
Specify KEEP to put blocksfrom the segment into the KEEP buffer pool. Maintaining an appropriately sizedKEEP buffer pool lets Oracle retain the schema object in memory to avoid I/Ooperations. KEEP takes precedence over any NOCACHEclause you specify for a table, cluster, materialized view, ormaterialized view log.
--指定KEEP将把数据块放入KEEP缓冲池中。维护一个适当尺寸的KEEP缓冲池可以使Oracle在内存中保留数据库对象而避免I/O操作。在表、聚集、实体化视图或实体化视图日志上,KEEP子句的优先权大于NOCACHE子句。
(3)RECYCLE
Specify RECYCLE to put blocksfrom the segment into the RECYCLE pool. An appropriately sized RECYCLE poolreduces the number of objects whose default pool is the RECYCLE pool fromtaking up unnecessary cache space.
--指定RECYCLE将把数据块放入RECYCLE缓冲池中。一个适当尺寸的RECYCLE缓冲池可以减少默认缓冲池为RECYCLE缓冲池的数据库对象的数量,以避免它们占用不必要的缓冲空间。
(4) DEFAULT
Specify DEFAULT to indicatethe default buffer pool. This is the default for objects not assigned to KEEPor RECYCLE.
--指定DEFAULT将适用默认的缓冲池。这个选项适用于没有分配给KEEP缓冲池和RECYCLE缓冲池的其它数据库对象。
(5)bufferpool 说明
在没有多个缓冲池的数据库中,所有的数据库对象使用同样的缓冲池,这样就会形成一种情况:
当希望某个频繁使用的数据库对象一直保留在缓冲池中时,一个大的、不经常使用的数据库对象会把它“挤”出缓冲池。这样就会降低缓冲池的效率,增加额外的I/O操作。
使用多个缓冲池后,可以更精确的调整缓冲池的使用,频繁使用数据库对象的缓冲池放在KEEP缓冲池中,大的、不经常使用的数据库对象放在RECYCLE缓冲池中,其它的数据库对象放在DEFAULT缓冲池中。
  
  1.1.2 CACHE |NOCACHE | CACHE READS
Use the CACHE clauses toindicate how Oracle should store blocks in the buffer cache. If you specifyneither CACHE nor NOCACHE:
--使用CACHE子句可制定Oracle在缓冲中如何存贮数据块。如果没有指定CACHE或NOCACHE:
  
  In aCREATE TABLE statement, NOCACHE is the default
In an ALTER TABLE statement, the existing value is not changed.
--在CREATE TABLE语句中,默认为NOCACHE。
--在ALTERTABLE语句中,不会改变当前表的CACHE/NOCACHE值。
(1)CACHEClause
For data that is accessedfrequently, this clause indicates that the blocks retrieved for this table areplaced at the most recently used end of the leastrecently used (LRU) list in the buffer cache when a full table scan isperformed. This attribute is useful for small lookup tables.
  --对于那些访问频繁的数据,这个子句可以指定当执行一个全表扫描时,将从表中获取的数据块放在缓冲中LRU列表的"最新使用"的一端。这个属性对小的查找表有用。
As a parameter in theLOB_storage_clause, CACHE specifies that Oracle places LOB data values in thebuffer cache for faster access.
--作为LOB存储子句的一个参数,CACHE可指定Oracle将LOB数据放在缓冲中,以便访问得更快。
(2)Restrictionon CACHE
You cannot specify CACHE foran index-organized table. However, index-organized tables implicitly provideCACHE behavior.
--不能在索引组织表上使用CACHE。但是,索引组织表隐式的提供了CACHE的效果。
(3)NOCACHEClause
For data that is not accessedfrequently, this clause indicates that the blocks retrieved for this table areplaced at the least recently used end of the LRU listin the buffer cache when a full table scan is performed.
--对于那些访问不频繁的数据,这个子句可以指定当执行一个全表扫描时,将从表中获取的数据块放在缓冲中LRU列表的“最久使用”的一端。

As a parameter in theLOB_storage_clause, NOCACHE specifies that the LOB value is either not broughtinto the buffer cache or brought into the buffer cache and placed at the leastrecently used end of the LRU list. (The latter is the default behavior.)
--作为LOB存储子句的一个参数,NOCACHE可指定Oracle将LOB数据不放在缓冲中或者放在缓冲中LRU列表的“最久使用”的一端。(后者是默认的做法。)
(4)Restrictionon NOCACHE
You cannot specify NOCACHE forindex-organized tables.
--不能在索引组织表上使用CACHE。
(5)CACHEREADS
CACHE READS applies only toLOB storage. It specifies that LOB values are brought into the buffer cacheonly during read operations, but not during write operations.
--CACHEREADS只适用于LOB存储。它指定当进行读操作时,将LOB放在缓冲中,而写操作时不这样做。

(6)说明
当BUFFER_POOL和CACHE同时使用时,KEEP比NOCACHE有优先权。
BUFFER_POOL用来指定存贮的缓冲池,而CACHE/NOCACHE指定存储的方式。
  
  1.2 官网说明
  It is possible to configure aRECYCLE buffer pool for blocks belonging to those segments that you do not wantto remain in memory. The RECYCLE pool is good forsegments that are scanned rarely or are not referenced frequently. If anapplication accesses the blocks of a very large object in a random fashion,then there is little chance of reusing a block stored in the buffer pool beforeit is aged out. This is true regardless of the size of the buffer pool (giventhe constraint of the amount of available physical memory). Consequently, theobject's blocks need not be cached; those cache buffers can be allocated toother objects.
  Memory is allocated to the RECYCLEbuffer pool by setting the parameter DB_RECYCLE_CACHE_SIZE to the required size. This memoryfor the RECYCLE buffer pool is not a subset of the default pool.
  Do not discard blocks from memorytoo quickly. If the buffer pool is too small, then blocks can age out of thecache before the transaction or SQL statement has completed execution. For example,an application might select a value from a table, use the value to process somedata, and then update the record. If the block is removed from the cache afterthe SELECT statement, then it must be read from disk again to perform theupdate. The block should be retained for the duration of the user transaction.
  
  http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/memory.htm#PFGRF94285
  
  1.3 说明
  Recycle Pool用于存储临时使用的、不被经常使用的较大的对象,这些对象放置在Default Buffer Pool显然是不合适的,这些块会导致过量的缓冲区刷新输出,而且不会带来任何好处,因为等你想要再用这个块时,它可已经老化退出了缓存。要把这些段与默认池和保持池中的段分开,这样就不会导致默认池和保持池中的块老化而退出缓存。
  
  对于Recycle Pool,先装载的表保留在RECYCLE池中。RECYCLE池满了之后,读取的数据不被缓存。读取没有进入过RECYCLE池的表,会替换掉最后进入RECYCLE池的很少的BLOCK,而且,缓存的BLOCK也可能会很快被替换出去,但是最少会保留1个BLOCK在缓存中。
  和全表扫描相比,索引扫描产生的CACHE被缓冲的优先级更高。
  
  二. 相关测试
  
  --查看db_recyle_cache_size
  SYS@anqing2(rac2)>show parameter db_recycle_cache_size
  
  NAME TYPE VALUE
  ----------------------------------------------- ------------------------------
  db_recycle_cache_size big integer 0
  
  --查看db_cache_size大小
  SYS@anqing2(rac2)>SELECT x.ksppinm NAME,y.ksppstvl VALUE, x.ksppdesc describ FROM SYS.x$ksppi x,SYS.x$ksppcv y WHERE x.indx = y.indx AND x.ksppinm LIKE '%__db_cache_size%';
  
  NAME VALUE DESCRIB
  ------------------------------ ------------------------------------------------
  __db_cache_size50331648 Actual size of DEFAULT buffer pool forstandard
  
  -- 查看keeppool 大小
  SYS@anqing2(rac2)>show parameter db_keep_cache_size
  
  NAME TYPE VALUE
  ----------------------------------------------- ------------------------------
  db_keep_cache_size big integer 100M
  
  --释放keeppool空间,然后分配给recycle pool
  SYS@anqing2(rac2)>alter system set db_keep_cache_size=0 scope=both sid='anqing2';
  Systemaltered.
  
  SYS@anqing2(rac2)>SELECT x.ksppinm NAME,y.ksppstvl VALUE, x.ksppdescdescrib FROM SYS.x$ksppi x, SYS.x$ksppcv y WHERE x.indx = y.indx AND x.ksppinmLIKE '%__db_cache_size%';
  
  NAME VALUE DESCRIB
  ------------------------------ ------------------------------------------------
  __db_cache_size155189248 Actual size of DEFAULT buffer pool forstandard
  SYS@anqing2(rac2)>alter system set db_recycle_cache_size=15M scope=bothsid='anqing2';
  Systemaltered.
  SYS@anqing2(rac2)>show parameter db_recycle_cache_size
  NAME TYPE VALUE
  ----------------------------------------------- ------------------------------
  db_recycle_cache_size big integer 16M
  SYS@anqing2(rac2)>SELECT x.ksppinm NAME,y.ksppstvl VALUE, x.ksppdescdescrib FROM SYS.x$ksppi x, SYS.x$ksppcv y WHERE x.indx = y.indx AND x.ksppinmLIKE '%__db_cache_size%';
  
  NAME VALUE DESCRIB
  ------------------------------ ------------------------------------------------
  __db_cache_size138412032 Actual size of DEFAULT buffer pool forstandard
  -- 当增加keep pool 或者 recycle pool 时,db_cache_size就会减小
  
  
  --创建table,并放入recycle pool
  SYS@anqing2(rac2)>create table r1 storage(buffer_pool recycle) as select * fromdba_objects;
  Tablecreated.
  SYS@anqing2(rac2)> create table r2 as select * from dba_objects;
  Tablecreated.
  SYS@anqing2(rac2)>alter table r2 storage(buffer_pool recycle);
  Tablealtered.
  
  --查看recyclepool中的对象
  SYS@anqing2(rac2)> select segment_name,blocks,bytes/1024/1024||'M'AS "SIZE" from dba_segments where BUFFER_POOL = 'RECYCLE';
  SEGMENT_NAME BLOCKS SIZE
  ----------------------- -----------------------------------------
  R1 768 6M
  R2 768 6M
  
  --查看v$bh 视图
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*)FROM V$BH A, USER_OBJECTS B WHERE A.OBJD = B.OBJECT_ID AND OBJECT_NAME IN('R1', 'R2') GROUP BY OBJECT_NAME,A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 xcur 1
  R1 xcur 1
  
  在我的Blog里:
  OracleBuffer Cache 原理
  http://blog.csdn.net/tianlesoftware/article/details/6573438
  
  有介绍过这个视图,Information on buffer headers. Contains a record(the buffer header) for each block in the buffer cache. 该视图的每一条记录就是一个block。
  
  这里看到,对r1和R2 都有1个block的cache。 这个是cache的最小单位。 即所有cache的table,至少会保留一个block,用来标记相关的信息。
  
  --全表扫描R1,让R1 加载进Cache。
  SYS@anqing2(rac2)>set autot on stat
  SYS@anqing2(rac2)>select count(*) from r1;
  COUNT(*)
  ----------
  50269
  Statistics
  ----------------------------------------------------------
  28recursive calls
  0db block gets
  786consistent gets
  690physical reads
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  --再次select,因为之前已经缓存过,所以现在不会有物理读
  SYS@anqing2(rac2)>select count(*) from r1;
  
  COUNT(*)
  ----------
  50269
  Statistics
  ----------------------------------------------------------
  0recursive calls
  0db block gets
  695consistent gets
  0physical reads --物理读为0
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  --查看v$bh 的缓存情况
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*)FROM V$BH A, USER_OBJECTS B WHEREA.OBJD = B.OBJECT_ID AND OBJECT_NAME IN ('R1', 'R2') GROUP BY OBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 xcur 1
  R1 xcur 1
  R1 scur 690
  
  XCUR:a current mode block, exclusive to this instance
  SCUR:a current mode block, shared with other instances
  
  注意:
  690+1=691 个blocks。 与之前查看的768个blocks 有出入。
  
  --我们对表R1 进行分析,在查看实际使用的Blocks
  SYS@anqing2(rac2)> exec dbms_stats.gather_table_stats('SYS','R1');
  PL/SQLprocedure successfully completed.
  --dba_tables 中的blocks必须在分析之后才有值
  SYS@anqing2(rac2)>select table_name,blocks from dba_tables where table_name='R1';
  TABLE_NAME BLOCKS
  ----------------------------------------
  R1 690
  --注意这里也是690.这个是我们实际使用的blocks数量,而我们通过dba_segmetns 表查看出来的是所有分配的blocks数量。
  -- 从这个结论,也可以推断出,当我们把objects keep 到对应pool 之后,分配的1个block 只是一个标记blocks,并不是我们真正的数据。
  
  
  --我们个Recycle pool 是15M,但系统分配了16M,R1和R2 表都是6M大,之前已经把R1,R2 keep 进去了,但R2的数据并没有刷到Recycle Pool。
  
  SYS@anqing2(rac2)> select count(*) from r2;
  
  COUNT(*)
  ----------
  50270
  
  Statistics
  ----------------------------------------------------------
  151recursive calls
  0db block gets
  793consistent gets
  690physical reads
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  3sorts (memory)
  0sorts (disk)
  1rows processed
  
  SYS@anqing2(rac2)>select count(*) from r2;
  COUNT(*)
  ----------
  50270
  Statistics
  ----------------------------------------------------------
  0recursive calls
  0db block gets
  695consistent gets
  0physical reads --第二次select 物理读为0
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  --查看v$bh缓存情况
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*)FROM V$BH A, USER_OBJECTS B WHEREA.OBJD = B.OBJECT_ID AND OBJECT_NAME IN ('R1', 'R2','R3') GROUP BY OBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 scur 690
  R2 xcur 1
  R1 scur 691
  --R1 和 R2 都缓存进去了,Recycle Pool 也满了
  
  --创建tableR3,也缓存到Recycle Pool
  SYS@anqing2(rac2)>create table r3 storage(buffer_pool recycle) asselect * from dba_objects;
  Tablecreated.
  
  SYS@anqing2(rac2)>select segment_name,blocks,bytes/1024/1024||'M' AS "SIZE" fromdba_segments where BUFFER_POOL = 'RECYCLE';
  
  SEGMENT_NAME BLOCKS SIZE
  ----------------------- -----------------------------------------
  R1 768 6M
  R2 768 6M
  R3 768 6M
  
  --查看V$bh
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*)FROM V$BH A, USER_OBJECTS B WHEREA.OBJD = B.OBJECT_ID AND OBJECT_NAME IN ('R1', 'R2') GROUP BY OBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 scur 690
  R2 xcur 1
  R1 scur 691
  R3 xcur 1
  
  --我们select一下,看能cache 多少blocks 进来
  SYS@anqing2(rac2)>select count(*) from r3;
  COUNT(*)
  ----------
  50271
  
  Statistics
  ----------------------------------------------------------
  28recursive calls
  0db block gets
  766consistent gets
  690physical reads --第一次物理读了690个blocks
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  SYS@anqing2(rac2)>/
  
  COUNT(*)
  ----------
  50271
  
  Statistics
  ----------------------------------------------------------
  0recursive calls
  0db block gets
  695consistent gets
  0physical reads --第二次没有物理读
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  --查看V$bh 视图
  SYS@anqing2(rac2)>SELECTOBJECT_NAME, A.STATUS, COUNT(*) FROMV$BH A, USER_OBJECTS B WHERE A.OBJD =B.OBJECT_ID AND OBJECT_NAME IN ('R1', 'R2','R3') GROUP BY OBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 scur 690
  R3 xcur 1
  R3 scur 690
  R2 xcur 1
  R1 scur 691
  -- R3 也cache 进来了,
  
  --查看recyclepool 大小
  SYS@anqing2(rac2)>show parameter db_recycle_cache_size
  
  NAME TYPE VALUE
  ----------------------------------------------- ------------------------------
  db_recycle_cache_size big integer 16M
  
  --三个表数据全部cache进去了,但是3*6M,需要18M的空间,肯定是放不下的,在次查看一下:
  
  SYS@anqing2(rac2)>SELECT SUBSTR (SUM (b.NUMBER_OF_BLOCKS) * 8129 / 1024 / 1024, 1, 5) ||'M'Total_Size
  2FROM ( SELECT o.OBJECT_NAME,COUNT (*)NUMBER_OF_BLOCKS
  3FROM DBA_OBJECTS o, V$BHbh,dba_segments dd
  4WHERE o.DATA_OBJECT_ID=bh.OBJD
  5 AND o.OWNER = dd.owner
  6 AND dd.segment_name=o.OBJECT_NAME
  7 AND dd.buffer_pool= 'RECYCLE'
  8 GROUP BY o.OBJECT_NAME
  9ORDER BY COUNT (*)) b;
  /
  TOTAL_SIZE
  -----------
  16.07M
  
  实际也使用了16M的空间。 在keep 一个大表进去
  SYS@anqing2(rac2)>alter table rb_test storage(buffer_pool recycle);
  Tablealtered.
  
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*)FROM V$BH A, USER_OBJECTS B WHEREA.OBJD = B.OBJECT_ID AND OBJECT_NAME IN ('R1', 'R2','R3','RB_TEST') GROUP BY OBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 scur 690
  R3 xcur 1
  R3 scur 690
  R2 xcur 1
  RB_TEST scur 597
  R1 scur 691
  
  6 rowsselected.
  
  SYS@anqing2(rac2)>SELECT SUBSTR (SUM (b.NUMBER_OF_BLOCKS) * 8129 / 1024 / 1024, 1, 5) ||'M'Total_Size
  2FROM ( SELECT o.OBJECT_NAME,COUNT (*)NUMBER_OF_BLOCKS
  3FROM DBA_OBJECTS o, V$BH bh,dba_segments dd
  4WHERE o.DATA_OBJECT_ID=bh.OBJD
  5 AND o.OWNER = dd.owner
  6 AND dd.segment_name=o.OBJECT_NAME
  7 AND dd.buffer_pool ='RECYCLE'
  8GROUP BY o.OBJECT_NAME
  9ORDER BY COUNT (*)) b;
  /
  TOTAL_SIZE
  -----------
  20.69M
  
  SYS@anqing2(rac2)>select count(*) from rb_test;
  COUNT(*)
  ----------
  4000000
  
  Statistics
  ----------------------------------------------------------
  127recursive calls
  0db block gets
  11047consistent gets
  10416physical reads --第一次会产生物理读
  0redo size
  411bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  4sorts (memory)
  0sorts (disk)
  1rows processed
  
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*) FROM V$BH A, USER_OBJECTS B WHERE A.OBJD = B.OBJECT_ID AND OBJECT_NAME IN('R1', 'R2','R3','RB_TEST') GROUP BYOBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 scur 690
  R3 xcur 1
  R3 scur 690
  R2 xcur 1
  RB_TEST scur 10845
  R1 scur 691
  
  6 rowsselected.
  
  SYS@anqing2(rac2)>SELECT SUBSTR (SUM (b.NUMBER_OF_BLOCKS) * 8129 / 1024 / 1024, 1, 5) ||'M'Total_Size
  2FROM ( SELECT o.OBJECT_NAME,COUNT (*)NUMBER_OF_BLOCKS
  3FROM DBA_OBJECTS o, V$BH bh,dba_segments dd
  4WHERE o.DATA_OBJECT_ID=bh.OBJD
  5 AND o.OWNER = dd.owner
  6 AND dd.segment_name=o.OBJECT_NAME
  7 AND dd.buffer_pool ='RECYCLE'
  8GROUP BY o.OBJECT_NAME
  9ORDER BY COUNT (*)) b;
  /
  TOTAL_SIZE
  -----------
  100.1M
  
  
  SYS@anqing2(rac2)>select count(*) from rb_test;
  
  COUNT(*)
  ----------
  4000000
  Statistics
  ----------------------------------------------------------
  0recursive calls
  0db block gets
  11029consistent gets
  543physical reads --第二次select ,有少量物理读
  0redo size
  411bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*)FROM V$BH A, USER_OBJECTS B WHEREA.OBJD = B.OBJECT_ID AND OBJECT_NAME IN ('R1', 'R2','R3','RB_TEST') GROUP BY OBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 scur 690
  R3 xcur 1
  R3 scur 690
  R2 xcur 1
  RB_TEST scur 11019
  R1 scur 691
  
  6 rowsselected.
  
  SYS@anqing2(rac2)> select count(*) fromrb_test;
  
  COUNT(*)
  ----------
  4000000
  
  Statistics
  ----------------------------------------------------------
  1recursive calls
  0db block gets
  11029consistent gets
  0physical reads --第三次select,没有物理读
  0redo size
  411bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  SYS@anqing2(rac2)>SELECT OBJECT_NAME, A.STATUS, COUNT(*)FROM V$BH A, USER_OBJECTS B WHEREA.OBJD = B.OBJECT_ID AND OBJECT_NAME IN ('R1', 'R2','R3','RB_TEST') GROUP BY OBJECT_NAME, A.STATUS;
  
  OBJECT_NAME STATUSCOUNT(*)
  -------------------- ----------
  R2 scur 690
  R3 xcur 1
  R3 scur 690
  R2 xcur 1
  RB_TEST scur 11019
  R1 scur 691
  6 rowsselected.
  
  SYS@anqing2(rac2)>SELECT SUBSTR (SUM (b.NUMBER_OF_BLOCKS) * 8129 / 1024 / 1024, 1, 5) ||'M'Total_Size
  2FROM ( SELECT o.OBJECT_NAME,COUNT (*)NUMBER_OF_BLOCKS
  3FROM DBA_OBJECTS o, V$BH bh,dba_segments dd
  4WHERE o.DATA_OBJECT_ID=bh.OBJD
  5 AND o.OWNER = dd.owner
  6AND dd.segment_name=o.OBJECT_NAME
  7 AND dd.buffer_pool ='RECYCLE'
  8GROUP BY o.OBJECT_NAME
  9ORDER BY COUNT (*)) b;
  /
  
  TOTAL_SIZE
  -----------
  101.4M
  
  SYS@anqing2(rac2)>select segment_name,blocks,bytes/1024/1024||'M' AS "SIZE" fromdba_segments where BUFFER_POOL = 'RECYCLE';
  
  SEGMENT_NAME BLOCKS SIZE
  ----------------------- -----------------------------------------
  R1 768 6M
  R2 768 6M
  R3 768 6M
  RB_TEST 11264 88M
  
  SYS@anqing2(rac2)> exec dbms_stats.gather_table_stats('SYS','RB_TEST');
  PL/SQLprocedure successfully completed.
  
  SYS@anqing2(rac2)>select table_name,blocks from dba_tables wheretable_name='RB_TEST';
  
  TABLE_NAME BLOCKS
  ----------------------------------------
  RB_TEST 11018
  
  --可以看到RB_TEST表的所有数据块也Cache到Recycle里了。
  
  
  --注意: 这里虽然Recyle Pool 变大了,但是db_cache_size 还是没有变
  SYS@anqing2(rac2)>SELECT x.ksppinm NAME,y.ksppstvl VALUE, x.ksppdesc describ FROM SYS.x$ksppi x,SYS.x$ksppcv y WHERE x.indx = y.indx AND x.ksppinm LIKE '%__db_cache_size%';
  
  NAME VALUE DESCRIB
  ------------------------------ ------------------------------------------------
  __db_cache_size138412032 Actual size of DEFAULTbuffer pool for standard
  
  
  在测试Keep Pool 的时候,放我们执行SQL>alter system flushbuffer_cache;
  会flush 掉keep Pool里的内容,现在我们flush 一下看看,验证下recycle pool里的内容能否flush 掉。
  
  SYS@anqing2(rac2)>alter system flush buffer_cache;
  Systemaltered.
  SYS@anqing2(rac2)>select count(*) from r1;
  COUNT(*)
  ----------
  50269
  Statistics
  ----------------------------------------------------------
  124recursive calls
  0db block gets
  705consistent gets
  695physical reads --所以,flush 也会清空recycle pool的内容
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  3sorts (memory)
  0sorts (disk)
  1rows processed
  
  SYS@anqing2(rac2)>select count(*) from r2;
  COUNT(*)
  ----------
  50270
  
  Statistics
  ----------------------------------------------------------
  0recursive calls
  0db block gets
  695consistent gets
  691physical reads
  0redo size
  413bytes sent via SQL*Net to client
  400bytes received via SQL*Net from client
  2SQL*Net roundtrips to/from client
  0sorts (memory)
  0sorts (disk)
  1rows processed
  
  
  SYS@anqing2(rac2)>col name for a40
  SYS@anqing2(rac2)>select * from v$sgainfo;
  NAME BYTESRES
  -------------------------------------------------- ---
  FixedSGA Size1267068 No
  RedoBuffers2924544 No
  Buffer Cache Size 159383552 Yes
  Shared Pool Size 109051904 Yes
  LargePool Size4194304 Yes
  JavaPool Size 4194304 Yes
  StreamsPool Size4194304 Yes
  GranuleSize4194304 No
  MaximumSGA Size285212672 No
  Startupoverhead in Shared Pool46137344 No
  FreeSGA Memory Available0
  
  11rows selected.
  
  SYS@anqing2(rac2)> create table r4 storage(buffer_pool recycle) as select *from dba_objects;
  Tablecreated.
  SYS@anqing2(rac2)>select count(*) from r4;
  
  SYS@anqing2(rac2)>select * from v$sgainfo;
  
  NAME BYTES RES
  ------------------------------------------ ---
  FixedSGA Size 1267068 No
  RedoBuffers 2924544 No
  Buffer Cache Size 159383552 Yes
  Shared Pool Size 109051904 Yes
  LargePool Size 4194304 Yes
  JavaPool Size 4194304Yes
  StreamsPool Size 4194304 Yes
  GranuleSize 4194304 No
  MaximumSGA Size 285212672 No
  Startupoverhead in Shared Pool 46137344 No
  FreeSGA Memory Available 0
  
  11rows selected.
  
  --通过以上测试,当Recycle Pool 增大的时候,DB buffer,shared Pool 大小并没有改变,所以在没有设置keep pool的情况下,Recycle pool 增大的内存来自与Defalut pool 减小的空间,而空间的增大和减小由ASMM 自动调整。
  
  
  小结:
  通过以上的测试,可以观察到,虽然我们的db_recycle_cache_size 只有16M,但是我们数据还是可以cache到里面,并且实际大小也会增加。 这是因为我们启动了ASMM (Automatic Shared Memory Management),启动ASMM之后,SGA可以进行自我调整的组件,该组件可以自动调整shared pool size、db cache size等SGA中的组件。
  所以虽然我们的的recycle pool 不大,但是通过ASMM 的自动调整,我们的数据还是可以keep 进去。
  启动ASMM,只需要设置sga_target参数,则其他组件就能够根据系统的负载和历史信息自动的调整各个部分的大小。还需要设置statistics_level为typical或all。
  
  
  yangtingkun 对这个recyclepool 也有测试,参考:
  http://yangtingkun.itpub.net/post/468/97277
  http://yangtingkun.itpub.net/post/468/94255
  http://yangtingkun.itpub.net/post/468/96169
  
  
  
  
  
  -------------------------------------------------------------------------------------------------------
  Blog: http://blog.csdn.net/tianlesoftware
  Email:dvd.dba@gmail.com
  DBA1 群:62697716(满);DBA2 群:62697977(满) DBA3 群:62697850(满)
  DBA 超级群:63306533(满);DBA4 群: 83829929 DBA5群:142216823
  DBA6 群:158654907 聊天 群:40132017 聊天2群:69087192
  --加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-250517-1-1.html 上篇帖子: oracle非阻塞读需要重视 下篇帖子: sql优化---oracle hint样例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表