必知:java
Latch集中于Buffer Cache的竞争和Shared Pool的竞争。和Buffer Cache相关的主要Latch竞争有cache buffers chains和cache buffers lru chain,和Shared Pool相关的主要Latch竞争有shared pool latch和library cache latch等。sql
Buffer Cache的Latch竞争常常是因为热点块竞争引发的;Shared Pool的Latch竞争一般是因为sql的大量硬解析引发的。缓存
热快是一种致使Oracle cache buffers chains latch(cbc)等待事件最多见的缘由,网络上有大多只是简单的将热快做为产生CBC等待事件的代名词,网络
其实产生cbc等待事件有两种常见的缘由:session
引自Tom大师: The first main type of latch that will be detailed for Oracle is called the buffer cache latch. The buffer cache latch family consists of two types of latches: the cache buffers chain latch; the other is the cache buffers LRU chain latch. Another factor for latch contention with buffers chain latches could possibly be hot block contention. Oracle Metalink Note # 163424.1 has some useful tips on tuning and identifying hot blocks within the Oracle database environment. The other buffer cache latch type is the cache buffers LRU chain latch. Whenever a new block enters the Oracle buffer cache within the SGA, this latch is acquired to allow block management in the Oracle SGA. Also, the latch is acquired when buffers are written back to disk such as when a scan is performed to move the LRU or least recently used chain of dirty blocks to flush out to disk from the buffer cache.
第一种:热快(hot block);ide
第二种:cachebuffers LRU chain( cache buffers LRU chain latch);性能
再看看Oracle官方文档对CBClatch描述:
优化
Description--描述 The cache buffers chains latches are used to protect a buffer list in the buffer cache. These latches are used when searching for, adding, or removing a buffer from the buffer cache. --cbclatch用来保护buffercache中的buffer列表。 这些latch可从buffer中进行搜索、添加、移除。 Blocks in the buffer cache are placed on linked lists (cache buffer chains) which hang off a hash table. The hash chain that a block is placed on is based on the DBA and CLASS of the block. Each hash chain is protected by a single child latch. Processes need to get the relevant latch to allow them to scan a hash chain for a buffer so that the linked list does not change underneath them. --处于缓存区中的块被搁置在buffer列表上,这些块挂着一个hash表。 --挂载哈希链的块是基于DBA 和 CLASS块,每个hash链被一个子latch所保护。而进程须要访问buffer中的块必须先得到cbclatch。
Contention on this latch usually means that there is a block that is in great contention (known as a hot block). --这种latch争用一般意味着块的争用(这就是所谓的热快),也就是说默认CBClatch争用指的就是热快。
提供两种方法:
ui
1.首先经过v$latch_children视图定位访问缓存链较多且持有块多的内存地址以及休眠时间:this
SELECT addr, sleeps FROM v$latch_children c, v$latchname n WHERE n.name='cache buffers chains' and c.latch#=n.latch# and sleeps > 100 ORDER BY sleeps /
2.而后从v$bh 以及根据v$latch_children.add相关联,获取具体的文件和数据块号
SELECT file#, dbablk, class, state, TCH FROM X$BH WHERE HLADDR='address of latch'; --tch解释:tch:touch count for the buffer,经过tch来定位热快
3.最后经过上述2获取的数据块地址,再根据dba_extents定位具体的段。
select p1 "File #", p2 "Block #", p3 "Reason Code" from v$session_wait where event = 'buffer busy waits';
select owner, segment_name, segment_type from dba_extents where file_id = &P1 and &P2 between block_id and block_id + blocks -1;
1.产生cbc等待事件的缘由是热快,也就是说出现热快,就会出现cbc等待事件;
2.经过v$session_wait,x$bh,dba_extents相关联,直接定位热快的对应的具体段;
3.热快的优化无非就是优化SQL,具体的优化说来话长,固然后续有机会再慢慢说。
最后提供Oracle社区直接定位热快的脚本:
select /* 当心使用此脚本,有性能问题-如有疑问,请留言*/ e.owner ||'.'|| e.segment_name segment_name, e.extent_id extent#, x.dbablk - e.block_id + 1 block#, x.tch, l.child# from sys.v$latch_children l, sys.x$bh x, sys.dba_extents e where x.hladdr = 'ADDR' and e.file_id = x.file# and x.hladdr = l.addr and x.dbablk between e.block_id and e.block_id + e.blocks -1 order by x.tch desc;
脚本定位产生热快的SQL语句,请移步