作为本系列最后的部分,我们一起来看看recycle池的使用情况。
6、子池对象定义和特性——Recycle池
recycle池是与keep池相对应的一个buffer cache子池。对recycle池的缓存数据块而言,同样是使用LRU算法、同样要面临age out问题。下面我们通过一系列的实验,来说明特征。
首先,我们先设置buffer cache的recycle池。
SQL> select component, current_size, min_size, max_size from v$sga_dynamic_components where component in ('DEFAULT buffer cache','KEEP buffer cache','RECYCLE buffer cache');
COMPONENT CURRENT_SIZE MIN_SIZE MAX_SIZE
-------------------- ------------ ---------- ----------
DEFAULT buffer cache 79691776 79691776 0
KEEP buffer cache 0 0 0
RECYCLE buffer cache 0 0 0
设置专门的区域
SQL> show parameter db_recycle
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recycle_cache_size big integer 0
设置recycle池大小。
--设置recycle池
SQL> alter system set db_recycle_cache_size=20M;
System altered
SQL> select component, current_size, min_size, max_size from v$sga_dynamic_components where component in ('DEFAULT buffer cache','KEEP buffer cache','RECYCLE buffer cache');
COMPONENT CURRENT_SIZE MIN_SIZE MAX_SIZE
-------------------- ------------ ---------- ----------
DEFAULT buffer cache 58720256 58720256 0
KEEP buffer cache 0 0 0
RECYCLE buffer cache 20971520 0 0
在scott用户下,建立recycle缓存数据表t_rec。
SQL> show user;
User is "scott"
SQL> create table t_recycle as select * from dba_objects where wner='SCOTT';
Table created
--设置其在recycle池中;
SQL> alter table t_recycle storage(buffer_pool recycle);
Table altered
--清除buffer cache缓存;
SQL> alter system flush buffer_cache;
System altered
使用autotrace进行检查。
--第一次执行
SQL> select count(*) from t_recycle;
已用时间: 00: 00: 00.10
统计信息
----------------------------------------------------------
130 recursive calls
0 db block gets
18 consistent gets
5 physical reads
0 redo size
--第二次调用
SQL> select count(*) from t_recycle;
已用时间: 00: 00: 00.01
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
调用之前脚本,可以发现当前recycle池的确发挥作用。
SQL> select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',
2 4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',
3 7,'16K SUBCACHE',8,'32K SUBCACHE','UNKNOWN') subcache,
4 bh.object_name,
5 bh.blocks
6 from x$kcbwds ds,
7 x$kcbwbpd pd,
8 (select /*+ use_hash(x) */ set_ds,
9 o.name object_name,
10 count(*) BLOCKS
11 from obj$ o,
12 x$bh x
13 where o.dataobj# = x.obj
14 and x.state !=0 --and o.owner# !=0
15 group by set_ds,o.name) bh
16 where ds.set_id >= pd.bp_lo_sid
17 and ds.set_id <= pd.bp_hi_sid
18 and pd.bp_size != 0
19 and ds.addr=bh.set_ds
20 and bh.object_name='T_RECYCLE';
SUBCACHE OBJECT_NAME BLOCKS
------------ ------------------------------ ----------
RECYCLE T_RECYCLE 3
从上面两个SQL的执行情况可以知道一个重要问题:recycle池对象缓存的数据块并不是读取出来之后,直接age out出去。Recycle数据块同样存在一定的缓存周期和缓存时间。只是说,在recycle池中的数据块独立成池,快速的age out不会影响到keep和default池的工作情况。
NOTE:recycle数据块也是可以发挥出数据缓存的作用的。
和keep池相似,sys数据表是不是也存在recycle无效的情况呢?我们进行下面实验。
SQL> show user;
User is "SYS"
SQL> create table t_rec as select * from dba_objects where wner='SCOTT';
Table created
SQL> alter table t_rec storage(buffer_pool recycle);
Table altered
SQL> alter system flush buffer_cache;
System altered
实验SQL:
SQL> select count(*) from t_rec;
已用时间: 00: 00: 00.06
统计信息
----------------------------------------------------------
128 recursive calls
0 db block gets
18 consistent gets
5 physical reads
SQL> select count(*) from t_rec;
已用时间: 00: 00: 00.00
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
缓存作用在上面连续执行的SQL中得到发挥。
SQL> select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',
2 4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',
3 7,'16K SUBCACHE',8,'32K SUBCACHE','UNKNOWN') subcache,
4 bh.object_name,
5 bh.blocks
6 from x$kcbwds ds,
7 x$kcbwbpd pd,
8 (select /*+ use_hash(x) */ set_ds,
9 o.name object_name,
10 count(*) BLOCKS
11 from obj$ o,
12 x$bh x
13 where o.dataobj# = x.obj
14 and x.state !=0 --and o.owner# !=0
15 group by set_ds,o.name) bh
16 where ds.set_id >= pd.bp_lo_sid
17 and ds.set_id <= pd.bp_hi_sid
18 and pd.bp_size != 0
19 and ds.addr=bh.set_ds
20 and bh.object_name='T_REC';
SUBCACHE OBJECT_NAME BLOCKS
------------ ------------------------------ ----------
RECYCLE T_REC 2
DEFAULT T_REC 1
上面实验说明,SYS用户的数据表在recycle池中的特殊情况的确存在。但是,recycle池是会使用到的,default也会存在使用的情况。
7、结论
Oracle Buffer Cache是利用物理缓存速度远高于外存储器的特点,而设计出的数据库技术。借助Buffer Cache,我们可以有效的减少物理读,实现整体的数据库性能提升。
但是,不同数据在业务上就存在优先级的问题。于是,为了更好地应用LRU算法和Buffer Cache Block List,Oracle提出了sub pool的概念,让用户自己进行数据划分。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/17203031/viewspace-715260/ ,如需转载,请注明出处,否则将追究法律责任。