zoukankan      html  css  js  c++  java
  • oracle的TX lock信息在哪里?

    我们都知道ORACLE不会发生锁升级,锁对于ORACLE来说并不是稀缺资源,为什么DML lock对于ORACLE来说不是稀缺资源,下面来寻找答案。

    SQL> select * from emp where sal>2999;

    EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
    ----- ---------- --------- ----- ----------- --------- --------- ------
     7788 SCOTT      ANALYST    7566 4/19/1987     3000.00               20
     7839 KING       PRESIDENT       11/17/1981    5000.00               10
     7902 FORD       ANALYST    7566 12/3/1981     3000.00               20

    SQL> select dbms_rowid.rowid_relative_fno(rowid)file_id,dbms_rowid.rowid_block_number(rowid)block_id from emp  where sal>2999;

       FILE_ID   BLOCK_ID
    ---------- ----------
             5        204
             5        204
             5        204

    SQL> update emp set job='ANALYST' where sal>2999;-----此处更新3行,那三行就会被lock

    3 rows updated

    SQL> select dump(job,'16') from emp where sal>2999;

    DUMP(JOB,'16')
    --------------------------------------------------------------------------------
    Typ=1 Len=7: 41,4e,41,4c,59,53,54
    Typ=1 Len=7: 41,4e,41,4c,59,53,54
    Typ=1 Len=7: 41,4e,41,4c,59,53,54

    SQL> alter system dump datafile 5 block 204;

    系统已更改。

    我现在省略一些无关信息,贴出主要的DUMP信息

     Object id on Block? Y
     seg/obj: 0xcd4c  csc: 0x00.1a6167  itc: 3  flg: E  typ: 1 - DATA
         brn: 0  bdba: 0x14000c9 ver: 0x01 opc: 0
         inc: 0  exflg: 0
     
     Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
    0x01   0x0004.001.00000348  0x0080003e.027c.08  ----    3  fsc 0x0002.00000000

    -----此处loc为3说明刚才发生的update就是由这条ITL记录的,loc表示这个事物影响了多少行。
    0x02   0x0003.021.000003e9  0x008002f5.021f.16  C---    0  scn 0x0000.001a41a8

    -----此处的flag 为C--- 表示事物已经提交,而且清除了行锁定
    0x03   0x0005.016.000003f9  0x008006de.0190.12  --U-    1  fsc 0x0000.001a81eb
    ---- 此处的 flag 为  --U- 表示这个事物已经提交,但是没有发生块清除,关于块清除这里暂不讨论。
    data_block_dump,data header at 0x988787c
    ===============
    tsiz: 0x1f80
    hsiz: 0x2e
    pbl: 0x0988787c
    bdba: 0x014000cc
         76543210
    flag=--------
    ntab=1
    nrow=14
    frre=-1
    fsbo=0x2e
    fseo=0x1d25
    avsp=0x1d1b
    tosp=0x1d1d
    0xe:pti[0] nrow=14 offs=0
    0x12:pri[0] offs=0x1f5a
    0x14:pri[1] offs=0x1f2f
    0x16:pri[2] offs=0x1f04
    0x18:pri[3] offs=0x1edb
    0x1a:pri[4] offs=0x1eae
    0x1c:pri[5] offs=0x1e85
    0x1e:pri[6] offs=0x1e5c
    0x20:pri[7] offs=0x1e34
    0x22:pri[8] offs=0x1d25
    0x24:pri[9] offs=0x1de3
    0x26:pri[10] offs=0x1dbd
    0x28:pri[11] offs=0x1d97
    0x2a:pri[12] offs=0x1d70
    0x2c:pri[13] offs=0x1d49
    block_row_dump:
    tab 0, row 0, @0x1f5a
    tl: 38 fb: --H-FL-- lb: 0x3  cc: 8
    col  0: [ 3]  c2 4a 46
    col  1: [ 5]  53 4d 49 54 48
    col  2: [ 5]  43 4c 45 52 4b
    col  3: [ 3]  c2 50 03
    col  4: [ 7]  77 b4 0c 11 01 01 01
    col  5: [ 2]  c2 0b
    col  6: *NULL*
    col  7: [ 2]  c1 15
    tab 0, row 1, @0x1f2f
    tl: 43 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4b 64
    col  1: [ 5]  41 4c 4c 45 4e
    col  2: [ 8]  53 41 4c 45 53 4d 41 4e
    col  3: [ 3]  c2 4d 63
    col  4: [ 7]  77 b5 02 14 01 01 01
    col  5: [ 2]  c2 11
    col  6: [ 2]  c2 04
    col  7: [ 2]  c1 1f
    tab 0, row 2, @0x1f04
    tl: 43 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4c 16
    col  1: [ 4]  57 41 52 44
    col  2: [ 8]  53 41 4c 45 53 4d 41 4e
    col  3: [ 3]  c2 4d 63
    col  4: [ 7]  77 b5 02 16 01 01 01
    col  5: [ 3]  c2 0d 33
    col  6: [ 2]  c2 06
    col  7: [ 2]  c1 1f
    tab 0, row 3, @0x1edb
    tl: 41 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4c 43
    col  1: [ 5]  4a 4f 4e 45 53
    col  2: [ 7]  4d 41 4e 41 47 45 52
    col  3: [ 3]  c2 4f 28
    col  4: [ 7]  77 b5 04 02 01 01 01
    col  5: [ 3]  c2 1e 4c
    col  6: *NULL*
    col  7: [ 2]  c1 15
    tab 0, row 4, @0x1eae
    tl: 45 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4d 37
    col  1: [ 6]  4d 41 52 54 49 4e
    col  2: [ 8]  53 41 4c 45 53 4d 41 4e
    col  3: [ 3]  c2 4d 63
    col  4: [ 7]  77 b5 09 1c 01 01 01
    col  5: [ 3]  c2 0d 33
    col  6: [ 2]  c2 0f
    col  7: [ 2]  c1 1f
    tab 0, row 5, @0x1e85
    tl: 41 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4d 63
    col  1: [ 5]  42 4c 41 4b 45
    col  2: [ 7]  4d 41 4e 41 47 45 52
    col  3: [ 3]  c2 4f 28
    col  4: [ 7]  77 b5 05 01 01 01 01
    col  5: [ 3]  c2 1d 33
    col  6: *NULL*
    col  7: [ 2]  c1 1f
    tab 0, row 6, @0x1e5c
    tl: 41 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4e 53
    col  1: [ 5]  43 4c 41 52 4b
    col  2: [ 7]  4d 41 4e 41 47 45 52
    col  3: [ 3]  c2 4f 28
    col  4: [ 7]  77 b5 06 09 01 01 01
    col  5: [ 3]  c2 19 33
    col  6: *NULL*
    col  7: [ 2]  c1 0b
    tab 0, row 7, @0x1e34
    tl: 40 fb: --H-FL-- lb: 0x1  cc: 8       ----此处lb表示这一行被lock了,lock这行的事物是 0x1,也就是刚才看见的ITL 0x1,cc表示有8列
    col  0: [ 3]  c2 4e 59
    col  1: [ 5]  53 43 4f 54 54
    col  2: [ 7]  41 4e 41 4c 59 53 54
    col  3: [ 3]  c2 4c 43
    col  4: [ 7]  77 bb 04 13 01 01 01  ----此处[7]表示len=7 与select dump(job,'16') from emp where sal>2999;信息一致
    col  5: [ 2]  c2 1f
    col  6: *NULL*
    col  7: [ 2]  c1 15
    tab 0, row 8, @0x1d25
    tl: 36 fb: --H-FL-- lb: 0x1  cc: 8       ---此行被事物0x1  lock

    col  0: [ 3]  c2 4f 28
    col  1: [ 4]  4b 49 4e 47
    col  2: [ 7]  41 4e 41 4c 59 53 54
    col  3: *NULL*
    col  4: [ 7]  77 b5 0b 11 01 01 01  ----此处[7]表示len=7 byte 与select dump(job,'16') from emp where sal>2999;信息一致
    col  5: [ 2]  c2 33
    col  6: *NULL*
    col  7: [ 2]  c1 0b
    tab 0, row 9, @0x1de3
    tl: 43 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4f 2d
    col  1: [ 6]  54 55 52 4e 45 52
    col  2: [ 8]  53 41 4c 45 53 4d 41 4e
    col  3: [ 3]  c2 4d 63
    col  4: [ 7]  77 b5 09 08 01 01 01
    col  5: [ 2]  c2 10
    col  6: [ 1]  80
    col  7: [ 2]  c1 1f
    tab 0, row 10, @0x1dbd
    tl: 38 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 4f 4d
    col  1: [ 5]  41 44 41 4d 53
    col  2: [ 5]  43 4c 45 52 4b
    col  3: [ 3]  c2 4e 59
    col  4: [ 7]  77 bb 05 17 01 01 01
    col  5: [ 2]  c2 0c
    col  6: *NULL*
    col  7: [ 2]  c1 15
    tab 0, row 11, @0x1d97
    tl: 38 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 2]  c2 50
    col  1: [ 5]  4a 41 4d 45 53
    col  2: [ 5]  43 4c 45 52 4b
    col  3: [ 3]  c2 4d 63
    col  4: [ 7]  77 b5 0c 03 01 01 01
    col  5: [ 3]  c2 0a 33
    col  6: *NULL*
    col  7: [ 2]  c1 1f
    tab 0, row 12, @0x1d70
    tl: 39 fb: --H-FL-- lb: 0x1  cc: 8                ----- 这行被事物0x1  lock

    col  0: [ 3]  c2 50 03
    col  1: [ 4]  46 4f 52 44
    col  2: [ 7]  41 4e 41 4c 59 53 54
    col  3: [ 3]  c2 4c 43
    col  4: [ 7]  77 b5 0c 03 01 01 01   ----此处[7]表示len=7byte 与select dump(job,'16') from emp where sal>2999;信息一致
    col  5: [ 2]  c2 1f
    col  6: *NULL*
    col  7: [ 2]  c1 15
    tab 0, row 13, @0x1d49
    tl: 39 fb: --H-FL-- lb: 0x0  cc: 8
    col  0: [ 3]  c2 50 23
    col  1: [ 6]  4d 49 4c 4c 45 52
    col  2: [ 5]  43 4c 45 52 4b
    col  3: [ 3]  c2 4e 53
    col  4: [ 7]  77 b6 01 17 01 01 01
    col  5: [ 2]  c2 0e
    col  6: *NULL*
    col  7: [ 2]  c1 0b
    end_of_block_dump
    End dump data blocks tsn: 6 file#: 5 minblk 204 maxblk 204
    由此,我们知道ORACLE中的TX -row lock是记录在 block中的,它不像其他数据库那样将lock记录在内存中,避免因为内存资源不足发生锁升级,在ORACLE中,锁开销是很小很小的。

  • 相关阅读:
    【leetcode】1295. Find Numbers with Even Number of Digits
    【leetcode】427. Construct Quad Tree
    【leetcode】1240. Tiling a Rectangle with the Fewest Squares
    【leetcode】1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold
    【leetcode】1291. Sequential Digits
    【leetcode】1290. Convert Binary Number in a Linked List to Integer
    【leetcode】1269. Number of Ways to Stay in the Same Place After Some Steps
    【leetcode】1289. Minimum Falling Path Sum II
    【leetcode】1288. Remove Covered Intervals
    【leetcode】1287. Element Appearing More Than 25% In Sorted Array
  • 原文地址:https://www.cnblogs.com/hehe520/p/6330637.html
Copyright © 2011-2022 走看看