Chinaunix首页 | 论坛 | 博客
  • 博客访问: 279506
  • 博文数量: 48
  • 博客积分: 1255
  • 博客等级: 中尉
  • 技术积分: 486
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-01 18:28
文章分类

全部博文(48)

文章存档

2014年(10)

2012年(9)

2011年(17)

2010年(9)

2009年(3)

我的朋友

分类: LINUX

2012-01-11 15:48:37

 
关于enq: TX - index contention 等待的探讨与测试
2010-05-08 14:05
最近生产库上遭遇短时间的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。
阅读(2027) | 评论(0) | 转发(0) |
0

上一篇:V$session 表的妙用

下一篇:linux中mount cdrom

给主人留下些什么吧!~~