计算公式:Library Cache Hit Ratio = sum(pinhits) / sum(pins)
通常在98%以上,否则,需要要考虑加大共享池,绑定变量,修改cursor_sharing等参数。
其中: &TSP_IN_M是你的总的共享池的SIZE(M)
共享池内存使用率,应该稳定在75%-90%间,太小浪费内存,太大则内存不足。
查询空闲的共享池内存:
计算公式:Hit ratio = 1 - [physical reads/(block gets + consistent gets)]
通常应在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的命中率
这里命中率的计算应该是
令 x = physical reads direct + physical reads direct (lob)
命中率 =100 - ( physical reads - x) / (consistent gets + db block gets - x)*100
通常如果发现命中率低于90%,则应该调整应用可可以考虑是否增大数据缓冲区
假如共享池的命中率低于95%,就要考虑调整应用(通常是没使用bind var )或者增加内存
查询内存排序数 查询磁盘排序数
--caculate sort in memory ratio
此比率越大越好,太小整要考虑调整,加大PGA
计算公式:BP x 100 / (BP + EBP)
BP: bytes processed
EBP: extra bytes read/written
或者从OEM的图形界面中查看
我们可以查看一个视图以获取Oracle的建议值:
The output of this query might look like the following:
TARGET_MB CACHE_HIT_PERC ESTD_OVERALLOC_COUNT
---------- -------------- --------------------
63 23 367
125 24 30
250 30 3
375 39 0
500 58 0
600 59 0
700 59 0
800 60 0
900 60 0
在此例中:PGA至少要分配375M
我个人认为PGA命中率不应该低于50%
以下的SQL统计sql语句执行在三种模式的次数: optimal memory size, one-pass memory size, multi-pass memory size:
计算公式:SUM(gets - getmisses - usage -fixed) / SUM(gets)
命中率应大于0.85
计算公式:1-(physical reads / (db block gets + consistent gets))
命中率应大于0.90最好
计算公式:SUM(pins - reloads) / SUM(pins)
命中率应大于0.99
SUM(waits)值应小于SUM(gets)值的1%
+--------------------------几个常用的检查语句-------------------------------+
SQL>SELECT HASH_VALUE, SQL_TEXT, SORTS, EXECUTIONS FROM V$SQLAREA ORDER BY SORTS DESC;
SQL>SELECT * FROM (SELECT sql_text,disk_reads "total disk" , executions "total exec",disk_reads/executions "disk/exec" FROM v$sql WHERE executions>0 and is_obsolete='N' ORDER BY 4 desc) WHERE ROWNUMselect substr(to_char(s.pct, '99.00'), 2) || '%' load,s.executions executes,p.sql_text from(select address,disk_reads,executions,pct,rank() over (order by disk_reads desc) ranking from (select address,disk_reads,executions,100 * ratio_to_report(disk_reads) over () pct from sys.v_$sql where command_type != 47) where disk_reads > 50 * executions) s,sys.v_$sqltext p where s.ranking select executions,disk_reads,buffer_gets,round((buffer_gets-disk_reads)/buffer_gets,2) Hit_radio,round(disk_reads/executions,2) reads_per_run,sql_text From v$sqlarea Where executions>0 and buffer_gets >0 and (buffer_gets-disk_reads)/buffer_getsselect /*+ push_subq */command_type,sql_text,sharable_mem,persistent_mem,runtime_mem,sorts,version_count,loaded_versions,open_versions,users_opening,executions,users_executing,loads,first_load_time,invalidations,parse_calls,disk_reads,buffer_gets,rows_processed,sysdate start_time,sysdate finish_time,’>’||address sql_address,’N’status From v$sqlarea Where address=(select sql_address from v$session where sid=&sid);
+--------------------Oracle 缓冲区命中率低的分析及解决办法--------------------+
首先确定下面的查询结果:
select round((1 - sum(decode(name,'physical reads',value,0)) / (sum(decode(name,'db block gets',value,0)) + sum(decode(name,'consistent gets',value,0))) ),4) *100 || '%' chitrati from v$sysstat;
select count(*), status from v$bh group by status;
select event,total_waits from v$system_event where event in ('free buffer waits');
select value/1024/1024 cache_size from v$parameter where name='db_cache_size';
select event ,total_waits,suml from (select event,total_waits,round(total_waits/sumt*100,2)||'%' suml from (select event,total_waits from v$system_event ), (select sum(total_waits) sumt from v$system_event) order by total_waits desc) where rownumselect value from v$sysstat where name ='physical reads'; value 3714179 sql>select value from v$sysstat where name ='physical reads direct'; value 0 sql>select value from v$sysstat where name ='physical reads direct(lob)'; value 0 sql>select value from v$sysstat where name ='consistent gets'; value 856309623 sql>select value from v$sysstat where name ='db block gets'; value 19847790
这里命中率的计算应该是
令x=physical reads direct + physical reads direct(lob)
命中率=100-(physical reads -x)/(consistent gets +db block gets -x)*100
通常如果发现命中率低于90%,则应该调整应用可以考虑是否增大数据加
共享池的命中率
sql> select sum(pinhits)/sum(pins)*100 "hit radio" from v$librarycache;
如果共享池的命中率低于95%就要考虑调整应用(通常是没应用bind var)或者增加内存。
关于排序部分
sql> select name,value from v$sysstat where name like '%sort%';
如果我们发现sorts(disk)/(sorts(memory)+sorts(disk))的比例过高,则通常意味着sort_area_size部分内存教较小,可考虑调整相应的参数。
关于log_buffer
sql>select name,value from v$sysstat where name in ('redo entries','redo buffer allocation retries');
假如redo buffer allocation retries/redo entries的比例超过1%我们就可以考虑增加log_buffer.