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

深入理解Oracle事务过程

2017-03-19 15:40 543 查看

1. 构造测试数据

SQL> create table t(id int,name varchar2(32));

Table created.

SQL> insert into t values(1,'AAAAA');

1 row created.

SQL> commit;

Commit complete.

SQL> update t set name='BBBBB' where id=1; # update事务

1 row updated.

2. dump操作的数据块

SQL> select dbms_rowid.rowid_relative_fno(rowid) file#,dbms_rowid.rowid_block_number(rowid) block# from t;

FILE# BLOCK#
---------- ----------
1 94897

SQL> alter system dump datafile 1 block 94897;

System altered.

3. trace文件内容分析

itl事务槽:

Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0003.00a.00000405 0x00c00a85.00a1.27 C--- 0 scn 0x0000.00137a59
0x02 0x0005.010.00000401 0x00c00d6c.00bf.3b ---- 1 fsc 0x0000.00000000Xid:Transaction identifiers (XID) uniquely identify a transaction within the system. They are used

within the ITL of a data or index block.
A transaction identifier consists of:

  * Rollback/undo segment number  # 回滚段编号

  * Transaction table slot number  # 事务槽编号

  * Sequence number or wrap# # 事务所在的这一行被重用的次数

XID = usn#.slot#.warp#

数据块内容:

data_block_dump,data header at 0x7f001dd9da5c
===============
tsiz: 0x1fa0
hsiz: 0x14
pbl: 0x7f001dd9da5c
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x1f94
avsp=0x1f80
tosp=0x1f80
0xe:pti[0] nrow=1 offs=0
0x12:pri[0] offs=0x1f94
block_row_dump:
tab 0, row 0, @0x1f94
tl: 12 fb: --H-FL-- lb: 0x2 cc: 2
col 0: [ 2] c1 02
col 1: [ 5] 42 42 42 42 42 #即BBBBB

4. 根据ITL槽上的XID找出对应的Undo回滚段段头的信息

0x0005.010.00000401:即5号回滚段

dump 5号回滚段的段头信息:

SQL> select * from v$rollname;

USN NAME
---------- ------------------------------------------------------------------------------------------
0 SYSTEM
1 _SYSSMU1_3724004606$
2 _SYSSMU2_2996391332$
3 _SYSSMU3_1723003836$
4 _SYSSMU4_1254879796$
5 _SYSSMU5_898567397$
6 _SYSSMU6_1263032392$
7 _SYSSMU7_2070203016$
8 _SYSSMU8_517538920$
9 _SYSSMU9_1650507775$
10 _SYSSMU10_1197734989$

11 rows selected.
SQL> alter system dump undo header '_SYSSMU5_898567397$';

System altered.

trace文件内容:

index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
------------------------------------------------------------------------------------------------
0x00 9 0x00 0x0401 0x0002 0x0000.00137873 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x01 9 0x00 0x0401 0xffff 0x0000.001379fe 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904857
0x02 9 0x00 0x0401 0x0020 0x0000.00137883 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x03 9 0x00 0x0401 0x0005 0x0000.0013780c 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x04 9 0x00 0x0401 0x000c 0x0000.001378db 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x05 9 0x00 0x0401 0x0016 0x0000.00137820 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x06 9 0x00 0x0401 0x0008 0x0000.00137928 0x00c00d6c 0x0000.000.00000000 0x00000001 0x000000
4000
00 1489904694
0x07 9 0x00 0x0401 0x0000 0x0000.00137868 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x08 9 0x00 0x0401 0x001d 0x0000.00137934 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x09 9 0x00 0x0400 0x0003 0x0000.001377fb 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x0a 9 0x00 0x0400 0x0019 0x0000.00137737 0x00c00d6b 0x0000.000.00000000 0x00000001 0x00000000 1489904545
0x0b 9 0x00 0x0400 0x000e 0x0000.001374ba 0x00c00d6b 0x0000.000.00000000 0x00000001 0x00000000 1489904111
0x0c 9 0x00 0x0401 0x000d 0x0000.001378ef 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x0d 9 0x00 0x0400 0x0013 0x0000.00137900 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 1489904694
0x0e 9 0x00 0x0400 0x000f 0x0000.00137514 0x00c00d6b 0x0000.000.00000000 0x00000001 0x00000000 1489904171
0x0f 9 0x00 0x03fe 0x0012 0x0000.001375a3 0x00c00d6b 0x0000.000.00000000 0x00000001 0x00000000 1489904280
0x10 10 0x80 0x0401 0x0002 0x0000.00137a79 0x00c00d6c 0x0000.000.00000000 0x00000001 0x00000000 0找到对应的010行,即是该操作对应的事务
Index:表示事务槽中槽号,只是一个序列,从0x00开始到0x21结束,11g的版本有34个槽

state: 表示事务状态,9代表不活动的事务,10代表事务正在活动

wrap#:表示事务表上的事务槽被重用的次数,是XID的一部分

uel:表示当前活动事务所在事务槽的下一个事务槽的指针(即如果发生新的事务,就会用到UEL指向的事务槽上的index)

scn:表示事务启动、提交、回滚的SCN

dba:表示uba,这个DBA是(rollback)回滚的起始点,也就是说记录事务修改的最后一条记录所在的undo块的地址

nub:表示当前事务所用到的undo块的个数

cmt:表示最接近当前的提交时间戳(以秒为单位记录),0表示事务正在活动

5. 根据事务表中dba即undo数据块的地址,结合数据块中的uba,查找事务修改前的值

00c即三号数据文件

SQL> select to_number('d6c','xxxxxxxxxx') from dual;

TO_NUMBER('D6C','XXXXXXXXXX')
-----------------------------
3436
SQL> alter system dump datafile 3 block 3436;

System altered.
trace文件内容分析:
UNDO BLK:
xid: 0x0005.010.00000401 seq: 0xbf cnt: 0x3b irb: 0x3b icl: 0x0 flg: 0x0000 # 与数据块和事务表上的xid一致

Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
---------------------------------------------------------------------------
0x01 0x1f38 0x02 0x1e88 0x03 0x1e0c 0x04 0x1d90 0x05 0x1ce0
0x06 0x1c64 0x07 0x1bf8 0x08 0x1b8c 0x09 0x1adc 0x0a 0x1a70
0x0b 0x19e8 0x0c 0x1988 0x0d 0x18d8 0x0e 0x186c 0x0f 0x17bc
0x10 0x1740 0x11 0x16d4 0x12 0x1668 0x13 0x15fc 0x14 0x1590
0x15 0x1524 0x16 0x1474 0x17 0x1408 0x18 0x138c 0x19 0x1320
0x1a 0x1270 0x1b 0x1204 0x1c 0x1198 0x1d 0x10e8 0x1e 0x107c
0x1f 0x100c 0x20 0x0fa0 0x21 0x0f34 0x22 0x0ec8 0x23 0x0e5c
0x24 0x0dac 0x25 0x0d40 0x26 0x0cd4 0x27 0x0c68 0x28 0x0bb8
0x29 0x0b4c 0x2a 0x0a9c 0x2b 0x0a30 0x2c 0x09c4 0x2d 0x0914
0x2e 0x0864 0x2f 0x07f8 0x30 0x0748 0x31 0x06dc 0x32 0x062c
0x33 0x05b0 0x34 0x0534 0x35 0x04ac 0x36 0x0450 0x37 0x03a0
0x38 0x0324 0x39 0x0288 0x3a 0x0218 0x3b 0x0170
*-----------------------------
* Rec #0x3b  slt: 0x10  objn: 88682(0x00015a6a)  objd: 88682  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000Ext idx: 0
flg2: 0
*-----------------------------
uba: 0x00c00d6c.00bf.3a ctl max scn: 0x0000.0013732f prv tx scn: 0x0000.00137343
txn start scn: scn: 0x0000.00137a79 logon user: 0
prev brb: 12586347 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03  ver: 0x01
compat bit: 4 (post-11) padding: 1
op: Z
Array Update of 1 rows:
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 12
ncol: 2 nnew: 1 size: 0
KDO Op code:  21 row dependencies Disabled
xtype: XAxtype KDO_KDOM2 flags: 0x00000080  bdba: 0x004172b1  hdba: 0x004172b0
itli: 2  ispac: 0  maxfr: 4863
vect = 3
col  1: [ 5]  41 41 41 41 41 # 事务的前映像
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: