关于enq: TX - index contention 等待的探讨与测试

本文介绍了一种数据库中常见的等待事件enq:TX-indexcontention,该事件通常发生在高并发插入操作中,尤其是在频繁进行大量删除操作的表上。通过模拟并发插入的场景,展示了如何重现这一等待事件,并提出了通过定期重建表和调整索引pctfree参数来缓解此问题的方法。

最近生产库上遭遇短时间的enq: TX - index contention 等待,导致数据库hang住:
这个等待事件解释如下:
Waits for TX in mode 4 also occur when a transaction inserting a row in an index has to wait for the end of an index block split being done by another transaction. This type of TX enqueue wait corresponds to the wait event enq: TX - index contention.

可以认为一个session在向一个索引块中执行插入时产生了索引块的split,而其它的session也要往该索引块中插入数据,此时,其它session必须要等待split完成,由此引发了该等待事件。

这个等待事件可以进行模拟:

创建测试表t1,并创建索引:

create table t1(x number,y char(20),z date,q varchar2(4000)) tablespace users;

create index t1_idx1 on t1(q,z)  tablespace users;

用2个session对表t1进行并发insert:

session 1:

SQL> select sid from v$mystat where rownum=1;


----------
        50

SQL>
SQL> begin
  2    for x in 1..5000 loop
  3        insert into t1 values(1162,'1060000abcdefg', sysdate, rpad('x',2000,'x'));
  4    end loop;
  5    end;
  6    /

PL/SQL procedure successfully completed.


session 2:
SQL> select sid from v$mystat where rownum=1;

       SID
----------
        32

SQL> begin
  2    for x in 1..5000 loop
  3        insert into t1 values(1162,'1060000abcdefg', sysdate, rpad('x',2000,'x'));
  4    end loop;
  5    end;
  6    /

PL/SQL procedure successfully completed.


session 3:

插入前:

SQL> select sid,event,time_waited from v$session_event where event ='enq: TX - index contention' and sid in (50,32);

no rows selected

插入后:

SQL>  select sid,event,time_waited from v$session_event where event ='enq: TX - index contention' and sid in (50,32);

       SID EVENT                                    TIME_WAITED
---------- ---------------------------------------- -----------
        32 enq: TX - index contention                       102
        50 enq: TX - index contention                        49

从抓取的ash报告来看,产生等待的是一条insert语句,而该sql要插入数据的表是一个每天需要进行频繁delete的表,该等待事件的产生与频繁的大批量delete是具有紧密联系的。厂商最后给出的建议是定期对该表进行rebuild,并加大索引的pctfree。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10972173/viewspace-609856/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10972173/viewspace-609856/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值