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查询优化之高效实现仅查询前10条记录的方法与实践

《Oracle查询优化之高效实现仅查询前10条记录的方法与实践》:本文主要介绍Oracle查询优化之高效实现仅查询前10条记录的相关资料,包括使用ROWNUM、ROW_NUMBER()函数、FET... 目录1. 使用 ROWNUM 查询2. 使用 ROW_NUMBER() 函数3. 使用 FETCH FI

数据库oracle用户密码过期查询及解决方案

《数据库oracle用户密码过期查询及解决方案》:本文主要介绍如何处理ORACLE数据库用户密码过期和修改密码期限的问题,包括创建用户、赋予权限、修改密码、解锁用户和设置密码期限,文中通过代码介绍... 目录前言一、创建用户、赋予权限、修改密码、解锁用户和设置期限二、查询用户密码期限和过期后的修改1.查询用

Oracle数据库使用 listagg去重删除重复数据的方法汇总

《Oracle数据库使用listagg去重删除重复数据的方法汇总》文章介绍了在Oracle数据库中使用LISTAGG和XMLAGG函数进行字符串聚合并去重的方法,包括去重聚合、使用XML解析和CLO... 目录案例表第一种:使用wm_concat() + distinct去重聚合第二种:使用listagg,

Go语言使用Buffer实现高性能处理字节和字符

《Go语言使用Buffer实现高性能处理字节和字符》在Go中,bytes.Buffer是一个非常高效的类型,用于处理字节数据的读写操作,本文将详细介绍一下如何使用Buffer实现高性能处理字节和... 目录1. bytes.Buffer 的基本用法1.1. 创建和初始化 Buffer1.2. 使用 Writ

oracle中exists和not exists用法举例详解

《oracle中exists和notexists用法举例详解》:本文主要介绍oracle中exists和notexists用法的相关资料,EXISTS用于检测子查询是否返回任何行,而NOTE... 目录基本概念:举例语法pub_name总结 exists (sql 返回结果集为真)not exists (s

Oracle的to_date()函数详解

《Oracle的to_date()函数详解》Oracle的to_date()函数用于日期格式转换,需要注意Oracle中不区分大小写的MM和mm格式代码,应使用mi代替分钟,此外,Oracle还支持毫... 目录oracle的to_date()函数一.在使用Oracle的to_date函数来做日期转换二.日

oracle数据库索引失效的问题及解决

《oracle数据库索引失效的问题及解决》本文总结了在Oracle数据库中索引失效的一些常见场景,包括使用isnull、isnotnull、!=、、、函数处理、like前置%查询以及范围索引和等值索引... 目录oracle数据库索引失效问题场景环境索引失效情况及验证结论一结论二结论三结论四结论五总结ora

Oracle Expdp按条件导出指定表数据的方法实例

《OracleExpdp按条件导出指定表数据的方法实例》:本文主要介绍Oracle的expdp数据泵方式导出特定机构和时间范围的数据,并通过parfile文件进行条件限制和配置,文中通过代码介绍... 目录1.场景描述 2.方案分析3.实验验证 3.1 parfile文件3.2 expdp命令导出4.总结

Oracle数据库执行计划的查看与分析技巧

《Oracle数据库执行计划的查看与分析技巧》在Oracle数据库中,执行计划能够帮助我们深入了解SQL语句在数据库内部的执行细节,进而优化查询性能、提升系统效率,执行计划是Oracle数据库优化器为... 目录一、什么是执行计划二、查看执行计划的方法(一)使用 EXPLAIN PLAN 命令(二)通过 S

Python中的异步:async 和 await以及操作中的事件循环、回调和异常

《Python中的异步:async和await以及操作中的事件循环、回调和异常》在现代编程中,异步操作在处理I/O密集型任务时,可以显著提高程序的性能和响应速度,Python提供了asyn... 目录引言什么是异步操作?python 中的异步编程基础async 和 await 关键字asyncio 模块理论