Cache buffers chains latch 与Cache buffers LRU chain latch

来源:互联网 发布:sql upper 编辑:程序博客网 时间:2024/05/16 00:32

Cache buffers chains latch官方解释

      This latch is acquired whenever a block in the buffer cache is accessed (pinned).Reducing contention for the cache buffer chains latch will usually require reducing logical I/O rates by tuning and minimizing the I/O requirements of the SQL involved. High I/O rates could be a sign of a hot block (meaning a block highly accessed).

      理解:当一个数据块读入sga区,相应的buffer header会被放置到bucket(Hash buckets are grouped by relative data block address and class number)下的hash列表上。如果一个进程想访问或修改hash chain上的block,需要先hash算法到bucket,然后在bucket里面扫描一个链表,需要获取 latch:cache buffers chains保护内存结构。

      原因一:低效率的SQL语句(主要体现在逻辑读过高),cache buffers chains latch很大程度与逻辑读有关,所以要观注v$sql中BUFFER_GETS/EXECUTIONS大的语句。同时每一个逻辑读需要一个latch get 操作及一个cpu操作,这样的sql也会很耗cpu资源。

      原因二:热块(访问过于频繁)。



Cache buffers 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.

Solutions

  • Consider implementing multiple buffer pools to reduce contention on this latch.
  • Increase the number of LRU latches with the parameter DB_BLOCK_LRU_LATCHES. Generally the default value works.
  • Reduce data blocks visited by a query and thereby reduce LRU latch requests in the buffer pool by tuning the SQ

可能原因:

想查看或者修改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语句上。


参考惜分飞blog: http://www.xifenfei.com/3097.html   http://www.xifenfei.com/1109.html

原创粉丝点击