暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

数据库巡检系列-- 死锁成因1(ITL不足)

云趣科技 2018-07-06
347


死锁误解

时常听客户聊起死锁时,都认为死锁完全是应用的问题,是应用SQL语句获取资源的逻辑有问题才产生死锁,所以但凡看到死锁,都需要交给开发去定位业务逻辑。其实造成死锁的原因有很多,本文模拟重现的为块上ITL事务槽不足引起死锁的案例。

故障模拟

测试环境通过以下脚本,初始化表T事务槽两个,插入2000条数据装满两个块儿。四个会话插入数据不提交,占满两个事务槽,再两两插入不同块儿的数据,可重现故障。

  1. SQL> conn test/test

  2. Connected.

  3. SQL> drop table t1;


  4. Table dropped.


  5. SQL>

  6. create table t1(a Int) pctfree 0 initrans 1;


  7. insert into t1 (a)  select level from dual connect by level <= 2e3;


  8. commit;SQL>

  9. Table created.


  10. SQL> SQL>

  11. 2000 rows created.


  12. SQL> SQL>


  13. Commit complete


  14. 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;


  15.     F      B         COUNT(*)     MAX(A)   MIN(A)

  16. ---------- ---------- ---------- ---------- ----------

  17.     4    1661701        733       733       1

  18.     4    1661702        733       1466    734

  19.     4    1661703        534       2000   1467



  20. SQL> update t1 set a =100000 where a =1;

  21. update t1 set a =100000 where a =1465;

  22. 1 row updated.


  23. SQL>


  24. 1 row updated.


  25. SQL>

  26. alter system dump datafile 4 block  1632635;SQL>


  27. System altered.


  28. SQL> !



  29. Block header dump:  0x0118e97b

  30. Object id on Block? Y

  31. seg/obj: 0x2f384  csc: 0x00.41bd90f5  itc: 2  flg: E  typ: 1 - DATA

  32.     brn: 0  bdba: 0x118e978 ver: 0x01 opc: 0

  33.     inc: 0  exflg: 0


  34. Itl           Xid                  Uba         Flag  Lck        Scn/Fsc

  35. 0x01   0x000e.020.00009f2f  0x014000b6.10bd.0c  C---    0  scn 0x0000.41bd35d4

  36. 0x02   0x0013.020.0000ca73  0x014005b0.138d.0f  ----    1  fsc 0x0000.00000000

  37. bdba: 0x0118e97b

  38. data_block_dump,data header at 0x7fb5d78ce064




  39. ------session 1

  40. SQL> update t1 set a =100000 where a =1;


  41. 1 row updated.



  42. SQL> update t1 set a =100000 where a =1463;



  43. ------session 2


  44. SQL> update t1 set a =100000 where a =1465;


  45. 1 row updated.



  46. SQL> update t1 set a =100000 where a =4;


  47. ------session 3


  48. SQL> update t1  set a =100000 where a =1466;


  49. 1 row updated.


  50. SQL> update t1  set a =100000 where a =6;





  51. ------session 4



  52. SQL> update t1  set a =100000 where a =2;


  53. 1 row updated.


  54. SQL> update t1  set a =100000 where a =1466;

  55. update t1  set a =100000 where a =1466

  56.       *

  57. ERROR at line 1:

  58. ORA-00060: deadlock detected while waiting for resource

故障分析

如上操作中会话一,会话二,会话三,会话四 在第一次插入的时候,会占满两个块共四个事务槽,dump 了一个块确认下。两个事务槽均被占用,第二次插入时,数据上均无冲突,但事务槽会有争用,进而引起死锁。SQL语句等待事件 TX-allocate ITL entry

处理思路

参考文档 1472175.1
 如有索引也需要调整。

  1. SQL> alter table t1 pctfree 10 initrans 20;

  2. alter table t1 move ;


  3. Table altered.


  4. SQL>

  5. Table altered.

巡检思路

巡检日志告警 以及 TX-allocate ITL entry
 等待事件。


文章转载自云趣科技,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论