一、今天在查看awr报告中,发现Top 5 Timed Foreground Events发现enq: HW - contention的等待事件;
二、enq: HW - contention的官方说明:
The HW enqueue is used to serialize the allocation of space beyond the high water mark of a segment.
?V$SESSION_WAIT.P2 / V$LOCK.ID1 is the tablespace number.
?V$SESSION_WAIT.P3 / V$LOCK.ID2 is the relative data block address (dba) of segment header of the object for which space is being allocated.
If this is a point of contention for an object, then manual allocation of extents solves the problem.
三、等待事件解释
为防止多个进程同时修改HWM而提供的锁称为HW锁。想要移动HWM的进程必须获得HW锁。若在获取HW锁过程中发生争用,则等待enq: HW - contention事件。HW锁争用大部分是因大量执行insert所引发的,偶尔也会因大量执行update在回滚段中发生HW锁争用现象。若是update,表中段的扩展的大小虽然不多,但在创建回滚数据的过程中,需要回滚段的急速扩张。HW锁争用是在急速空间扩张时普遍出现的等待现象,有时也会引发严重的性能下降。
SQL> select event#,name,parameter1,parameter2,parameter3 from v$event_name where name = 'enq: HW - contention';
EVENT# NAME PARAMETER1 PARAMETER2 PARAMETER3
---------- ---------------------------------------- -------------------- -------------------- --------------------
250 enq: HW - contention name|mode table space # block
众所周知,Oracle高水位线标志着该线以下的block均被Oracle格式过,通俗一点讲就是该高水位线以下的block都被Oracle使用过。 通常在执行insert操作时,当高水位线以下block不够用时,Oracle将会推进高水位线。更进一步讲,当有多个进程在同时进行insert操作时,比较容易引起高水位线争用,主要表现为enq: HW - contention。
四、如何找到事件:'enq: HW - contention' 热点对象:
1、查看v$session_wait,应该会有如下等待事件:
SQL> select p1, p2, p3 from v$session_wait where event = 'enq: HW - contention';
P1 P2 P3
---------- ---------- ----------
1213661190 7 140003563
1213661190 7 140003563
1213661190 7 140003563
1213661190 7 140003563
1213661190 7 140003563
1213661190 7 140003563
1213661190 7 140003563
2、通过P3进行DBMS_UTILITY转换可以获知发生争用的文件和block:
SQL> select dbms_utility.data_block_address_block(140003563),dbms_utility.data_block_address_file(140003563) from dual;
DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK(140003563) DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE(140003563)
------------------------------------------------ -----------------------------------------------
1591531 33
3、进而通过file#和block#定位对象:
SQL> select owner, segment_type, segment_name
from dba_extents
where file_id = 33 and 1591531 between block_id and block_id + blocks - 1;
五、减少HW锁争用的方法如下:
If this is a point of contention for an object, then manual allocation of extents solves the problem.
脚本:alter table <TABNAME> allocate extent,提前分配空间;
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
本文作者:JOHN
ORACLE技术博客:ORACLE 猎人笔记 数据库技术群:367875324 (请备注ORACLE管理 )
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++