oracle优化-shared pool

来源:互联网 发布:linux获取cpu核心数 编辑:程序博客网 时间:2024/06/05 18:43

Oracle优化中的shared pool tunning优化。

 

 

在oracle优化中,Shared pool的优化应该放在优先考虑,因为一个cache miss在shared pool中发生比在data buffer中发生导致的成本更高,由于dictionary数据一般比library cache中的数据在内存中保存的时间长,所以关键是library cache的优化。

 

Gets:(parse)在namespace中查找对象的次数;

 

Pins:(execution)在namespace中读取或执行对象的次数;

 

 

Reloads:(reparse)在执行阶段library cache misses的次数,导致sql需要重新解析。

 

1) 检查v$librarycache中sql area的gethitratio是否超过90%,如果未超过90%,应该检查应用代码,提高应用代码的效率

SQL> select gethitratio from v$librarycache where namespace='SQL AREA';

GETHITRATIO                                                                -----------                                                           .515739103

2) v$librarycache中reloads/pins的比率应该小于1%,如果大于1%,应该增加参数shared_pool_size的值

 

 SQL>  select sum(pins) "executions",sum(reloads) "cache misses", sum(reloads)/sum(pins) from v$librarycache;

 

executions cache misses SUM(RELOADS)/SUM(PINS)                                  

---------- ------------ ----------------------                                  

    366835         6828             .018613273  

 

 reloads/pins>1%有两种可能,一种是library cache空间不足,一种是sql中引用的对象不合法。

3)shared pool reserved size一般是shared pool size的10%,不能超过50%

 

V$shared_pool_reserved中的request misses=0或没有持续增长,或者free_memory大于shared pool reserved size的50%,表明shared pool reserved size过大,可以压缩

4)保留大的对象在shared pool中

 

大的对象是造成内存碎片的主要原因,为了腾出空间许多小对象需要移出内存,从而影响了用户的Oracle性能。因此需要将一些常用的大的对象保留在shared pool中,下列对象需要保留在shared pool中:

 

a. 经常使用的存储过程;

 

 

b. 经常操作的表上的已编译的触发器

 

 

c. Sequence,因为Sequence移出shared pool后可能产生号码丢失。

 

 

查找没有保存在library cache中的大对象:

 

SQL> select * from v$db_object_cache where

  2  sharable_mem>10000 and type in('package','procedure','function','package body') and kept='no';

 

no rows selected 

将这些对象保存在library cache中:

SQL> execute dbms_shared_pool.keep('package_name');

5)查找是否存在过大的匿名pl/sql代码块。两种解决方案:

 

A.转换成小的匿名块调用存储过程

 

 

B.将其保留在shared pool中

 

 

查找是否存在过大的匿名pl/sql块:

 

SQL> select sql_text from v$sqlarea where command_type=47 and length(sql_text)>500;

6)Dictionary cache的 优化

 

避免出现Dictionary cache的misses,或者misses的数量保持稳定,只能通过调整shared_pool_size来间接调整dictionary cache的大小。Percent misses应该很低:大部分应该低于2%,合计应该低于15%

SQL> select sum(getmisses)/sum(gets) from v$rowcache;

 

SUM(GETMISSES)/SUM(GETS)

------------------------

              .044162111

若超过15%,增加shared_pool_size的值。

 

增加shared_pool_size

SQL> alter system set shared_pool_size=2222;

不用加单位。


查看shared poolsize语句

select pool,sum(bytes)/1024/1024 || ' MB'  from v$sgastat where pool is not null group by pool;


原创粉丝点击