关于Oracle数据库latch: cache buffers chains等待事件

latch: cache buffers chains等待事件的原理

当一个数据块读入到sga中时,该块的块头(buffer header)会放置在一个hash bucket的链表(hash chain)中。该内存结构由一系列cache buffers chains子latch保护(又名hash latch或者cbc latch)。对Buffer cache中的块,要select或者update、insert,delete等,都得先获得cache buffers chains子latch,以保证对chain的排他访问。若在过程中发生争用,就会等待latch:cache buffers chains事件。

latch: cache buffers chains等待事件产生原因

我们先看看Oracle官方对latch:cache buffers chains等待事件的说明:

latch: cache buffers chains:

"latch: cache buffers chains" contention is typically encountered because SQL statements read more buffers than they need to and multiple sessions are waiting to read the same block.

If you have high contention, you need to look at the statements that perform the most buffer gets and then look at their access paths to determine whether these are performing as efficiently as you would like.

Typical solutions are:-

•Look for SQL that accesses the blocks in question and determine if the repeated reads are necessary. This may be within a single session or across multiple sessions.

•Check for suboptimal SQL (this is the most common cause of the events) - look at the execution plan for the SQL being run and try to reduce the gets per executions which will minimize the number of blocks being accessed and therefore reduce the chances of multiple sessions contending for the same block.

1. 低效率的SQL语句(主要体现在逻辑读过高)

在某些环境中,应用程序打开执行相同的低效率SQL语句的多个并发会话,这些SQL语句都设法得到相同的数据集,每次执行都带有高BUFFER_GETS(逻辑读取)的SQL语句是主要的原因。相反,较小的逻辑读意味着较少的latch get操作,从而减少锁存器争用并改善性能。注意v$sql中BUFFER_GETS/EXECUTIONS大的语句。

2.Hot block热点块

当多个会话重复访问一个或多个由同一个子cache buffers chains锁存器保护的块时,热块就会产生。当多个会话争用cache buffers chains子锁存器时,就会出现这个等待事件。有时就算调优了SQL,但多个会话同时执行此SQL,那怕只是扫描特定少数块,也是也会出现HOT BLOCK的。

如果是存在热点块,那么介绍两种找出热点块的方法。

找出热点块方法一:

--首先找出p1raw

[SQL] syntaxhighlighter_viewsource syntaxhighlighter_copycodeselect p1, p1raw

from v$session_wait

where event = 'latch: cache buffers chains';

--再根据p1raw找到对象

[SQL] syntaxhighlighter_viewsource syntaxhighlighter_copycodeSELECT /*+ RULE */

E.OWNER || '.' || E.SEGMENT_NAME SEGMENT_NAME,

E.PARTITION_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 = '00000003576EE324' --p1raw

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] syntaxhighlighter_viewsource syntaxhighlighter_copycodeSELECT OBJECT_NAME, SUBOBJECT_NAME

FROM DBA_OBJECTS

WHERE DATA_OBJECT_ID IN

(SELECT DATA_OBJECT_ID

FROM (SELECT OBJ DATA_OBJECT_ID, FILE#, DBABLK, CLASS, STATE, TCH

FROM X$BH

WHERE HLADDR IN (SELECT ADDR

FROM (SELECT ADDR

FROM V$LATCH_CHILDREN

ORDER BY (GETS + MISSES + SLEEPS) DESC)

WHERE ROWNUM < 10)

ORDER BY TCH DESC)

WHERE ROWNUM < 10);

分析latch: cache buffers chains,查找逻辑读较多的SQL进行分析:

Problem: Database is slow and 'latch: cache buffers chains' is high in the waits in AWR.

Start with Top 5 Waits:

Top 5 Timed Events                                      Avg    %Total

~~~~~~~~~~~~~~~~~~                                      wait   Call

Event                          Waits        Time (s)    (ms)   Time   Wait Class

------------------------------ ------------ ----------- ------ ------ ----------

latch: cache buffers chains          74,642      35,421    475    6.1 Concurrenc

CPU time                                         11,422           2.0

log file sync                        34,890       1,748     50    0.3 Commit

latch free                            2,279         774    340    0.1 Other

db file parallel write               18,818         768     41    0.1 System I/O

-------------------------------------------------------------

High cache buffers chains latch indicates that there is likely to be something reading a lot of buffers. Typically the SQL with the most gets is likely to be that which is contending:

SQL ordered by Gets         DB/Inst:  Snaps: 1-2

-> Resources reported for PL/SQL code includes the resources used by all SQL

statements called by the code.

-> Total Buffer Gets:   265,126,882

-> Captured SQL account for   99.8% of Total

Gets                CPU      Elapsed

Buffer Gets    Executions   per Exec     %Total Time (s) Time (s)  SQL Id

-------------- ------------ ------------ ------ -------- --------- -------------

256,763,367       19,052     13,477.0   96.8 ######## ######### a9nchgksux6x2

Module: JDBC Thin Client

SELECT * FROM SALES ....

1,974,516      987,056          2.0    0.7    80.31    110.94 ct6xwvwg3w0bv

SELECT COUNT(*) FROM ORDERS ....

The Query with SQL_ID a9nchgksux6x2 is reading 100x more buffers than the 2nd most 'hungry' statement and CPU and Elapsed are off the 'scale' of the report.  This is a prime candidate for the cause of the CBC latch issues.

You can also link this information to the Top  Segments by Logical Reads:

Segments by Logical Reads

-> Total Logical Reads:     265,126,882

-> Captured Segments account for   98.5% of Total

Tablespace                      Subobject  Obj.       Logical

Owner         Name    Object Name            Name     Type         Reads  %Total

---------- ---------- -------------------- ---------- ----- ------------ -------

DMSUSER    USERS      SALES                           TABLE  212,206,208   80.04

DMSUSER    USERS      SALES_PK                        INDEX   44,369,264   16.74

DMSUSER    USERS      SYS_C0012345                    INDEX    1,982,592     .75

DMSUSER    USERS      ORDERS_PK                       INDEX      842,304     .32

DMSUSER    USERS      INVOICES                        TABLE      147,488     .06

-------------------------------------------------------------

The top object read is SALES and the top SQL is a select from SALES which appears to correlate towards this being a potential problem select.

This SQL should be investigated to see if the Gets per Exec or the Executions figure per hour has changed in any way (comparison to previous reports would show this) and if so the reasons for that change investigated and resolved.

In this case the statement is reading > 10,000 buffers per execution and executing > 15,000 times

so both of these may need to be adjusted to get better performance.

Note: This is a simple example where there is a high likelihood that the 'biggest' query is the culprit but it is not always the 'Top' SQL that causes the problem. For example, contention may occur on a statement with a smaller total if it is only executed a small number of times so that  it may not appear as the top sql. It may still make millions of buffer gets, but will appear lower in the list because other sqls are performing many times, just not contending.

So, if the first SQL is not the culprit then look at the others.

oracle数据库latch,关于Oracle数据库latch: cache buffers chains等待事件相关推荐

  1. latch:cache buffers chains等待事件导致的latch争用的原理原因与检查

    latch:cache buffers chains 原理 当一个数据块读入到sga中时,该块的块头(buffer header)会放置在一个hash bucket的链表(hash chain)中.该 ...

  2. 深入理解latch: cache buffers chains

    事件背景:    一个客户的数据库发生了宕机事件,查看了数据库的awr报告,原来是由于出现大量的latch: cache buffers chains等待事件导致系统消耗量大量的CPU,最终导致系统h ...

  3. 深入理解 latch: cache buffers chains

    事件背景:    一个客户的数据库发生了宕机事件,查看了数据库的awr报告,原来是由于出现大量的latch: cache buffers chains等待事件导致系统消耗量大量的CPU,最终导致系统h ...

  4. Oracle latch: cache buffers chains

    buffer cache深度分析之buffer cache的优化 buffer cache的等待事件     与buffer cache相关的等待事件包括:latch free.buffer busy ...

  5. oracle等待资源时间加长,案例:Oracle等待事件latch: cache buffers chains故障优化处理总结...

    天萃荷净 数据库的CPU使用率为100%,应用相应迟缓.查看AWR中数据库的latch:cache buffers chains等待较多 当一个数据块读入sga区,相应的buffer header会被 ...

  6. mysql闩_Oracle闩:Cache Buffers chains

    Latch cache buffers chains大约是Oracle中child latch数量最多,使用最为频繁的闩锁了.其子闩总数受到初始化参数(8i中的db_block_buffers/4)的 ...

  7. oracle中的latch: cache buffers chains 与热块

    oracle中的latch: cache buffers chains 与热块 oracle中的latch: cache buffers chains 与热块 ORACLE中的buffer cache ...

  8. Oracle等待事件(一)—— latch cache buffers chains 分析与优化思路

    一. 什么是CBC等待 首先我们需要知道CBC等待发生在哪里,为什么会发生,才能理解应该如何定位,如何处理. 首先,CBC latch是用于保护buffer cache的,因此CBC等待一定发生在bu ...

  9. latch: cache buffers chains故障处理总结

    客户说数据库的CPU使用率为100%,应用相应迟缓. 发现是latch: cache buffers chains 作祟 故障分析思路 查看等待事件,判断故障起因 1 SQL>select * ...

最新文章

  1. android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形scale动画...
  2. 搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡
  3. 涉及的一些操作的命令
  4. Angular本地数据存储LocalStorage
  5. XML 命名空间以及它们如何影响 XPath 和 XSLT (Extreme XML)
  6. [html] 如何给input的右上角加个清除的按钮?
  7. 从底层重学 Java 之两大浮点类型 GitChat链接
  8. CentOS下添加Root权限用户‘超级用户’方法(xxx is not in the sudoers file.This incident will be reported.的解决方法)
  9. Focal loss及其实现
  10. 「Photoshop 入门教程」如何在Mac版 Photoshop 中打开图像?
  11. float的比较要慎重
  12. mysql主从备份功能配置与測试
  13. nvme固态硬盘开机慢_固态硬盘速度慢?三步教你开启SSD全速模式!
  14. 威纶触摸屏在easybuilder中如何组态添加滑动开关元件?
  15. linux表示虚拟字符终端,终端,控制台,虚拟终端分别指什么
  16. SLIC超像素算法学习笔记
  17. 【终极】文件夹隐藏方法,彻底隐藏文件夹的方法!显示隐藏的文件也看不到
  18. python期权价格计算器_GitHub - QSCTech-Sange/Options-Calculator: 期权价格计算器——金融工程第二次展示...
  19. 闭关之 C++ Template 笔记(一):PartⅠ基本概念(一)
  20. wireshark抓组播数据_wireshark过滤?wireshark 看端口号?wireshark组播包?WireShark 过滤语法...

热门文章

  1. python外国网站爬虫_Python3网络爬虫(一):利用urllib进行简单的网页抓取
  2. 好书推荐:《商贸与文明》
  3. 论文水记|How to Train Triplet Networks with 100K Identities?
  4. Android中ExpandableListView中嵌套ListView
  5. 这些安全类书籍值得一读
  6. 简单聊聊FPGA的一些参数——后篇
  7. python星号和双星号的区别
  8. web前端技术笔记(十六)bootstrap、表单正则和前端优化
  9. 碗状碎块三维模型的下载(.PLY格式)3D model file with Bowl-shaped Broken Piece (.ply format)
  10. Ubuntu 11.10 图形(图解)安装教程、基本设置、网络设置、软件源、硬件驱动