您的位置:首页 > 数据库 > Oracle

【ORACLE】事务与一致性:TRN TBL 和ITL基础

2015-01-30 14:07 399 查看


************************************************************************
****原文:blog.csdn.net/clark_xu  徐长亮的专栏
************************************************************************
4 事务与一致性

4.1 undo segment header 事务表及事务控制表(TRN TBL and TRN ctl)

--undo header 包含事务表TRN TBL用于标示最近事务的简单列表,

 TRN TBL::
  index  state cflags  wrap#    uel         scn            dba            parent-xid    nub     stmt_num    cmt
  ------------------------------------------------------------------------------------------------
   0x00    9    0x00  0x0146  0x002e  0x0000.000c4261  0x008000e8  0x0000.000.00000000  0x00000001   0x00000000  1422514868
   0x01    9    0x00  0x0146  0x0007  0x0000.000c43f4  0x008000e8  0x0000.000.00000000  0x00000001   0x00000000  1422515883
   0x02    9    0x00  0x0146  0x002c  0x0000.000c43d3  0x008000e8  0x0000.000.00000000  0x00000001   0x00000000  1422515883
   0x03    9    0x00  0x0146  0x0008  0x0000.000c440a  0x008000e8  0x0000.000.00000000  0x00000001   0x00000000  1422515883
 
 
--undo header包含事务控制区TRN CTL详细描述事务表的状态
TRN CTL:: seq: 0x00cc chd: 0x0009 ctl: 0x002f inc: 0x00000000 nfb: 0x0002
            mgc: 0x8201 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
            uba: 0x008000b9.00cc.06 scn: 0x0000.000c3c00
Version: 0x01
  FREE BLOCK POOL::
    uba: 0x008000b9.00cc.08 ext: 0x7  spc: 0x1c7e 
    uba: 0x008000e6.00cb.13 ext: 0x6  spc: 0x1024 
    uba: 0x00000000.00c9.2f ext: 0x4  spc: 0xc7c  
    uba: 0x00000000.0000.00 ext: 0x0  spc: 0x0    
uba: 0x00000000.0000.00 ext: 0x0  spc: 0x0    
 
--commit指令
Commit指令也会生产一个改变向量,因为修改undo的事务表的两个字段state,scn;
 
--事务ID:xid
事务ID有undo段编号(1,10),事务表的index值(ox00开始)加warp#构成了事务ID。

4.2 查看事务xid

--查看xid事务号
SQL> update scott.stu set stu_id=4 where stu_id=5;
 
已更新 1 行
SQL> select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec from v$transaction;
    XIDUSN    XIDSLOT     XIDSQN     UBABLK     UBAFIL     UBAREC
---------- ---------- ---------- ---------- ---------- ----------
         2         43        313         31          2         52
--xidusn:undo segment number
--xidslot:slot number
--xidsqn:sequence number(wrap#)
--ubablk:undo记录所在对的undo文件的block号。uba block number
--UBAFILE: undo记录所在的undo文件号。
//数据文件2,block 31
 
SQL> select trunc(id1/65536) usn,mod(id1,65536) slot,id2 wrap,lmode  from v$lock where type='TX';
 
       USN       SLOT       WRAP      LMODE
---------- ---------- ---------- ----------
         2         43        313          6
//lmod 为6 独占模式。Slot 43转换为16进制,0x2b:
 
--获取undo字段2 header中事务表 的slot ox2b信息。
index  state cflags  wrap#    uel         scn            dba            parent-xid    nub        stmt_num    cmt
0x2b   10    0x80  0x0139  0x0000  0x0000.000c44bc  0x0080001f  0x0000.000.00000000  0x00000001   0x00000000  0
//state为10,活动状态
//cflags为0x80表示活动事务,ox00表示无事务,0x10表示死事务。
//uel为ox0000 记录下一个可用的事务槽为信息
//dba,事务写undo时候,最后一个undo块数
    //nub为1,当前事务使用一个undo数据块。
//block 31

4.3 通过事务号XID事务的undo记录

--dump事务对应的undo记录的信息。
ALTER SYSTEM DUMP UNDO BLOCK '_SYSSMU2$' XID 2 43 313
--查看undo记录dump信息
Undo Segment:  _SYSSMU2$ (2)
xid: 0x0002.02b.00000139
UNDO BLK:  Extent: 0   Block: 5   dba (file#, block#): 2,0x0000001f(10进制31)
KDO undo record:
KTB Redo
op: 0x03  ver: 0x01 
op: Z
KDO Op code: URP row dependencies Disabled
  xtype: XAxtype KDO_KDOM2 flags: 0x00000080  bdba: 0x010000cc  hdba: 0x010000cb
itli: 2  ispac: 0  maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 161
ncol: 4 nnew: 1 size: 0
Vector content:
col  0: [ 2]  c1 06

4.4 通过x$ktuxe表可以同时获取事务xid信息(段号,slot号)及事务所在地址(数据文件号,及block号)

--x$ktuxe的使用
SQL> select indx,ktuxesqn wrap#,ktuxerdbf dba_file,ktuxerdbb dba_block from x$ktuxe
  2  where ktuxesta='ACTIVE';
 
      INDX      WRAP#   DBA_FILE  DBA_BLOCK
---------- ---------- ---------- ----------
       189        313          2         31
 

4.5 并发动作的测试

1. 查看测试table head所在地址。

 (1)Create table t1 (id number, n1 number)

(2)

select HEADER_FILE, HEADER_BLOCK,BYTES,BLOCKS,INITIAL_EXTENT,EXTENTS,NEXT_EXTENT

from dba_segments where segment_type='TABLE' and owner='SCOTT' and segment_name='T1';

 

HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS INITIAL_EXTENT    EXTENTS NEXT_EXTENT

----------- ------------ ---------- ---------- -------------- ---------- -----------

          4       251           65536          8          65536          1

2. 三个进程update t1 3条记录。

3. table t1  dump文件:

SQL> alter system dump datafile 4 block min 251 block max 258;

4.
读取 table dump文件:


   (1)t1表头(segment_header):
buffer tsn: 4 rdba: 0x010000fb (4/251)
scn: 0x0000.000c6195 seq: 0x02 flg: 0x04 tail: 0x61952302

 

    (4) buffer tsn: 4 rdba: 0x010000fe (4/254)
Itl           Xid                 Uba         Flag  Lck        Scn/Fsc

0x01   0x0001.00b.00000147  0x0080000d.00ce.1b  ----    1  fsc 0x0000.00000000

0x02   0x0005.025.0000013b  0x00800a05.010f.14  ----    1  fsc 0x0000.00000000

0x03   0x0009.01e.00000150  0x0080015f.00a8.33  ----    1  fsc 0x0000.00000000

         block_row_dump:

tab 0, row 0, @0x1f76

tl: 10 fb: --H-FL-- lb: 0x2  cc: 2

col  0: [ 2]  c1 02

col  1: [ 3]  c2 02 02

tab 0, row 1, @0x1f6c

tl: 10 fb: --H-FL-- lb: 0x1  cc: 2

col  0: [ 2]  c1 03

col  1: [ 3]  c2 03 02

tab 0, row 2, @0x1f62

tl: 10 fb: --H-FL-- lb: 0x3  cc: 2

col  0: [ 2]  c1 04

col  1: [ 3]  c2 04 02

end_of_block_dump

 

5. 读取undo header记录:

查看undo的TRN tab事务

SQL> select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec from v$transaction;

 

    XIDUSN    XIDSLOT     XIDSQN    
UBABLK     UBAFIL     UBAREC

---------- ---------- ---------- ---------- ---------- ----------

         1         11        327         13          2         27

         9         30        336        351          2         51

         5         37        315       2565          2         20

//三个事务的undo记录,在三个undo字段中,表头中slot记录事务列表信息。数据文件2中一些数据块存储了undo的记录。

SQL> select trunc(id1/65536) usn,mod(id1,65536) slot,id2 wrap,lmode  from v$lock where type='TX';

 

       USN       SLOT       WRAP      LMODE

---------- ---------- ---------- ----------

         1         11        327          6

         9         30        336          6

         5         37        315          6

通过xid获取相应事务对于undo段的undo header信息

alter system dump undo header '_SYSSMU9$';

alter system dump undo header '_SYSSMU1$';

alter system dump undo header '_SYSSMU5$';

 

Undo Segment:  _SYSSMU9$ (9)

index  state cflags  wrap#    uel         scn           dba           parent-xid    nub     stmt_num    cmt

  ------------------------------------------------------------------------------------------------

0x1e   10    0x80  0x0150  0x0002  0x0000.000c6202  0x0080015f  0x0000.000.00000000  0x00000001   0x00000000  0

 

Undo Segment:  _SYSSMU1$ (1)

index  state cflags  wrap#    uel         scn            dba            parent-xid    nub     stmt_num    cmt

  ------------------------------------------------------------------------------------------------

0x0b   10    0x80  0x0147  0x0000  0x0000.000c61c3  0x0080000d  0x0000.000.00000000  0x00000001   0x00000000  0

 

Undo Segment:  _SYSSMU5$ (5)

index  state cflags  wrap#    uel        scn            dba            parent-xid    nub     stmt_num    cmt

  ------------------------------------------------------------------------------------------------

0x25   10    0x80  0x013b  0x0002  0x0000.000c61b8  0x00800a05  0x0000.000.00000000  0x00000001   0x00000000  0

4.5.1 数据块地址

1. DBA

DBA(Data Block Address)一般指绝对数据块地址

如Undo数据块地址:
 dba (file#, block#): 2,0x0000001f(10进制31)
 
如ITL表中XID对应undo数据块地址

v$transaction表中ubablk=351

 

TRN table中相应事务ID对应dba(0x0080015f)换算为10进制:351;

2. rdba

Rdba(Tablespace relative database block address)是相对数据块地址,

rdba: 0x010000fb (4/251)  fb换算为10进制为251

如果数据文件超过>=1024即2的10次方的话,仅用绝对dba在内部没办法表示的,内部一般是用rdba来表示,它限定了某个数据文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: