Oracle等待事件之buffer busy waits

2024-02-05 16:48

本文主要是介绍Oracle等待事件之buffer busy waits,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

产生原因

官方定义:

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')
--------------1SQL> 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')
--------------27SQL> 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=21         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          110 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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/681555

相关文章

Oracle数据库常见字段类型大全以及超详细解析

《Oracle数据库常见字段类型大全以及超详细解析》在Oracle数据库中查询特定表的字段个数通常需要使用SQL语句来完成,:本文主要介绍Oracle数据库常见字段类型大全以及超详细解析,文中通过... 目录前言一、字符类型(Character)1、CHAR:定长字符数据类型2、VARCHAR2:变长字符数

C#如何动态创建Label,及动态label事件

《C#如何动态创建Label,及动态label事件》:本文主要介绍C#如何动态创建Label,及动态label事件,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C#如何动态创建Label,及动态label事件第一点:switch中的生成我们的label事件接着,

Oracle存储过程里操作BLOB的字节数据的办法

《Oracle存储过程里操作BLOB的字节数据的办法》该篇文章介绍了如何在Oracle存储过程中操作BLOB的字节数据,作者研究了如何获取BLOB的字节长度、如何使用DBMS_LOB包进行BLOB操作... 目录一、缘由二、办法2.1 基本操作2.2 DBMS_LOB包2.3 字节级操作与RAW数据类型2.

查看Oracle数据库中UNDO表空间的使用情况(最新推荐)

《查看Oracle数据库中UNDO表空间的使用情况(最新推荐)》Oracle数据库中查看UNDO表空间使用情况的4种方法:DBA_TABLESPACES和DBA_DATA_FILES提供基本信息,V$... 目录1. 通过 DBjavascriptA_TABLESPACES 和 DBA_DATA_FILES

spring @EventListener 事件与监听的示例详解

《spring@EventListener事件与监听的示例详解》本文介绍了自定义Spring事件和监听器的方法,包括如何发布事件、监听事件以及如何处理异步事件,通过示例代码和日志,展示了事件的顺序... 目录1、自定义Application Event2、自定义监听3、测试4、源代码5、其他5.1 顺序执行

Oracle登录时忘记用户名或密码该如何解决

《Oracle登录时忘记用户名或密码该如何解决》:本文主要介绍如何在Oracle12c中忘记用户名和密码时找回或重置用户账户信息,文中通过代码介绍的非常详细,对同样遇到这个问题的同学具有一定的参... 目录一、忘记账户:二、忘记密码:三、详细情况情况 1:1.1. 登录到数据库1.2. 查看当前用户信息1.

Go 1.23中Timer无buffer的实现方式详解

《Go1.23中Timer无buffer的实现方式详解》在Go1.23中,Timer的实现通常是通过time包提供的time.Timer类型来实现的,本文主要介绍了Go1.23中Timer无buff... 目录Timer 的基本实现无缓冲区的实现自定义无缓冲 Timer 实现更复杂的 Timer 实现总结在

oracle DBMS_SQL.PARSE的使用方法和示例

《oracleDBMS_SQL.PARSE的使用方法和示例》DBMS_SQL是Oracle数据库中的一个强大包,用于动态构建和执行SQL语句,DBMS_SQL.PARSE过程解析SQL语句或PL/S... 目录语法示例注意事项DBMS_SQL 是 oracle 数据库中的一个强大包,它允许动态地构建和执行

PLsql Oracle 下载安装图文过程详解

《PLsqlOracle下载安装图文过程详解》PL/SQLDeveloper是一款用于开发Oracle数据库的集成开发环境,可以通过官网下载安装配置,并通过配置tnsnames.ora文件及环境变... 目录一、PL/SQL Developer 简介二、PL/SQL Developer 安装及配置详解1.下

oracle如何连接登陆SYS账号

《oracle如何连接登陆SYS账号》在Navicat12中连接Oracle11g的SYS用户时,如果设置了新密码但连接失败,可能是因为需要以SYSDBA或SYSOPER角色连接,解决方法是确保在连接... 目录oracle连接登陆NmOtMSYS账号工具问题解决SYS用户总结oracle连接登陆SYS账号