ExaGridDba

Demonstrate Jonathan Lewis's RI lock

May 10th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. Demonstrate Jonathan Lewis's RI lock.
  2.  
  3. https://jonathanlewis.wordpress.com/2016/05/09/ri-locks/
  4.  
  5. ----- Session 1 -----
  6.  
  7. [oracle@stormking cdb12102 deadlock]$ sqlplus /nolog
  8.  
  9. SQL*Plus: Release 12.1.0.2.0 Production on Tue May 10 23:01:11 2016
  10.  
  11. Copyright (c) 1982, 2014, Oracle. All rights reserved.
  12.  
  13. SQL> @ conn.u.sql
  14. Connected.
  15. SQL> set echo on
  16. SQL> @ sidprompt.sql
  17. SQL> column sid_ new_value sid_ format a5
  18. SQL> select sys_context('userenv','sid' ) sid_ from dual;
  19.  
  20. SID_
  21. -----
  22. 64
  23.  
  24. SQL> set sqlprompt '&&sid_> '
  25. 64>
  26. 64> @ create.tables.sql
  27. 64>
  28. 64> create table parent (
  29. 2 id number(8,0),
  30. 3 constraint par_pk primary key(id)
  31. 4 );
  32.  
  33. Table created.
  34.  
  35. 64>
  36. 64> create table child (
  37. 2 id_p number(8,0) not null references parent,
  38. 3 id_c number(8,0) not null,
  39. 4 constraint child_pk primary key(id_p, id_c)
  40. 5 )
  41. 6 ;
  42.  
  43. Table created.
  44.  
  45. 64>
  46. 64> @ insert.parent.sql
  47. 64> -- session 1
  48. 64> insert into parent values(1);
  49.  
  50. 1 row created.
  51.  
  52. ----- Session 2 -----
  53.  
  54. [oracle@stormking cdb12102 deadlock]$ sqlplus /nolog
  55.  
  56. SQL*Plus: Release 12.1.0.2.0 Production on Tue May 10 23:02:10 2016
  57.  
  58. Copyright (c) 1982, 2014, Oracle. All rights reserved.
  59.  
  60. SQL> @ conn.u.sql
  61. Connected.
  62. SQL> set echo on
  63. SQL> @ sidprompt.sql
  64. SQL> column sid_ new_value sid_ format a5
  65. SQL> select sys_context('userenv','sid' ) sid_ from dual;
  66.  
  67. SID_
  68. -----
  69. 34
  70.  
  71. SQL> set sqlprompt '&&sid_> '
  72. 34>
  73. 34> @ insert.child.sql
  74. 34> -- session 2
  75. 34> insert into child values(1,1);
  76.  
  77. ----- Session 1 -----
  78.  
  79. 64> @ vlock.sql
  80. 64> select sid, type, id1, id2, lmode, request, ctime, block
  81. 2 from V$lock
  82. 3 where sid in (select sid from V$session where username = 'U')
  83. 4 and type != 'AE'
  84. 5 order by
  85. 6 sid, type desc
  86. 7 /
  87.  
  88. SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK
  89. ---------- -- ---------- ---------- ---------- ---------- ---------- ----------
  90. 34 TX 262156 21994 0 4 25 0
  91. 34 TX 196630 23351 6 0 25 0
  92. 34 TM 96098 0 3 0 25 0
  93. 34 TM 96096 0 3 0 25 0
  94. 64 TX 262156 21994 6 0 75 1
  95. 64 TM 96096 0 3 0 75 0
  96. 64 TM 96098 0 2 0 75 0
  97.  
  98. 7 rows selected.
  99.  
  100. 64> rollback;
  101.  
  102. Rollback complete.
  103.  
  104. ----- Session 2 -----
  105.  
  106. insert into child values(1,1)
  107. *
  108. ERROR at line 1:
  109. ORA-02291: integrity constraint (U.SYS_C0011029) violated - parent key not
  110. found
Add Comment
Please, Sign In to add comment