合 ASSM引发的索引争用与 enq HW - contention 等待事件
故障概述
2017年07月24日11:58左右,客户核心数据库出现大量活动会话,导致数据库负载急剧加大,从而导致业务出现延时,DBA通过查看SESSION信息发现有大量的“enq: HW - contention”等待事件。
一直持续约有3分钟,数据库负载下降:
下面是详细的故障分析诊断过程,以及详细的解决方案描述。
故障现象
ENMODB数据库出现大量活动会话,数据库负载急剧加大,通过V$SESSION能看到大量enq:HW contention的活动会话信息,客户紧急采集了ASH信息,方便后期故障分析。
分析过程
从AWR和ASH两个维度来分析此故障,先整体后局部,首先从AWR分析入手。
1、AWR分析
首先看一下故障时间段的AWR报告:
半小时的采样时间,DB Time 215mins,其中等待时间“enq: HW - contention”占据近36%,为TOP 10 events中最主要的非空闲等待事件。
等待事件“enq: HW - contention”的解释:
The HW enqueue is used to manage the allocation of space beyond the high water mark of a segment. The high water mark of a segment is the boundary between used and unused space in that segment. If contention is occurring for "enq: HW - contention" it is possible that automatic extension is occuring to allow the extra data to be stored since the High Water Mark has been reached. Frequent allocation of extents,reclaiming chunks,and sometimes poor I/O performance may be causing contention for the LOB segments high water mark.
The HW enqueue is used to serialize the allocation of space beyond the high water mark of a segment. If lots of data is being added to an object concurrently, then multiple processes may be trying to allocate space above the high water mark at the same time, leading to contention.
简而言之,HW锁是在分配高水位线以上的空闲空间时,多个进程同时为了分配高水位线上空闲空间而修改HWM,修改HWM需要持有HW锁,该锁又属于排他锁(mode=6)。
如果大量数据被并发插入某个对象时,那多个进程可能会试图在高水位线以上同时申请可用空间,大并发的申请HW锁,从而导致HW enqueue争用。HW – contention等待事件的P1,P2,P3参数参考下表;
Event | P1 Parameter | P2 Parameter | Parameter 3 |
---|---|---|---|
enq: HW - contention | name|mode | table space | # block |
发现这个时间段确实有大量的INSERT操作,半小时采用中,该SQL执行了约近24w次。
下一步看看HW竞争是在表段还是在索引段上?