事務槽小記

oracle在對錶進行多事務插入時,採用的是分佈式多數據塊插入,oracle表初始事務槽數量是ini_trans爲2,最多兩個事務對同一個數據塊進行插入,而其餘的事務則插入到新塊中,這樣就不會產生事務槽的爭用。

  1. 會話一 
  2.  
  3. SQL> insert into scott.t1 values (1); 
  4. insert into scott.t1 values (2); 
  5. insert into scott.t1 values (3); 
  6. insert into scott.t1 values (4); 
  7. insert into scott.t1 values (5); 
  8.  
  9. SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1; 
  10.  
  11.     ID      DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) 
  12. ----------  ------------------------------------ ------------------------------------ 
  13.          1                                    4                                                              171 
  14.          2                                    4                                                              171 
  15.          3                                    4                                                              171 
  16.          4                                    4                                                          171 
  17.          5                                    4                                                          171 
  18.  
  19.  
  20. 會話2 
  21.  
  22. SQL> insert into scott.t1 values (5); 
  23. insert into scott.t1 values (6); 
  24. insert into scott.t1 values (7); 
  25.  
  26. SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1; 
  27.  
  28.    ID       DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) 
  29. ---------- ------------------------------------ ------------------------------------ 
  30.          5                                    4                                                             173 
  31.          6                                    4                                                             173 
  32.          7                                    4                                                             173 
  33.  
  34.  
  35. 會話3 
  36.  
  37. SQL> insert into scott.t1 values (8); 
  38. SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1; 
  39.  
  40.         ID DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) 
  41. ---------- ------------------------------------ ------------------------------------ 
  42.          8                                    4                                                             172 
  43.  
  44. SQL> alter system dump datafile 4 block min 171 block max 173; 
  45. SQL> ho vim /opt/app/oracle/diag/rdbms/db2/db2/trace/db2_ora_18916.trc 
  46. buffer tsn: 4 rdba: 0x010000ab (4/171) 
  47.  seg/obj: 0x12160  csc: 0x00.5a3ec5  itc: 2  flg: E  typ: 1 - DATA 
  48.      brn: 0  bdba: 0x10000a8 ver: 0x01 opc: 0 
  49.      inc: 0  exflg: 0 
  50.  Itl           Xid                  Uba         Flag  Lck        Scn/Fsc 
  51. 0x01   0x0009.01c.0000031c  0x00c0024c.00d0.10  ----    5  fsc 0x0000.00000000 
  52. 0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000 
  53. block_row_dump: 
  54. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  55. col  0: [ 2]  c1 02 
  56. tab 0, row 1, @0x1f8c 
  57. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  58. col  0: [ 2]  c1 03 
  59. tab 0, row 2, @0x1f86 
  60. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  61. col  0: [ 2]  c1 04 
  62. tab 0, row 3, @0x1f80 
  63. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  64. col  0: [ 2]  c1 05 
  65. tab 0, row 4, @0x1f7a 
  66. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  67. col  0: [ 2]  c1 06 
  68.  
  69.  
  70. buffer tsn: 4 rdba: 0x010000ac (4/172) 
  71.  seg/obj: 0x12160  csc: 0x00.5a3e7e  itc: 2  flg: E  typ: 1 - DATA 
  72.      brn: 0  bdba: 0x10000a8 ver: 0x01 opc: 0 
  73.      inc: 0  exflg: 0 
  74.  
  75.  Itl           Xid                  Uba         Flag  Lck        Scn/Fsc 
  76. 0x01   0x0005.021.00000362  0x00c002e4.010b.01  ----    1  fsc 0x0000.00000000 
  77. 0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000 
  78.  
  79. block_row_dump: 
  80. tab 0, row 0, @0x1f92 
  81. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  82. col  0: [ 2]  c1 09 
  83.  
  84. buffer tsn: 4 rdba: 0x010000ad (4/173) 
  85.  seg/obj: 0x12160  csc: 0x00.5a3e7e  itc: 2  flg: E  typ: 1 - DATA 
  86.      brn: 0  bdba: 0x10000a8 ver: 0x01 opc: 0 
  87.      inc: 0  exflg: 0 
  88.  
  89.  Itl           Xid                  Uba         Flag  Lck        Scn/Fsc 
  90. 0x01   0x000c.016.00000017  0x00c007e6.001f.05  ----    3  fsc 0x0000.00000000 
  91. 0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000 
  92. block_row_dump: 
  93. tab 0, row 0, @0x1f92 
  94. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  95. col  0: [ 2]  c1 06 
  96. tab 0, row 1, @0x1f8c 
  97. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  98. col  0: [ 2]  c1 07 
  99. tab 0, row 2, @0x1f86 
  100. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  101. col  0: [ 2]  c1 08 
  102. 可以看出多事務插入時,採用了多個塊插入,每個數據塊都產生了兩個事務槽,使用了其中一個,每個事務槽的修改對應了所修改的行。 

update時當同時修改一個數據塊中的行時,每個回話都會在塊中有一個對應的事務槽,max_trans默認是255,發生ITL的爭用比較少;

  1. SQL> declare 
  2.   2  begin 
  3.   3  for i in 1..10 loop 
  4.   4  insert into scott.t1 values (i); 
  5.   5  end loop; 
  6.   6  commit; 
  7.   7  end; 
  8.   8  / 
  9.  
  10. SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1; 
  11.  
  12.         ID DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) 
  13. ---------- ------------------------------------ ------------------------------------ 
  14.          1                                    4                                  171 
  15.          2                                    4                                  171 
  16.          3                                    4                                  171 
  17.          4                                    4                                  171 
  18.          5                                    4                                  171 
  19.          6                                    4                                  171 
  20.          7                                    4                                  171 
  21.          8                                    4                                  171 
  22.          9                                    4                                  171 
  23.         10                                    4                                  171 
  24.  
  25. 會話1 
  26. SQL> update scott.t1 set idid =id where id in (1,2,3,4); 
  27.  
  28. 4 rows updated. 
  29.  
  30. 會話2 
  31. SQL> update scott.t1 set idid =id where id in (5,6,7,8); 
  32.  
  33. 4 rows updated. 
  34.  
  35. 會話3 
  36. SQL> update scott.t1 set idid =id where id in (9,10); 
  37.  
  38. 2 rows updated. 
  39.  
  40. SQL> alter system dump datafile 4 block 171; 
  41.  
  42. SQL> ho vim /opt/app/oracle/diag/rdbms/db2/db2/trace/db2_ora_18916.trc 
  43. Start dump data blocks tsn: 4 file#:4 minblk 171 maxblk 171 
  44.  
  45.  Object id on Block? Y 
  46.  seg/obj: 0x12162  csc: 0x00.5a44d4  itc: 3  flg: E  typ: 1 - DATA 
  47.      brn: 0  bdba: 0x10000a8 ver: 0x01 opc: 0 
  48.      inc: 0  exflg: 0 
  49.   
  50.  Itl           Xid                  Uba         Flag  Lck        Scn/Fsc 
  51. 0x01   0x000a.00c.0000028d  0x00c000bd.00dd.07  ----    4  fsc 0x0000.00000000 
  52. 0x02   0x0008.007.000003f8  0x00c0037a.00c5.06  ----    4  fsc 0x0000.00000000 
  53. 0x03   0x0003.006.0000033c  0x00c00c9b.0175.01  ----    2  fsc 0x0000.00000000 
  54.  
  55. block_row_dump: 
  56. tab 0, row 0, @0x1f7a 
  57. tl: 6 fb: --H-FL-- lb: 0x2  cc: 1 
  58. col  0: [ 2]  c1 02 
  59. tab 0, row 1, @0x1f74 
  60. tl: 6 fb: --H-FL-- lb: 0x2  cc: 1 
  61. col  0: [ 2]  c1 03 
  62. tab 0, row 2, @0x1f6e 
  63. tl: 6 fb: --H-FL-- lb: 0x2  cc: 1 
  64. col  0: [ 2]  c1 04 
  65. tab 0, row 3, @0x1f68 
  66. tl: 6 fb: --H-FL-- lb: 0x2  cc: 1 
  67. col  0: [ 2]  c1 05 
  68. tab 0, row 4, @0x1f62 
  69. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  70. col  0: [ 2]  c1 06 
  71. tab 0, row 5, @0x1f5c 
  72. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  73. col  0: [ 2]  c1 07 
  74. tab 0, row 6, @0x1f56 
  75. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  76. col  0: [ 2]  c1 08 
  77. tab 0, row 7, @0x1f50 
  78. tl: 6 fb: --H-FL-- lb: 0x1  cc: 1 
  79. col  0: [ 2]  c1 09 
  80. tab 0, row 8, @0x1f4a 
  81. tl: 6 fb: --H-FL-- lb: 0x3  cc: 1 
  82. col  0: [ 2]  c1 0a 
  83. tab 0, row 9, @0x1f44 
  84. tl: 6 fb: --H-FL-- lb: 0x3  cc: 1 
  85. col  0: [ 2]  c1 0b 
  86. 可以看到,每個UPDATE的會話都有一個事務槽對應,前兩個會話的事務槽每個對應4行,第三個對應2行 

事務槽(事務,是否提交,鎖定)

事務正在使用的回滾段,轉向 http://rilee.blog.51cto.com/467020/772463

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章