Oracle等待事件之buffer busy waits

逻辑织雪使
• 阅读 2021

产生原因

官方定义:

This wait happens when a session wants to access a database block in the buffer cache but it cannot as the buffer is "busy". The two main cases where this can occur are:

  1. Another session is reading the block into the buffer
  2. Another session holds the buffer in an incompatible mode to our request

模拟等待

创建测试表并插入数据:

SQL> create table tb1 (id int ,name varchar2(10));

Table created.

SQL> insert into tb1 values (1,'scott');

1 row created.

SQL> insert into tb1 values (2,'tom');

1 row created.

SQL> commit;

Commit complete.

会话1修改数据:

SQL> select userenv('sid') from dual;

USERENV('SID')
--------------
             1
             
SQL> begin
for i in 1..100000 loop
update tb1 set name='rose' where id=2;
commit;
end loop;
end;
/

会话2修改数据:

SQL> select userenv('sid') from dual;

USERENV('SID')
--------------
            27

SQL> begin
for i in 1..100000 loop
update tb1 set name='john' where id=1;
commit;
end loop;
end;
/

在会话3查看等待情况:

--定位到造成等待的SQL
SQL> SELECT g.inst_id,g.sid,g.serial#,g.event,g.username,g.sql_hash_value,s.sql_fulltext
FROM gv$session g,v$sql s
WHERE g.sql_hash_value = s.hash_value and username='HR' and event='buffer busy waits';
   INST_ID        SID    SERIAL# EVENT                          USERNAME   SQL_HASH_VALUE SQL_FULLTEXT
---------- ---------- ---------- ------------------------------ ---------- -------------- --------------------------------------------------
         1          1          7 buffer busy waits              HR              401484711 UPDATE TB1 SET NAME='rose' WHERE ID=2
         1         27         49 buffer busy waits              HR             2040921087 UPDATE TB1 SET NAME='john' WHERE ID=1

--定位到热点快
SQL> select event,sid,p1,p2,p3 from v$session_wait_history where event='buffer busy waits'
EVENT                       SID         P1         P2         P3
-------------------- ---------- ---------- ---------- ----------
buffer busy waits             1          4       5471          1
buffer busy waits             1          4       5471          1
buffer busy waits             1          4       5471          1
buffer busy waits             1          4       5471          1
buffer busy waits             1          4       5471          1
buffer busy waits            27          4       5471          1
buffer busy waits            27          4       5471          1
buffer busy waits            27          4       5471          1
buffer busy waits            27          4       5471          1
buffer busy waits            27          4       5471          1

10 rows selected.

--P1=file#
--P2=block#

--定位到块所属的段
SQL> SELECT OWNER, SEGMENT_NAME, SEGMENT_TYPE, TABLESPACE_NAME, A.PARTITION_NAME FROM DBA_EXTENTS A WHERE FILE_ID = 4 AND 5471 BETWEEN BLOCK_ID AND BLOCK_ID + BLOCKS - 1;

OWNER      SEGMENT_NAME         SEGMENT_TYPE       TABLESPACE_NAME                PARTITION_NAME
---------- -------------------- ------------------ ------------------------------ ------------------------------
HR         TB1                  TABLE              USERS

解决方法

As buffer busy waits are due to contention for particular blocks then you cannot take any action until you know which blocks are being competed for and why. Eliminating the cause of the contention is the best option. Note that "buffer busy waits" for data blocks are often due to several processes repeatedly reading the same blocks (eg: if lots of people scan the same index) - the first session processes the blocks that are in the buffer cache quickly but then a block has to be read from disk - the other sessions (scanning the same index) quickly 'catch up' and want the block which is currently being read from disk - they wait for the buffer as someone is already reading the block in.

The following hints may be useful for particular types of contention - these are things that MAY reduce contention for particular situations:

Block TypePossible Actions
data blocksEliminate HOT blocks from the application. Check for repeatedly scanned / unselective indexes. Change PCTFREE and/or PCTUSED. Check for 'right- hand-indexes' (indexes that get inserted into at the same point by many processes). Increase INITRANS. Reduce the number of rows per block.
segment headerIncrease of number of FREELISTs. Use FREELIST GROUPs (even in single instance this can make a difference).
freelist blocksAdd more FREELISTS. In case of Parallel Server make sure that each instance has its own FREELIST GROUP(s).
undo headerAdd more rollback segments.

参考: WAITEVENT: "buffer busy waits" Reference Note (Doc ID 34405.1)

欢迎关注我的公众号,一起学习。

Oracle等待事件之buffer busy waits

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
美凌格栋栋酱 美凌格栋栋酱
6个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
Wesley13 Wesley13
3年前
java中比较两个时间的差值
项目背景1.某篇文稿的发布时间是publishDate,例如:2020072118:00:41。2.现要求判断该篇文稿的发布时间是否在近30天之内。publicstaticlongdayDiff(DatecurrentDate,DatepublishDate){LongcurrentTimecurrentDat
Wesley13 Wesley13
3年前
RAC环境单实例启动数据库收到ORA
     在RAC环境中,如果你在没有启动节点的集群服务的情况下单实例启动数据库,将收到类似如下的报错:\oracle@rhel1u01\$sqlSQL\Plus:Release10.2.0.5.0ProductiononTueApr215:00:272013Copyright(
Stella981 Stella981
3年前
KaliTools说明书+BurpSuit实战指南+SQL注入知识库+国外渗透报告
!(https://oscimg.oschina.net/oscnet/d1c876a571bb41a7942dd9752f68632e.gif"15254461546.gif")0X00KaliLinux Tools中文说明书!(https://oscimg.oschina.net/oscnet/
Wesley13 Wesley13
3年前
Oracle:如果表存在
我正在为Oracle数据库编写一些迁移脚本,并且希望Oracle有类似MySQL的IFEXISTS结构。具体来说,每当我想在MySQL中删除表时,我都会这样做DROPTABLEIFEXISTStable_name;这样,如果表不存在,DROP不会产生错误,脚本可以继续。Oracle是否有类似的机制?
Wesley13 Wesley13
3年前
MySQL总结(十一)子查询
!(https://oscimg.oschina.net/oscnet/upa344f41e81d3568e3310b5da00c57ced8ea.png)子查询1\.什么是子查询需求:查询开发部中有哪些员工selectfromemp;通
Wesley13 Wesley13
3年前
Oracle查询被锁的表以及解锁表
1.查询引起了锁表的原因selectl.session_idsid,s.serial,l.locked_mode,l.oracle_username,s.user,l.os_user_name,s
Stella981 Stella981
3年前
PostgreSQL Oracle 兼容性之
Oracle使用sys\_guid()用来产生UUID值。 在PostgreSQL中有类似的函数,需要安装uuidossp插件。 如果用户不想修改代码,还是需要使用sys\_guid()函数的话,可以自己写一个。 如下:1.postgres\createextension"uuidossp";2.CREATE
Wesley13 Wesley13
3年前
oracle查询表数据并重新插入到本表
oracle查询表数据并重新插入到本表CreateTime2018年5月17日10:30:10Author:Marydon1.情景描述查询表中数据SELECTFROMat_aut
为什么mysql不推荐使用雪花ID作为主键
作者:毛辰飞背景在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究