日期:2014-05-16  浏览次数:20510 次

Oracle中各个命中率的总结及调优笔记整理

关于Oracle中各个命中率的计算以及相关的调优

1)Library Cache的命中率 :

.计算公式 :Library Cache Hit Ratio = sum(pinhits) / sum(pins)

SQL>SELECT SUM(pinhits)/sum(pins)??

???? FROM V$LIBRARYCACHE;

通常在 98%以上,否则,需要要考虑加大共享池,绑定变量,修改 cursor_sharing等参数。

?

2)计算共享池内存使用率 :

SQL>SELECT (1 - ROUND(BYTES / (&TSP_IN_M * 1024 * 1024), 2)) * 100 || '%'

??? ?FROM V$SGASTAT

??? ?WHERE NAME = 'free memory' AND POOL = 'shared pool';

其中 : &TSP_IN_M 是你的总的共享池的 SIZE(M)

?

共享池内存使用率,应该稳定在 75%-90%间,太小浪费内存,太大则内存不足。

查询空闲的共享池内存 :

SQL>SELECT * FROM V$SGASTAT

??? ?WHERE NAME = 'free memory' AND POOL = 'shared pool';

?

3)db buffer cache命中率 :

计算公式 :Hit ratio = 1 - [physical reads/(block gets + consistent gets)]

SQL>SELECT NAME, PHYSICAL_READS, DB_BLOCK_GETS, CONSISTENT_GETS,

????? 1 - (PHYSICAL_READS / (DB_BLOCK_GETS + CONSISTENT_GETS)) "Hit Ratio"

????? FROM V$BUFFER_POOL_STATISTICS

????? WHERE NAME='DEFAULT';

通常应在 90%以上,否则,需要调整 ,加大 DB_CACHE_SIZE

?

另外一种计算命中率的方法 (摘自 ORACLE官方文档 <<数据库性能优化 >>):

命中率的计算公式为 : Hit Ratio = 1 - ((physical reads - physical reads direct - physical reads direct (lob)) / (db block gets + consistent gets - physical reads direct - physical reads direct (lob))

分别代入上一查询中的结果值 ,就得出了 Buffer cache的命中率

SQL>SELECT NAME, VALUE

??? ?FROM V$SYSSTAT

??? ?WHERE NAME IN('session logical reads',

?'physical reads',

?'physical reads direct',

?????????????? 'physical reads direct (lob)',

?????????????? 'db block gets', 'consistent gets');

?

4)数据缓冲区命中率:

SQL> select value from v$sysstat where name ='physical reads';

SQL> select value from v$sysstat where name ='physical reads direct';

SQL> select value from v$sysstat where name ='physical reads direct (lob)';

SQL> select value from v$sysstat where name ='consistent gets';

SQL> select value from v$sysstat where name = 'db block gets';

这里命中率的计算应该是

x = physical reads direct +