Oracle热快-从认识到定位



必知:

Latch集中于Buffer Cache的竞争和Shared Pool的竞争。和Buffer Cache相关的主要Latch竞争有cache buffers chains和cache buffers lru chain,和Shared Pool相关的主要Latch竞争有shared pool latch和library cache latch等。

Buffer Cache的Latch竞争经常是由于热点块竞争引起的;Shared Pool的Latch竞争通常是由于sql的大量硬解析引起的。


      CBC latch简介

      热快是一种导致Oracle cache buffers chains latch(cbc)等待事件最常见的原因,网络上有大多只是简单的将热快作为产生CBC等待事件的代名词,

其实产生cbc等待事件有两种常见的原因:

引自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);

第二种:cachebuffers LRU chain( cache buffers LRU chain latch)


再看看Oracle官方文档对CBClatch描述:

Latch: cache buffer chains (%)

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。


CBC latch等待事件代言人——热快
Contention on this latch usually means that there is a block that is in great contention (known as a hot block).
--这种latch争用通常意味着块的争用(这就是所谓的热快),也就是说默认CBClatch争用指的就是热快。


寻找热快对象

提供两种方法:

第一种,来自Oracle官方文档:

1.首先通过v$latch_children视图定位访问缓存链较多且持有块多的内存地址以及休眠时间:

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定位具体的段。



第二种,来自Tom大师:
首先通过v$session_wait查找文件number号即P1:
select
   p1 "File #",
   p2 "Block #",
   p3 "Reason Code"
from
   v$session_wait
where
   event = 'buffer busy waits';
然后根据获取的file,block信息,通过dba_extents,查找具体的块
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语句,请移步

http://my.oschina.net/1272149624/blog/613508



转载于:https://my.oschina.net/1272149624/blog/614275

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值