通过下列两种方式检查数据缓冲区设置是否合理:
查看数据库缓冲区的命中率,执行命令:
select 1 - ((physical.value - direct.value -lobs.value) / logical.value)
"Buffer Cache Hit Ratio"
from v$sysstat physical,v$sysstat direct,v$sysstat lobs,v$sysstatlogical
where physical.name = 'physical reads'
anddirect.name='physical reads direct'
andlobs.name='physical reads direct (lob)'
andlogical.name='session logical reads';
运行结果:
SQL> select 1 - ((physical.value - direct.value - lobs.value) /logical.value)
2 "Buffer Cache HitRatio"
3 from v$sysstatphysical,v$sysstat direct,v$sysstat lobs,v$sysstat logical
4 where physical.name ='physical reads'
5 and direct.name='physicalreads direct'
6 and lobs.name='physical readsdirect (lob)'
7 and logical.name='sessionlogical reads';
Buffer Cache Hit Ratio
----------------------
0.958117758479709
SQL>
惯例来说,上述语句当>0.9实说明调整充分的。命中率是高的,这里已经为0.95,所以命中率还是比较可观的。对于数据库系统而言,数据缓冲区中包括的DEFAULT缓冲池就足够应用需要了。
查询数据缓冲区中每个缓冲区的逻辑读和物理读的信息,可以查询动态性能视图v$buffer_pool_statistics,例如:
SQL> selectt1.name,t1.PHYSICAL_READS,t1.DB_BLOCK_GETS,t1.CONSISTENT_GETS,1-(t1.PHYSICAL_READS/(t1.DB_BLOCK_GETS+t1.CONSISTENT_GETS))"Hit Ratio"
2 from v$buffer_pool_statisticst1
3 ;
NAME PHYSICAL_READS DB_BLOCK_GETSCONSISTENT_GETS Hit Ratio
-------------------- --------------------------- --------------- ----------
DEFAULT 44480354387 571096618 33595740186 -0.3018575
SQL>
调整数据缓冲区大小
如果数据缓冲区小于90%,就要考虑调整数据缓冲区大小。增大数据缓冲区之前,先看看V$DB_CACHE_SIZE(select * from v$db_cache_advice),确定数据缓冲区增大到多少能够显著降低物理I/O的数量,然后动态修改初始化参数DB_CACHE_SIZE。初始化参数DB_CACHE_SIZE对应的是标准数据缓冲区大小,如果要修改非标准的数据缓冲区大小,需要修改初始化参数DB_nK_CACHE_SIZE(n取值为2、4、8、16、32,且n不能是标准数据块大小)