Oracle local write wait 和 enq:RO - fast object reuse 等待事件 说明

 

在AWR 看到local write waits和 enq: RO - fast object reuse 的 等待事件。

 

 

 

一.Local write waits 等待说明

 

网上对local write waits 的说明:

 

Note 1

Typically DBWRhas to free up some buffers when you want to read something from the disk.During this process there are chances that you will be waiting for your localbuffer (i.e blocks dirtied/invalidated by your session) to be written to disk.During this time the waits are shown as local write waits.

 

Note 2

Basically  'localwrite' wait happens (as the name indicates) when the session is waiting for itslocal (means writes pending because of its own operation)  writeoperation. This could happen typically if the underlying disc has some seriousproblems (one of the member disk crash in RAID-05 - for example, or acontroller failure). That is why I might have said ' you never see this wait inthe normal databases!'.  You may see thisduring (rarely) Truncating a large table while most of the buffers of thattable in cache. During TRUNCATEs the session has to a local checkpoint andduring this process, the session may wait for 'local write' wait.

基本上'local write' wait 表示会话在等待自己的写操作。在磁盘发生严重问题时会发生(例如RAID 5的一个磁盘崩溃,或者磁盘控制器错误),这在正常的系统中极少发生,在TRUNCATE 一个大表而这个表在缓存中的时候,会话必需进行一个localcheckpoint,这个时候会话会等待localsession wait.

 

在MOS 的文档:

Truncates Taking Too Long... [ID 334822.1]

提到了这个等待事件。

 

Cause

Processes thatinvolve temporary tables being truncated and repopulated in multiple,concurrent batch streams may present this situation.

The underlyingproblem is we have to write the object's dirty buffers to disk prior toactually truncating or dropping the object. This ensures instancerecoverability and avoids a stuck recovery. It seems at first glance perfectlyreasonable to simply truncate a temporary table, then repopulate for anotherusage. And then to do the temporary poplulate/truncate operationsin concurrent batches to increase throughput.

 

However, inreality the concurrent truncates get bogged down as dbwr gets busy flushing thosedirty block buffers from the buffer cache. You will see huge CI enqueue waits.The multiple truncate operations in concurrent streams absolutely killthroughput.This is specially critical with large buffers.

There was also adisscussion in Bug: 4147840 (non-publish) where a peoplesoft process wascausing this behavior because of the above explanation and they seemed to fixit by changing some peoplesoft code to implement delete rather than truncate onsamll temporary tables.

 

Solution

In 9.2.0.5 andhigher, it may also help to make sure a "temp" table that isfrequently truncated have storage defined so that it occupies one extent.But this workaround is only available as long as the extent is no morethan 50% the size of the buffer cache. In non-RAC environments the tablestill has to be smaller than 50% of the buffer cache, but it allows thetable to have up to 5 extents before falling back to the old algorithm. 

 

 

二.enq: RO - fast object reuse 等待事件

 

该等待事件多与bug 相关

 

2.1 Bug 1Bug 7385253

 

Bug 7385253 - Slow Truncate / DBWR useshigh CPU / CKPT blocks on RO enqueue [ID 7385253.8]

 

Affects:

Product (Component)

Oracle Server (Rdbms)

Range of versions believed to be affected

Versions >= 10 but BELOW 11.2

Versions confirmed as being affected

Platforms affected

Generic (all / most platforms affected)

Fixed:

This issue is fixed in

 

 

该Bug的3个表现:

(1)    Hang(Involving Shared Resource)

(2)    PerformanceAffected (General)

(3)    Waits for "enq:RO - fast object reuse"

 

 

DBWR may use alot of CPU and seem to spin in or around kcbo_write_qdue to large number offree buffers on the object reuse queue or checkpoint queue.

 

In some casesthe CKPT holds the RO enqueue for very long blocking other operations  with waitevent "enq: RO - fast objectreuse".

 

Operations so farreported being affected are :

- Apply Processes in StandBy databases

- Gather stats

- Truncates

- drop/shrink/alter tablespace

 

Note: This fix was previously incorrectlylisted as not affecting 11g.

     The bug itself is present in 11g but it is unlikely to show anysignificant symptom due to other 11g changes meaning that free buffers are nolonger kept on the object queue.

 

对与该Bug 的解决方法:

setting _db_fast_obj_truncate=FALSE <--did not fix the issue
enabling asyn i/o <-- customer refused to implement to avoid corruptionsrisk
applying 7287289 <-- did not fix the issue

 

2.2 文档二

 

'enq: RO - fastobject reuse' contention when gathering schema/table statistics in parallel [ID762085.1]

 

 

Symptoms

(1)Database has been recently upgradedfrom 10.2.0.1 to 10.2.0.4.
(2)There is 'enq: RO - fastobject reuse' contention when gathering schema/table statistics in parallelusing DBMS_STATS package (with DEGREE>1).

 

其也是因为Bug 7385253导致这个问题。

 

解决方法:

1) Flushing the buffer cache.
OR
2) Setting "_db_fast_obj_truncate" =FALSE. This reverts back to the9i way of invalidating buffers in the buffer cache. 

Kindly note thatboth workarounds could have an impact on the database performance. Instead, itis recommended applying the corresponding patch.

--2种解决方法对db 性能都有很大影响,建议应用合适的patch

 

2.3 文档三

Bug8544896 - Waits for "enq: RO - fast object reuse" with high DBWR CPU[ID 8544896.8]

 

Affects:

Product (Component)

Oracle Server (Rdbms)

Range of versions believed to be affected

Versions >= 10.2.0.4 but BELOW 10.2.0.5

Versions confirmed as being affected

Platforms affected

Generic (all / most platforms affected)


 It is believed to be a regression in default behaviour thus:
   Regression introduced in 10.2.0.4

Fixed:

This issue is fixed in

 

 

This problem is introduced in 10.2.0.4.

 

Sessions can wait on "enq: RO - fastobject reuse" while DBWR consumes lots of CPU when performing truncatetype operations.

 

 

Workaround:

(1)Flush the buffer cache beforetruncating

 OR

(2) set _db_fast_obj_truncate = FALSE.

 

 

我这里出现这2个等待事件都与Truncate 操作有关。

 

 

 

 

 

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

版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!

QQ:492913789

Email:ahdba@qq.com

Blog:  http://www.cndba.cn/dave

Weibo: http://weibo.com/tianlesoftware

Twitter: http://twitter.com/tianlesoftware

Facebook: http://www.facebook.com/tianlesoftware

Linkedin: http://cn.linkedin.com/in/tianlesoftware

 

 

-------加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请----

DBA1 群:62697716(满);   DBA2 群:62697977(满)  DBA3 群:62697850(满)  

DBA 超级群:63306533(满);  DBA4 群:83829929   DBA5群: 142216823

DBA6 群:158654907    DBA7 群:172855474   DBA总群:104207940

### 原因分析 enq: TM - contention 是 Oracle 数据库中常见的等待事件之一,主要与表级锁(TM Lock)的争用有关。这种等待事件通常发生在对具有外键约束的表进行插入、更新或删除操作时,而未在外键列上建立索引的情况下[^4]。当没有合适的索引时,Oracle 会强制获取整个子表的 TM 锁,以确保数据一致性,这会导致并发操作受限并引发性能瓶颈。 此外,其他可能导致 enq: TM - contention 的情况包括显式使用 `LOCK TABLE` 命令锁定表资源,或者在高并发环境中多个会话同时尝试修改相关联的主外键表结构或数据的情况。 从 AWR 报告 ASH 报告中可以观察到该等待事件的具体发生时间受影响的对象。例如,在某一时段内,数据库出现严重的 enq: TM - contention 锁等待问题,结合 ASH 性能报告可定位到具体涉及的表(如 AA.BBIATE 表与 tran_jrnl 表),这两张表之间存在主外键关联关系[^2]。 ### 诊断方法 1. **AWR ASH 报告**:通过生成 AWR 报告来识别系统中的性能瓶颈,并利用 ASH 报告进一步细化具体的等待事件及其影响对象。检查 ASH 报告中的 EVENT 列可以帮助找到 enq: TM - contention 相关信息,并根据 BLOCKING_SESSION 定位阻塞源会话[^3]。 2. **SQL 查询分析**:运行以下 SQL 查询以查看当前正在发生的 enq: TM - contention 等待事件及相关的阻塞会话: ```sql SELECT s.sid, s.serial#, s.event, s.wait_class, s.seconds_in_wait, s.blocking_session, s.sql_id, s.prev_sql_id, s.module, s.machine FROM v$session s WHERE s.event = 'enq: TM - contention'; ``` 此查询结果将提供有关被阻塞会话的信息以及可能的阻塞会话 ID。 3. **查找缺失索引**:检查所有涉及主外键关系的表,确认外键字段是否有适当的索引。可以通过以下 SQL 查询查找缺少索引的外键: ```sql SELECT a.table_name, a.constraint_name, b.column_name FROM user_constraints a JOIN user_cons_columns b ON a.constraint_name = b.constraint_name WHERE a.constraint_type = 'R' AND NOT EXISTS ( SELECT 1 FROM user_ind_columns c WHERE c.table_name = a.table_name AND c.column_name = b.column_name ); ``` ### 解决方案 1. **为外键添加索引**:最常见的解决办法是为每个外键字段创建索引,特别是在频繁执行 DML 操作的表上。这样可以避免全表级别的 TM 锁,从而减少锁竞争。例如: ```sql CREATE INDEX idx_child_table_fk ON child_table(fk_column); ``` 2. **优化事务处理**:尽量缩短事务持续时间,确保每次事务仅包含必要的操作,降低并发冲突的可能性。 3. **调整并发控制策略**:对于某些特定场景,考虑是否需要显式地使用 `LOCK TABLE`,如果确实需要,请评估其必要性潜在的影响,并寻找替代方案。 4. **定期监控维护**:定期审查数据库性能指标,特别是关注长期存在的锁等待事件。使用自动化的监控工具帮助快速发现解决问题。 5. **深入排查阻塞源头**:一旦确定了阻塞会话,应立即调查该会话所执行的 SQL 语句,并采取相应措施(如终止不必要的长时间运行的事务)来缓解问题。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值