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 数据库数据操作如何精通 INSERT, UPDATE, DELETE

《Oracle数据库数据操作如何精通INSERT,UPDATE,DELETE》在Oracle数据库中,对表内数据进行增加、修改和删除操作是通过数据操作语言来完成的,下面给大家介绍Oracle数... 目录思维导图一、插入数据 (INSERT)1.1 插入单行数据,指定所有列的值语法:1.2 插入单行数据,指

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

解决mysql插入数据锁等待超时报错:Lock wait timeout exceeded;try restarting transaction

《解决mysql插入数据锁等待超时报错:Lockwaittimeoutexceeded;tryrestartingtransaction》:本文主要介绍解决mysql插入数据锁等待超时报... 目录报错信息解决办法1、数据库中执行如下sql2、再到 INNODB_TRX 事务表中查看总结报错信息Lock

Java 的 Condition 接口与等待通知机制详解

《Java的Condition接口与等待通知机制详解》在Java并发编程里,实现线程间的协作与同步是极为关键的任务,本文将深入探究Condition接口及其背后的等待通知机制,感兴趣的朋友一起看... 目录一、引言二、Condition 接口概述2.1 基本概念2.2 与 Object 类等待通知方法的区别

Oracle 通过 ROWID 批量更新表的方法

《Oracle通过ROWID批量更新表的方法》在Oracle数据库中,使用ROWID进行批量更新是一种高效的更新方法,因为它直接定位到物理行位置,避免了通过索引查找的开销,下面给大家介绍Orac... 目录oracle 通过 ROWID 批量更新表ROWID 基本概念性能优化建议性能UoTrFPH优化建议注

PostgreSQL 序列(Sequence) 与 Oracle 序列对比差异分析

《PostgreSQL序列(Sequence)与Oracle序列对比差异分析》PostgreSQL和Oracle都提供了序列(Sequence)功能,但在实现细节和使用方式上存在一些重要差异,... 目录PostgreSQL 序列(Sequence) 与 oracle 序列对比一 基本语法对比1.1 创建序

Python开发文字版随机事件游戏的项目实例

《Python开发文字版随机事件游戏的项目实例》随机事件游戏是一种通过生成不可预测的事件来增强游戏体验的类型,在这篇博文中,我们将使用Python开发一款文字版随机事件游戏,通过这个项目,读者不仅能够... 目录项目概述2.1 游戏概念2.2 游戏特色2.3 目标玩家群体技术选择与环境准备3.1 开发环境3

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.