Oracle数据库关于命中率的查询语句总结

1) Library Cache的命中率
公式:Library Cache Hit Ratio=SUM(PINHITS)/SUM(PINS)
SELECT SUM(PINHITS)/SUM(PINS) FROM V$LIBRARYCACHE;

命中率不能低于99%,否则需要考虑是否受共享池大小,绑定变量,cursor_sharing等因素的影响。
SELECT NAME,VALUE FROM V$PARAMETER WHERE NAME='cursor_sharing'

2) Shared Pool的使用率
公式:Shared Pool Hit Ratio=(100-Free memory/shared_pool_size*100)%
如果数据库采用AMM方式管理内存使用以下语句获取Shared Pool大小:

SELECT POOL,ROUND(SUM(BYTES)/1024/1024,2) FROM V$SGASTAT where POOL='shared pool' group by POOL;

如果是采取Manual方式管理内存则:
SELECT NAME,VALUE FROM V$PARAMETER WHERE NAME='shared_pool_size';

查询1:

SELECT 100 - ROUND((SELECT ROUND(SUM(BYTES) / 1024 / 1024, 2) BYTES
                      FROM V$SGASTAT
                    WHERE NAME = 'free memory'
                      AND POOL = 'shared pool'
                    GROUP BY POOL) / ROUND(SUM(BYTES) / 1024 / 1024, 2),
                  4) * 100 || '%' RATIOS
 FROM V$SGASTAT
 where POOL = 'shared pool'
 GROUP BY POOL

查询2:
SELECT 100 - ROUND(B.BYTES / ROUND(SUM(A.BYTES) / 1024 / 1024, 2),4)*100 || '%' RATIOS
  FROM V$SGASTAT A,
      (SELECT POOL,ROUND(SUM(BYTES) / 1024 / 1024, 2) BYTES
          FROM V$SGASTAT
        WHERE NAME = 'free memory' AND POOL='shared pool' GROUP BY POOL) B
 where A.POOL = 'shared pool' GROUP BY B.BYTES,A.POOL

共享池使用率应稳定在75%-90%间,过小则浪费,过大说明内存不足或语句重用性不高。

相关推荐