死锁误解
时常听客户聊起死锁时,都认为死锁完全是应用的问题,是应用SQL语句获取资源的逻辑有问题才产生死锁,所以但凡看到死锁,都需要交给开发去定位业务逻辑。其实造成死锁的原因有很多,本文模拟重现的为块上ITL事务槽不足引起死锁的案例。
故障模拟
测试环境通过以下脚本,初始化表T事务槽两个,插入2000条数据装满两个块儿。四个会话插入数据不提交,占满两个事务槽,再两两插入不同块儿的数据,可重现故障。
SQL> conn test/test
Connected.
SQL> drop table t1;
Table dropped.
SQL>
create table t1(a Int) pctfree 0 initrans 1;
insert into t1 (a) select level from dual connect by level <= 2e3;
commit;SQL>
Table created.
SQL> SQL>
2000 rows created.
SQL> SQL>
Commit complete
SQL> SELECT f, b,count(*),max(a),min(a) FROM (SELECT DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) f,DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) b, a FROM t1 )group by f,b order by 5;
F B COUNT(*) MAX(A) MIN(A)
---------- ---------- ---------- ---------- ----------
4 1661701 733 733 1
4 1661702 733 1466 734
4 1661703 534 2000 1467
SQL> update t1 set a =100000 where a =1;
update t1 set a =100000 where a =1465;
1 row updated.
SQL>
1 row updated.
SQL>
alter system dump datafile 4 block 1632635;SQL>
System altered.
SQL> !
Block header dump: 0x0118e97b
Object id on Block? Y
seg/obj: 0x2f384 csc: 0x00.41bd90f5 itc: 2 flg: E typ: 1 - DATA
brn: 0 bdba: 0x118e978 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x000e.020.00009f2f 0x014000b6.10bd.0c C--- 0 scn 0x0000.41bd35d4
0x02 0x0013.020.0000ca73 0x014005b0.138d.0f ---- 1 fsc 0x0000.00000000
bdba: 0x0118e97b
data_block_dump,data header at 0x7fb5d78ce064
------session 1
SQL> update t1 set a =100000 where a =1;
1 row updated.
SQL> update t1 set a =100000 where a =1463;
------session 2
SQL> update t1 set a =100000 where a =1465;
1 row updated.
SQL> update t1 set a =100000 where a =4;
------session 3
SQL> update t1 set a =100000 where a =1466;
1 row updated.
SQL> update t1 set a =100000 where a =6;
------session 4
SQL> update t1 set a =100000 where a =2;
1 row updated.
SQL> update t1 set a =100000 where a =1466;
update t1 set a =100000 where a =1466
*
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
故障分析
如上操作中会话一,会话二,会话三,会话四 在第一次插入的时候,会占满两个块共四个事务槽,dump 了一个块确认下。两个事务槽均被占用,第二次插入时,数据上均无冲突,但事务槽会有争用,进而引起死锁。SQL语句等待事件 TX-allocate ITL entry
处理思路
参考文档 1472175.1
如有索引也需要调整。
SQL> alter table t1 pctfree 10 initrans 20;
alter table t1 move ;
Table altered.
SQL>
Table altered.
巡检思路
巡检日志告警 以及 TX-allocate ITL entry
等待事件。




