http://space.itpub.net/12361284/viewspace-154924

 

 

在系统运行过程中,如果我们发现Cache hit rate过小,或者我们通过观察statspack中的Instance Efficiency Percentages这部分呢,我们会发现Buffer Hit%的值很低,通常这就是在暗示你要增加DB_CACHE_SIZE了

1.通常的计算方法

可能大家都知道我们一般都是通过以下的公式来计算我们的buffer hit%的
Cache hit rate=((consistent_gets + db_block_gets) - physical_reads) /
(consistent_gets + db_block_gets)

2.进一步更精确的结果,我们需要考虑direct reads

如果Buffer hit%为85%,那么如果只是这样简单的按照上面的公式,计算得到85%的命中率,并不意味着miss rate=15%,因为15%中包括我们通常所说的direct reads。

direct reads一般发生在parallel scans和 reads from temporary tablespaces等情况下。blocks被直接读入私有PGA中的buffer,而没有经过SGA中的buffer cache.所以我们不应该把其算入内.

所以,如果我们通过查询v$sysstat来计算buffer hit%,可以去掉direct物理读部分,这样更新后的公式就是
Buffer hit = 1 - ((physical reads - physical reads direct - physical reads direct (lob)) /
(db block gets + consistent gets - physical reads direct - physical reads direct (lob))

另外,v$sysstat中的consistent_gets的值也有所夸大,可以累加以下4项得到:
no work - consistent read gets
cleanouts only - consistent read gets
rollbacks only - consistent read gets
cleanouts and rollbacks - consistent read gets

其实最好的方法是直接访问V$BUFFER_POOL_STATISTICS而不是v$sysstat,其中的数据都是排除了direct reads的结果。
比如
V$BUFFER_POOL_STATISTICS.physical_reads=v$sysstat 的'physical reads'- 'physical reads direct'- 'physical reads direct (lob)'

这样可以直接运行下面的语句来计算我们的Buffer Hit%:


select name, ((consistent_gets + db_block_gets) - physical_reads) /
(consistent_gets + db_block_gets) * 100 "Hit Ratio%"
from v$buffer_pool_statistics
where physical_reads > 0;