三、调整shared pool memory
用于缓冲SQL语句、PL/SQL块和其他内存对象,以减少CPU消耗和到达数据文件的I/O过程。
Shared pool memory包括 库缓冲、数据字典缓冲、字符集结构、锁结构、锁存器结构、排队结构。
库缓冲命名空间内存结构:select namespace,gets,gethits,gethitratio from v$librarycache;
对象类型:select * from v$library_cache_memory;
当前会话:select * from v$session_object_cache;
数据字典内存结构:select parameter ,count,usage,fixed from v$rowcache;
shared pool memory 应当是SGA总内存的30%-40%。
共享池不同结构大小:select * from v$sgastat where pool='shared pool';
Shared_pool_reserved_size 一般默认是 shared pool memory 大小的5%,最大值是10%。
保留shared pool memory统计:select free_space,request_failures,request_misses from v$shared_pool_reserved;
free_space:始终大于50%,就减少Shared_pool_reserved_size
request_failures:始终大于0,就增加Shared_pool_reserved_size
request_misses:始终小于等于0,就减少Shared_pool_reserved_size
建议查看:select * from v$shared_pool_advice;
诊断:
库缓冲
1、select namespace,gethitratio from v$librarycache;
1 SQL AREA 0.922011162276638
2 TABLE/PROCEDURE 0.993672142262278
3 BODY 0.99454343135466
4 TRIGGER 0.963121509019321
5 INDEX 0.980018227542776
6 CLUSTER 0.982589250059899
7 OBJECT 1
8 PIPE 0.992282074324682
9 JAVA SOURCE 1
10 JAVA RESOURCE 1
11 JAVA DATA 0.992904841402337 始终大于90%表示库高速缓冲中的对象正在超出范围,可能因为shared pool memory 不够大
2、select namespace,pinhitratio from v$librarycache;
1 SQL AREA 0.99132158903781
2 TABLE/PROCEDURE 0.977691736274111
3 BODY 0.981356955961079
4 TRIGGER 0.902006015785784
5 INDEX 0.977707757271772
6 CLUSTER 0.97099705960973
7 OBJECT 1
8 PIPE 0.992335232716454
9 JAVA SOURCE 1
10 JAVA RESOURCE 1
11 JAVA DATA 0.985271903323263 始终小于90%表示未在内存中找到执行过的对象,这是 shared pool memory不足。
3、select (reload_count/object_count)*100 reloads_ratio from (select sum(reloads) reload_count from v$librarycache),(select count(*) object_count from v$db_object_cache);
重新加载与库缓冲中被缓冲对象数量的比率小于5%。
4、select (invalidation_count/object_count)*100 invalidation_ratio from (select sum(invalidations) invalidation_count from v$librarycache),(select count(*) object_count from v$db_object_cache);
对象无效的数量的比率小于1%
5、select sum(reloads)/sum(pins)*100 reloads_pins_ration from v$librarycache;
引脚本数量与重新加载数量的比率小于1%
数据字典
1、 select parameter ,(sum(getmisses)/sum(gets))*100 getmisses_ratio from v$rowcache where gets>0 group by parameter; 失败的请求不能大于15%
select (used/value)*100 shared_pool_usage_ratio from v$parameter p,(select sum(bytes) used from v$sgastat where pool='shared pool'and name<>'free memory') where p.name='shared_pool_size';
共享池的利用率100%-80%分配不足(增加分配),80%-60%适当(最佳),60%-40%安全(可以接受),40%-20%关注过多(分配超过需要),20%-0%过度分配(浪费)。
select (s.bytes/p.value)*100 shared_pool_free_ratio from v$parameter p ,v$sgastat s where s.pool='shared pool' and s.name='free memory' and p.name='shared_pool_size';
共享池可用空间100%-40%过度分配,40%-20%安全,20%-10%适当,10%-0%分配不足。
select (s.bytes/used)*100 shared_pool_userd_free_ratio from v$sgastat s ,(select sum(bytes) used from v$sgastat where pool='shared pool' and name<> 'free memory'