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%間,過小則浪費,過大說明記憶體不足或語句重用性不高。