配置和使用Shared Pool and Large Pool
[@more@]包括PL/SQL blocks and SQL,dictionary cache data和其他。正确配置的好处在于:
1、 避免SQL重复parse,减少CPU资源使用
2、 减少latch资源争用
3、 减少IO,因为dictionary elements避免了访问磁盘
Shared Pool Concepts
包括library cache 和dictionary cache,根据需要自动增加或减少。
library cache包括parsed or compiled的PL/SQL blocks 和 SQL以及JAVA类。
dictionary cache 存放了来自 data dictionary的数据。比如usernames, segment information, profile data, tablespace information, and sequence numbers等,在解析和编译SQL时引用.
Shared Pool 的cache miss开销比buffer cache的大很多,所以要谨慎设置。
共享池内存分配以chunks(大块)为单位,这样允许大对象(5K)直接CACHE到内存中,而不需要申请一段连续的空间,这样可以减少碎片带来的空间浪费.
reserved pool:Shared Pool隔离出来的一小段,用来存放大于5k的大对象.
Hard / soft parse:
Soft parse使用的资源包括CPU 和library cache latch gets
Hard parse是指要解析的SQL没有在library cache中,或者执行的时候发现解析过的SQL已经aged out,就是离开了library cache,称为Library cache misses.使用的资源包括额外的CPU, library cache latch gets, 以及shared pool latch gets.
Using the Shared Pool Effectively
Shared Cursors
SQL中尽量指定表的owner,而不使用public synonyms.,可以significantly reduces the number of entries in the dictionary cache.令一种方法是使用同样的USERID访问数据库.尽量使用存储过程.
避免在高峰时期执行DDL,因为这样会使相关连的SQL失效,要重新编译.
Cache Sequence Numbers可以减少dictionary cache locks,比如:ALTER SEQUENCE customers_seq CACHE 5; 事先cache 5个.2~28
Sizing the Shared Pool
不能太大,因为需要维护共享的结构,同时使得SQL的老化的代价更高,带来大量的管理开销,导致CPU的严重问题.在充分利用绑定变量的系统,通常100m(1G)~300m(8G), erp 可以达到500m.
Library Cache 的配置:
可以通过以下3点判断:
1)V$LIBRARYCACHE:
RELOAD列反映了之前已经CACHE的对象,后来AGED OUT了,然后又被re-load (re-parsing)的SQL数量.因为其object handle已经建立,所以会有这个统计结果.期望值应该为0.
INVALIDATIONS 列反映了对象失效的次数,导致的原因比如DDL操作等.系统高峰时期的期望值应该为0.如果过大,应该减少高峰时期DDL操作,或者适当减小共享池配置.
PINS:The number of times a PIN was requested for objects of this namespace
PINHITS:The number of times all of the metadata pieces of the library object were found in memory
SELECT namespace, pins, pinhits, reloads, invalidations
FROM V$LIBRARYCACHE
ORDER BY namespace;
NAMESPACE PINS PINHITS RELOADS INVALIDATIONS
--------------- ---------- ---------- ---------- -------------
SQL AREA 21536413 21520516 11204 2
...
SQL AREA部分,执行了21536413次,11204次导致library cache miss,需要reparse SQL或者reload定义;2次INVALIDATIONS,同样导致library cache miss
Library Cache Hit Ratio = sum(pinhits) / sum(pins)
2)V$SGASTAT:
高峰时期检查pool=’shared pool’ and name=’free memory’值,应该尽量低.
3)Library cache hit ratio:
考察hard parsing rate的大小,是否有shared pool latch 和 library cache latch的竞争.
Shared Pool Advisory Statistics
V$SHARED_POOL_ADVICE.ESTD_LC_TIME_SAVED:表示Parse time saved
V$LIBRARY_CACHE_MEMORY: library cache中各个命名空间的具体内存
Dictionary Cache的配置:
通常shared pool满足了library cache后,dictionary cache也会被满足.
Instance刚启动的时候,dictionary cache没有任何的数据.任何的SQL都会导致cache miss.逐渐的,数据越多,miss越小.
V$ROWCACHE记录了library cache中每种数据字典item类型的统计信息:
Parameter:数据字典item类型
Gets: 对这种类型数据的请求次数.
Getsmiss:请求失败,需要IO读取磁盘
Modifications: 数据被修改(update, insert , delete)的次数
Interpreting Shared Pool Statistics
增大shared_pool_size的同时,考虑增加open_cursors参数(cursors permitted for a session).
如果reloads接近0,并且有大量的free memory,可以适当减小shared_pool_size
使用Large Pool
Large pool没有LRU链,oracle不会将对象aged out.Large pool用于以下情况:
Parallel query并行查询,Recovery Manager,shared server
Tuning the Large Pool and Shared Pool for the Shared Server Architecture
使用large pool to allocate the shared server-related User Global Area (UGA),配置LARGE_POOL_SIZE,最小300k,查询v$sgastat
Even though use of shared memory increases with shared servers, the total amount of memory use decreases. This is because there are fewer processes; therefore, Oracle uses less PGA memory with shared servers when compared to dedicated server environments.
For best performance with sorts using shared servers, set SORT_AREA_SIZE and SORT_AREA_RETAINED_SIZE to the same value. This keeps the sort result in the large pool instead of having it written to disk.
V$SESSTAT:
Session UGA memory: The value of this statistic is the amount of memory in bytes allocated to the session. (If the sessions are connected to dedicated server processes, then this memory is part of the memories of the user processes. If the sessions are connected to shared server processes, then this memory is part of the shared pool.可以根据这个值来配置large pool)
Session UGA memory max: The value of this statistic is the maximum amount of memory in bytes ever allocated to the session.
PRIVATE_SGA:
来限制没个session从SGA中得到多少内存,很少用到.
使用CURSOR_SPACE_FOR_TIME(……)
配置Reserved Pool(……)
Keeping Large Objects to Prevent Aging(……)
CURSOR_SHARING for Existing Applications(……)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28211342/viewspace-2130966/ ,如需转载,请注明出处,否则将追究法律责任。