shared pool latch 等待事件

shared pool latch相关描述

The shared pool latch is used to protect critical operations when allocating 
and freeing memory in the shared pool. 
If an application makes use of literal (unshared) SQL then this can severely 
limit scalability and throughput. The cost of parsing a new SQL statement is 
expensive both in terms of CPU requirements and the number of times the library 
cache and shared pool latches may need to be acquired and released. Before Oracle9, 
there was just one such latch for the entire database to protect the allocation of 
memory in the library cache. In Oracle9, multiple children were introduced to relieve
contention on this resource.

减少shared pool latch方法

Avoid hard parses when possible, parse once, execute many. 
Eliminate  literal SQL so that same sql is shared by many sessions.
Size the shared_pool adequately to avoid reloads
Use of MTS (shared server option) also greatly influences the shared pool latch. 

查询未绑定sql

--9i
SELECT substr(sql_text,1,40) "SQL", 
         count(*) , 
         sum(executions) "TotExecs"
    FROM v$sqlarea
   WHERE executions < 5
   GROUP BY substr(sql_text,1,40)
  HAVING count(*) > 30
   ORDER BY 2
  ;

--10g及其以后版本
SET pages 10000
SET linesize 250
column FORCE_MATCHING_SIGNATURE format 99999999999999999999999
WITH c AS
     (SELECT  FORCE_MATCHING_SIGNATURE,
              COUNT(*) cnt
     FROM     v$sqlarea
     WHERE    FORCE_MATCHING_SIGNATURE!=0
     GROUP BY FORCE_MATCHING_SIGNATURE
     HAVING   COUNT(*) > 20
     )
     ,
     sq AS
     (SELECT  sql_text                ,
              FORCE_MATCHING_SIGNATURE,
              row_number() over (partition BY FORCE_MATCHING_SIGNATURE ORDER BY sql_id DESC) p
     FROM     v$sqlarea s
     WHERE    FORCE_MATCHING_SIGNATURE IN
              (SELECT FORCE_MATCHING_SIGNATURE
              FROM    c
              )
     )
SELECT   sq.sql_text                ,
         sq.FORCE_MATCHING_SIGNATURE,
         c.cnt "unshared count"
FROM     c,
         sq
WHERE    sq.FORCE_MATCHING_SIGNATURE=c.FORCE_MATCHING_SIGNATURE
AND      sq.p                       =1
ORDER BY c.cnt DESC

查询数据库整体解析情况

select to_char(100 * sess / calls, '999999999990.00') || '%' cursor_cache_hits, 
to_char(100 * (calls - sess - hard) / calls, '999990.00') || '%' soft_parses, 
to_char(100 * hard / calls, '999990.00') || '%' hard_parses 
from ( select value calls from v$sysstat where name = 'parse count (total)' ), 
( select value hard from v$sysstat where name = 'parse count (hard)' ), 
( select value sess from v$sysstat where name = 'session cursor cache hits' );

参考:Note 62143.1 Troubleshooting: Tuning the Shared Pool and Tuning Library Cache Latch

发表在 Oracle性能优化 | 评论关闭

Oracle 8.0.5 安装过程截图

此多媒体陈列厅包含 7 张图像

作为新一代dba(包括我),很少有机会能够接触到ORACLE 8.0.5数据库. … 继续阅读

更多多媒体陈列厅 | 一条评论

cache buffer lru chain latch等待事件

cache buffer lru chain latch官方解释

The cache buffer lru chain latch is acquired in order to introduce a new block into the buffer cache 
and when writing a buffer back to disk, specifically when trying to scan the LRU (least recently used) chain 
containing all the dirty blocks in the buffer cache.

cache buffer lru chain latch可能原因

想查看或者修改LRU+LRUW的进程,始终要持有cache buffers lru chain latch。
若在此过程中发生争用,则要等待latch:cache buffers lru chain 事件。
总结出来如下两种情况会导致cache buffers lru chain latch:
1.进程欲读取还没有装载到内存上的块时,通过查询LRU 列分配到所需空闲缓冲区,在此过程中需要cache buffers lru chain latch。
2.DBWR 为了将脏缓冲区记录到文件上,查询LRUW 列,将相应缓冲区移动到LRU 列的过程中也要获得cache buffers lru chain latch。
2.1)DBWR在如下情况下将脏缓冲区记录到文件里。
2.2)Oracle 进程为了获得空闲缓冲区,向DBWR 请求记录脏缓冲区时;
2.3)Oracle进程为执行Parallel Query 或Tablespace Backup,Truncate/Drop 等工作,请求记录相关对象的脏缓冲区时; 
2.4)周期性或管理上的原因检查点(checkpointing)被执行时。
2.5)Oracle 为了保障将通过FAST_START_MTTR_TARGET(或LOG_CHECKPOINT_TIMEOUT)指定的时间的恢复,周期性执行检查点。
2.6)管理员执行检查点命令或根据日志文件切换,也会发生检查点。

cache buffers lru chain latch争用的最重要的原因是过多请求空闲缓冲区。低效的SQL语句是过多请求空闲缓冲区的最典型情况,若多个会话同时执行低效的SQL语句,则在查询空闲缓冲区过程中和记录脏缓冲区的过程中,为了获取buffers lru chain latch发生争用。多个会话同时扫描不同表或索引时,发生cache buffers lru chain latch争用的概率高。多个会话将各不相同的块载入到内存过程中,确保空闲缓冲区的请求会增多,因此发生对工作组争用的概率将提高。特别是因为数据修改频繁,以至于脏缓冲区数量多,正因此DBWR 因为检查点而查询LRUW 列的次数频繁,所以cache buffers lru chain latch争用将更加严重。cache buffers lru chain latch争用的另一个重要特点就是伴随着物理I/O。若是低效的索引扫描引起的问题,则同时发生db file sequential read 等待和lru chain latch争用;若是不必要的全表扫描引起的问题,则同时发生db file scattered read 等待和lru chain latch争用。事实上,cache buffers chains latch争用和cache buffers lru chain latch争用同时发生的情况较多,因为复杂的应用程序将复合地应用上述模式。data buffer过小或检查点周期过短时,也会增加cache buffers lru chain latch争用;但是现在的数据库的data buffer都不会太小,而检查点周期一般使用缺省值,所以通常定位cache buffers lru chain latch的原因还是在低效的SQL语句上

发表在 Oracle性能优化 | 评论关闭