频道栏目
首页 > 资讯 > Oracle > 正文

Latch的使用详解

13-10-30        来源:[db:作者]  
收藏   我要投稿
Latch的使用详解
 
     Latch是Oracle为了保护内存结构而发明的一种资源。常应用于并发的用户从磁盘中读取或写入数据。最常见的latch争用有:共享池中latch的争用和数据缓冲池中latch的争用。
1、共享池中latch的争用:
共享池中如果存在大量的SQL语句被反复分析,就很可能造成latch争用和长时间等待,常见的现象是由于没有绑定变量造成的。
SQL> select * from v$latchname where name like 'library cache%'

 

 
 
 
 
在分析系统性能时,如果有library cache这样的latch争用,基本可以断定是共享池中出现的问题,这种问题是由SQL语句导致的,比如没有绑定变量或者一些存储过程被反复分析。
 
2、数据缓冲池中latch的争用:
当很多用户一起去访问某几个数据块时,就会导致数据缓冲池的latch争用,主要有两种:buffer busy  waits 和 cache buffer chain。访问频率高的数据块被称为热块(hot block),当很多用户同时访问相同的数据块就会导致热块问题,造成热块的原因可能是数据库设置导致或者重复执行的SQL频繁的访问一些相同的数据块导致的。
 
 
 
2.1查询当前数据库最繁忙的Buffer:TCH(Touch)表示访问次数越高,热点块竞争问题就存在
  select *
  from (select addr,
  ts#,
  file#,
  dbarfil,
  dbablk,
  tch
  from x$bh
  order by tch desc)
  where rownum<11;
2.2结合dba_extents查询得到这些热点Buffer来自哪些对象
  select e.owner, e.segment_name, e.segment_type
  from dba_extents e,
  (select *
  from (select addr, ts#, file#, dbarfil, dbablk, tch
  from x$bh
  order by tch desc)
  where rownum<11) b
  where e.relative_fno=b.dbarfil
  and e.block_id<=b.dbablk
  and e.block_id+e.blocks>b.dbablk;
2.3结合SQL视图可以找到操作这些对象的相关SQL,然后通过优化SQL减少数据的访问,或者优化某些容易引起争用的操作(如connect by等操作)来减少热点块竞争
  break on hash_value skip 1
  select /*+ rule */ hash_value,sql_text
  from v$sqltext
  where (hash_value, address) in (
  select a.hash_value, a.address
  from v$sqltext a,
  (select distinct a.owner, a.segment_name, a.segment_type
  from dba_extents a,
  (select dbarfil, dbablk
  from (select  dbarfil, dbablk
  from x$bh
  order by tch desc)
  where rownum<11) b
  where a.relative_fno = b.dbarfil
  and a.block_id <= b.dbablk
  and a.block_id + a.blocks > b.dbablk) b
  where a.sql_text like ‘%’ || b.segment_name || ‘%’
  and b.segment_type = ‘TABLE’)
  order by  hash_value, address, piece;

 


相关TAG标签
上一篇:How to dump redo log entry
下一篇:C#多线程同步事件及等待句柄
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站