转载:原文地址:http://blog.csdn.net/oradh/article/details/25778779
这篇文章主要描述oracle的回滚机制,篇幅可能较长,因为对于oracle的回滚机制来说,要讨论和描述的实在太多,只能刷选自己认为最有意义的一部分进行深入研究和分享
一、我们来看一个DML语句的处理过程描述
update undotest set object_type='VIEW' where object_type='PROCEDURE';
- 检查shared pool中是否存在相同的语句,如果存在,重用执行计划,执行扫描运算,如果不存在,执行硬解析生成执行计划
- 根据执行计划中的扫描运算,检查undotest表中的相关数据块是否存在buffer cache中,如果不存在则读取到内存中
- 检查数据块中符合object_type='PROCEDURE'条件的记录,如果没有符合条件的行记录,则结束语句,如果存在则进入下一步
- 以当前模式(current)获取符合object_type='PROCEDURE'条件的数据块,准备进行更新
- 在回滚表空间的相应回滚段头的事务表上分配事务槽,这个动作需要记录redo日志
- 从回滚段数据块上创建object_type='PROCEDURE'的前映像数据,这个动作也要记录redo日志
- 修改object_type='VIEW' ,这是DML操作的数据变更,而需要记录redo日志
- 用户提交时,在redo日志中记录提交信息,将回滚段头上的事务表和回滚段数据块标记为非活动,清除修改数据块上的事务信息(也可能延迟清除)。同时必须确保整个事务的redp日志写到磁盘上的日志文件
注意:如果最后用户回滚了事务,oracle从回滚段中将前映像数据提取出来,覆盖被更新的数据块。这个回滚动作本身也需要产生redo日志,因此,我们要知道回滚的代价非常昂贵。
二、不同的DML操作,UNDO BLOCK中保存的前映像内容
- INSERT操作,UNDO中只需要保存插入记录的rowid,如果需要回退,通过保存的rowid进行删除即可(后面有案例)
- UPDATE操作,UNDO中只需要记录被更新字段的旧值,如果需要回退,只需要通过旧值覆盖更新后的值即可。
- DELETE操作,UNDO中必须记录整行的数据,如果需要回退,只需要将这整行的数据重新插入至表中即可。
备注:本文章只对INSERT操作,UNDO中保存的内容进行测试,至于UPDATE、DELETE操作,实验方法基本一致,这里就不再累赘
示例
1.开启事务
SQL
>
create
table tt
as
select object_name,object_id
from dba_objects;
Table created.
SQL > insert into tt values( 'dddddd', 1233456); --执行insert操作
1 row created.
Table created.
SQL > insert into tt values( 'dddddd', 1233456); --执行insert操作
1 row created.
2.检查事务信息和其他一些事务信息
SQL > select HEADER_FILE,HEADER_BLOCK from dba_segments a where segment_name = 'TT';
HEADER_FILE HEADER_BLOCK
- - - - - - - - - - - - - - - - - - - - - - -
4 810
SQL > SELECT
2 dbms_rowid.rowid_object(rowid) object_id,
3 dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
4 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
5 dbms_rowid.rowid_row_number(rowid) ROWNO,rowid,object_name
6 FROM tt WHERE object_name = 'dddddd';
OBJECT_ID REL_FNO BLOCKNO ROWNO ROWID
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OBJECT_NAME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73430 4 1150 0 AAAR7WAAEAAAAR +AAA
dddddd
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5 21 960 1466 3 7 0 f5520 1004832
根据上面查询获取的事务信息,dump insert事务undo 段头和undo 块
SQL > select HEADER_FILE,HEADER_BLOCK from dba_segments a where segment_name = 'TT';
HEADER_FILE HEADER_BLOCK
- - - - - - - - - - - - - - - - - - - - - - -
4 810
SQL > SELECT
2 dbms_rowid.rowid_object(rowid) object_id,
3 dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
4 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
5 dbms_rowid.rowid_row_number(rowid) ROWNO,rowid,object_name
6 FROM tt WHERE object_name = 'dddddd';
OBJECT_ID REL_FNO BLOCKNO ROWNO ROWID
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OBJECT_NAME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73430 4 1150 0 AAAR7WAAEAAAAR +AAA
dddddd
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5 21 960 1466 3 7 0 f5520 1004832
根据上面查询获取的事务信息,dump insert事务undo 段头和undo 块
SQL
>
select
name
from v$rollname
where usn
=
5;
NAME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SYSSMU5_1527469038$
NAME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SYSSMU5_1527469038$
3.dump undo 段头和undo 块
SQL > oradebug setmypid;
Statement processed.
SQL > oradebug tracefile_name
/u01 /oracle /diag /rdbms /test /test /trace /test_ora_604.trc
SQL > alter system dump undo header '_SYSSMU5_1527469038$';
System altered.
SQL > alter system dump datafile 3 block 1466;
System altered.
UNDO BLK:
xid: 0x0005. 015. 000003c0 seq: 0x12c cnt: 0x7 irb: 0x7 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1fa4 0x02 0x1f48 0x03 0x1ecc 0x04 0x1e70 0x05 0x1df4
0x06 0x1d90 0x07 0x1d20
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x7 slt: 0x15 objn: 73430(0x00011ed6) objd: 73430 tblspc: 4(0x00000004)
* 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: 0x00c005b9. 012c. 2d ctl max scn: 0x0000.000f4ed4 prv tx scn: 0x0000.000f4ee0
txn start scn: scn: 0x0000.000f53a9 logon user: 85
prev brb: 12584373 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: DRP row dependencies Disabled --DRP操作完成回滚
xtype: XA flags: 0x00000000 bdba: 0x0100047e hdba: 0x0100032a --bdba表示block address hdba 代表sgment header address
itli: 1 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) - - - - - - - - - 这个slot表示这一行数据在数据块中的行地址(行序列)
其中bdba表示file 4,block 1150 ,hdba表示file 4,block 810 与我们上面查询出来的地址相符。
SQL > oradebug setmypid;
Statement processed.
SQL > oradebug tracefile_name
/u01 /oracle /diag /rdbms /test /test /trace /test_ora_604.trc
SQL > alter system dump undo header '_SYSSMU5_1527469038$';
System altered.
SQL > alter system dump datafile 3 block 1466;
System altered.
UNDO BLK:
xid: 0x0005. 015. 000003c0 seq: 0x12c cnt: 0x7 irb: 0x7 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1fa4 0x02 0x1f48 0x03 0x1ecc 0x04 0x1e70 0x05 0x1df4
0x06 0x1d90 0x07 0x1d20
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x7 slt: 0x15 objn: 73430(0x00011ed6) objd: 73430 tblspc: 4(0x00000004)
* 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: 0x00c005b9. 012c. 2d ctl max scn: 0x0000.000f4ed4 prv tx scn: 0x0000.000f4ee0
txn start scn: scn: 0x0000.000f53a9 logon user: 85
prev brb: 12584373 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: DRP row dependencies Disabled --DRP操作完成回滚
xtype: XA flags: 0x00000000 bdba: 0x0100047e hdba: 0x0100032a --bdba表示block address hdba 代表sgment header address
itli: 1 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) - - - - - - - - - 这个slot表示这一行数据在数据块中的行地址(行序列)
其中bdba表示file 4,block 1150 ,hdba表示file 4,block 810 与我们上面查询出来的地址相符。
我们可以看到,undo块中并没有直接保存rowid信息,但是oracle完全可以根据上面的几个信息(bdba,slot,objd)定位回滚时需要删除的具体数据,因此对于Insert操作,ORACLE只需保留上述信息,即可完成回滚操作
三、基本概念和名词解释
- UBA: Undo block address
- RBA: Redo block address
- Dba: Data block address
- Rdba: Root dba
- Xid: Transaction ID
- ITL: Interested Transaction List 保存在数据块的头部(事务信息部分),包含XID,UBA,LCK,FLG等重要信息
Transaction Identifiers
Transaction identifiers (XID) uniquely identify a transaction within the system; they are used within the Interested Transaction List (ITL) of the data block.
A transaction identifier consists of:
- Undo segment number 即v$rollname中的usn
- Transaction table slot number 对应回滚段头中回滚事务表的第几条记录
- Sequence number or wrap#
XID = usn# . slot# . wrap#
Undo Block Address
The undo block address (UBA) uniquely identifies the undo block for a given transaction; it is found within the ITL of the data block.
A UBA consists of:
- Data block address (DBA) of the block 前映像undo 块地址
- The sequence number of the block 序列号
- The record number within the block undo记录的开始地址(针对该块)
UBA = DBA. seq#. rec#
四、从一个DML语句开始研究,SESSION A执行下面的语句,更新完成后先不提交
(1)session A执行更新,更新两条数据,如下
SQL
>
select
*
from undotest
where object_type
=
'PROCEDURE'
and id
in (
4703,
4704);
ID OBJECT_ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4703 4771 SUBPTXT2 PROCEDURE
4704 4772 SUBPTXT PROCEDURE
SQL > update undotest set object_type = 'VIEW' where object_type = 'PROCEDURE' and id in ( 4703, 4704);
2 rows updated.
SQL > select * from undotest where id in ( 4703, 4704);
ID OBJECT_ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4703 4771 SUBPTXT2 VIEW
4704 4772 SUBPTXT VIEW
ID OBJECT_ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4703 4771 SUBPTXT2 PROCEDURE
4704 4772 SUBPTXT PROCEDURE
SQL > update undotest set object_type = 'VIEW' where object_type = 'PROCEDURE' and id in ( 4703, 4704);
2 rows updated.
SQL > select * from undotest where id in ( 4703, 4704);
ID OBJECT_ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4703 4771 SUBPTXT2 VIEW
4704 4772 SUBPTXT VIEW
(2)查询更新数据块的信息和事务信息
s
QL
>
SELECT
2
dbms_rowid.rowid_object(rowid) object_id,
3 dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
4 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
5 dbms_rowid.rowid_row_number(rowid) ROWNO,rowid,id,object_name,object_type
6 FROM dh.undotest WHERE id in ( 4703, 4704);
OBJECT_ID REL_FNO BLOCKNO ROWNO ROWID ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73424 4 195 70 AAAR7QAAEAAAADDABG 4703 SUBPTXT2 VIEW
73424 4 195 71 AAAR7QAAEAAAADDABH 4704 SUBPTXT VIEW
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 0 4 258 5 2 0 0 0
SQL > select name from v$rollname where usn = 19;
NAME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SYSSMU19$
4 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
5 dbms_rowid.rowid_row_number(rowid) ROWNO,rowid,id,object_name,object_type
6 FROM dh.undotest WHERE id in ( 4703, 4704);
OBJECT_ID REL_FNO BLOCKNO ROWNO ROWID ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73424 4 195 70 AAAR7QAAEAAAADDABG 4703 SUBPTXT2 VIEW
73424 4 195 71 AAAR7QAAEAAAADDABH 4704 SUBPTXT VIEW
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 0 4 258 5 2 0 0 0
SQL > select name from v$rollname where usn = 19;
NAME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SYSSMU19$
(3)刷新内存,dump数据块,undo 段头,undo block,如下
SQL
>
alter
system flush buffer_cache;
System altered.
SQL > oradebug
SQL > oradebug setmypid
Statement processed.
SQL > oradebug tracefile_name
/u01 /oracle /diag /rdbms /test /test /trace /test_ora_902.trc
SQL > alter system dump datafile 4 block 195;
System altered.
SQL > alter system dump undo header '_SYSSMU19$';
System altered.
SQL > alter system dump datafile 5 block 258;
System altered.
System altered.
SQL > oradebug
SQL > oradebug setmypid
Statement processed.
SQL > oradebug tracefile_name
/u01 /oracle /diag /rdbms /test /test /trace /test_ora_902.trc
SQL > alter system dump datafile 4 block 195;
System altered.
SQL > alter system dump undo header '_SYSSMU19$';
System altered.
SQL > alter system dump datafile 5 block 258;
System altered.
(4)分析数据块dump文件
Block header dump: 0x010000c3
Object id on Block? Y
seg /obj: 0x11ed0 csc: 0x00.f2e95 itc: 3 flg: E typ: 1 - DATA
brn: 1 bdba: 0x10000b8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn /Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C - - - 0 scn 0x0000.000f2e95
0x02 0x0013.000. 00000004 0x01400102. 0001. 02 - - - - 2 fsc 0x000a.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 - - - - 0 fsc 0x0000.00000000
uba中undo record参数为2,即这个事务在这个数据块上的变更(修改)产生的undo记录(变更旧值记录)在对应的undo数据块中的开始地址(开始偏移量)
bdba: 0x010000c3
data_block_dump, data header at 0x2b0a86e2da7c
.....省略一部分..........
tab 0, row 70, @0x45f
tl: 25 fb: - -H -FL - - lb: 0x2 cc: 4 - - -这一行数据被锁定,锁定该行数据的事务为ITL事务槽中的第二个事务。
col 0: [ 3] c2 30 04
col 1: [ 3] c2 30 48
col 2: [ 8] 53 55 42 50 54 58 54 32
col 3: [ 4] 56 49 45 57
tab 0, row 71, @0x447
tl: 24 fb: - -H -FL - - lb: 0x2 cc: 4 - - -这一行数据被锁定,锁定该行数据的事务为ITL事务槽中的第二个事务。
col 0: [ 3] c2 30 05
col 1: [ 3] c2 30 49
col 2: [ 7] 53 55 42 50 54 58 54
col 3: [ 4] 56 49 45 57
.........省略trace 文件中后面的输出.............
Object id on Block? Y
seg /obj: 0x11ed0 csc: 0x00.f2e95 itc: 3 flg: E typ: 1 - DATA
brn: 1 bdba: 0x10000b8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn /Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C - - - 0 scn 0x0000.000f2e95
0x02 0x0013.000. 00000004 0x01400102. 0001. 02 - - - - 2 fsc 0x000a.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 - - - - 0 fsc 0x0000.00000000
uba中undo record参数为2,即这个事务在这个数据块上的变更(修改)产生的undo记录(变更旧值记录)在对应的undo数据块中的开始地址(开始偏移量)
bdba: 0x010000c3
data_block_dump, data header at 0x2b0a86e2da7c
.....省略一部分..........
tab 0, row 70, @0x45f
tl: 25 fb: - -H -FL - - lb: 0x2 cc: 4 - - -这一行数据被锁定,锁定该行数据的事务为ITL事务槽中的第二个事务。
col 0: [ 3] c2 30 04
col 1: [ 3] c2 30 48
col 2: [ 8] 53 55 42 50 54 58 54 32
col 3: [ 4] 56 49 45 57
tab 0, row 71, @0x447
tl: 24 fb: - -H -FL - - lb: 0x2 cc: 4 - - -这一行数据被锁定,锁定该行数据的事务为ITL事务槽中的第二个事务。
col 0: [ 3] c2 30 05
col 1: [ 3] c2 30 49
col 2: [ 7] 53 55 42 50 54 58 54
col 3: [ 4] 56 49 45 57
.........省略trace 文件中后面的输出.............
(5)分析undo 段头dump文件
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Undo Segment: _SYSSMU19$ (19)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Extent Control Header
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
............省略中间一部分................
Retention Table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Extent Number: 0 Commit Time: 0
Extent Number: 1 Commit Time: 0
TRN CTL:: seq: 0x0001 chd: 0x0001 ctl: 0x0021 inc: 0x00000000 nfb: 0x0000
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x01400102.0001.01 scn: 0x0000.000e61e6
Undo Segment: _SYSSMU19$ (19)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Extent Control Header
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
............省略中间一部分................
Retention Table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Extent Number: 0 Commit Time: 0
Extent Number: 1 Commit Time: 0
TRN CTL:: seq: 0x0001 chd: 0x0001 ctl: 0x0021 inc: 0x00000000 nfb: 0x0000
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x01400102.0001.01 scn: 0x0000.000e61e6
这个uba经过测试验证,为事务表中最后(最新)一个事务的对应的undo block上的第一个undo record,即当这个回滚段头存在多个事务时,这个uba表示最新的事务的uba地址,这个地址在整个事务的周期内不发生改变(除非这个回滚段头上又分配了一个新的事务表),因此,这个地址指向的是事务使用的第一个undo block
Version: 0x01
FREE BLOCK POOL::
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
TRN TBL::
index state cflags wrap# uel scn dba parent -xid nub stmt_num cmt
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x00 10 0x80 0x0004 0x0000 0x0000.00000000 0x01400102 0x0000.000.00000000 0x00000001 0x00000000 0
0x01 9 0x00 0x0003 0x0002 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x02 9 0x00 0x0003 0x0003 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x03 9 0x00 0x0003 0x0004 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
............省略中间一部分................
0x1f 9 0x00 0x0003 0x0020 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x20 9 0x00 0x0003 0x0021 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x21 9 0x00 0x0003 0xffff 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
Version: 0x01
FREE BLOCK POOL::
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
TRN TBL::
index state cflags wrap# uel scn dba parent -xid nub stmt_num cmt
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x00 10 0x80 0x0004 0x0000 0x0000.00000000 0x01400102 0x0000.000.00000000 0x00000001 0x00000000 0
0x01 9 0x00 0x0003 0x0002 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x02 9 0x00 0x0003 0x0003 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x03 9 0x00 0x0003 0x0004 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
............省略中间一部分................
0x1f 9 0x00 0x0003 0x0020 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x20 9 0x00 0x0003 0x0021 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x21 9 0x00 0x0003 0xffff 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
回顾我们开始时查询的事务XID信息:xidslot=0(这个事务占用UNDO事务表中第几号事务槽) and xidseq=4 与上面标红的0x00、state=10(代表事务状态为活动)、wrap#=4 完全相符合。
其中dba列值表示包含这个事务的前映像的undo块地址(事务最后更新的前映像UNDO地址),与ITL事务槽中的uba地址一致 ,即file 5,block 258(可使用dbms_utility.data_block_address_file函数转换)
(6)分析UNDO block dump文件
UNDO BLK:
xid: 0x0013.000. 00000004 seq: 0x1 cnt: 0x2 irb: 0x2 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset - -undo信息偏移量,在undo块中偏移
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1f58 0x02 0x1ef4 - -当前undo块中的最后一个偏移地址即Ox02 与irb一致
其中irb:0x2 表示未提交事务最新(最后执行的)变更对应的undo数据块中的UNDO record地址,如果开始rollback,这是回滚的起点。
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x1 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004) - -根据Rec #0x2 中的rci记录找到#0x1
* Layer: 11 ( Row) opc: 1 rci 0x00 - -rci指针为 0,表示这是事务回滚过程中的最后一条记录
Undo type: Regular undo Begin trans Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000Ext idx: 0
flg2: 0
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uba: 0x00000000.0000.00 ctl max scn: 0x0000.000e61e6 prv tx scn: 0x0000.000e61e6
txn start scn: scn: 0x0000.00000000 logon user: 85
prev brb: 0 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 70(0x46) flag: 0x2c lock: 0 ckix: 80 - -slot表示更新数据的行序列值(rowno),用于定位具体的数据,与我们查询的一致
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 - - -转换为字符为‘ PROCEDURE’,与我们更新前数据一致
转换方法:
SELECT utl_raw.cast_to_varchar2(replace('50 52 4f 43 45 44 55 52 45',' ')) value FROM dual;
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x2 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x01 --指向REC# 0x01,即上一个偏移量
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102. 0001. 01 --这个uba表示undo chain tx table,即同一update语句中的undo chain地址,这里为1,指向第一个偏移量。一个事务中的不同DML语句,无法通过该参数连接起来(形成undo chain),因为该参数,不能跨越DML语句。
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 71(0x47) flag: 0x2c lock: 0 ckix: 80 --slot表示更新数据的行序列值(rowno),用于定位具体的数据,与我们查询的一致
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 - -与上面描述的一样,转换为字符为‘ PROCEDURE’,与我们更新前数据一致
Rec #0x2 这条undo record中还记录了一个rci参数,表示undo chain,同一个事务中的多次修改,根据这个chain连接起来。
当前rci参数值为0x01,即指向该undo块中的第一个undo record,找到Rec #0x01 undo record后,检查发现确实是我们这个UPDATE语句中的被更新的另一条数据。
xid: 0x0013.000. 00000004 seq: 0x1 cnt: 0x2 irb: 0x2 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset - -undo信息偏移量,在undo块中偏移
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1f58 0x02 0x1ef4 - -当前undo块中的最后一个偏移地址即Ox02 与irb一致
其中irb:0x2 表示未提交事务最新(最后执行的)变更对应的undo数据块中的UNDO record地址,如果开始rollback,这是回滚的起点。
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x1 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004) - -根据Rec #0x2 中的rci记录找到#0x1
* Layer: 11 ( Row) opc: 1 rci 0x00 - -rci指针为 0,表示这是事务回滚过程中的最后一条记录
Undo type: Regular undo Begin trans Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000Ext idx: 0
flg2: 0
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uba: 0x00000000.0000.00 ctl max scn: 0x0000.000e61e6 prv tx scn: 0x0000.000e61e6
txn start scn: scn: 0x0000.00000000 logon user: 85
prev brb: 0 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 70(0x46) flag: 0x2c lock: 0 ckix: 80 - -slot表示更新数据的行序列值(rowno),用于定位具体的数据,与我们查询的一致
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 - - -转换为字符为‘ PROCEDURE’,与我们更新前数据一致
转换方法:
SELECT utl_raw.cast_to_varchar2(replace('50 52 4f 43 45 44 55 52 45',' ')) value FROM dual;
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x2 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x01 --指向REC# 0x01,即上一个偏移量
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102. 0001. 01 --这个uba表示undo chain tx table,即同一update语句中的undo chain地址,这里为1,指向第一个偏移量。一个事务中的不同DML语句,无法通过该参数连接起来(形成undo chain),因为该参数,不能跨越DML语句。
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 71(0x47) flag: 0x2c lock: 0 ckix: 80 --slot表示更新数据的行序列值(rowno),用于定位具体的数据,与我们查询的一致
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 - -与上面描述的一样,转换为字符为‘ PROCEDURE’,与我们更新前数据一致
Rec #0x2 这条undo record中还记录了一个rci参数,表示undo chain,同一个事务中的多次修改,根据这个chain连接起来。
当前rci参数值为0x01,即指向该undo块中的第一个undo record,找到Rec #0x01 undo record后,检查发现确实是我们这个UPDATE语句中的被更新的另一条数据。
五、在SESSION A中继续进行更新操作,进一步研究
(1)更新两条数据,同时查询基本的事务信息和数据块信息
SQL
>
update undotest
set object_type
=
'VIEW'
where object_type
=
'PROCEDURE'
and id
in (
11504,
11505);
2 rows updated.
SQL > SELECT
2 dbms_rowid.rowid_object(rowid) object_id,
3 dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
4 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
5 dbms_rowid.rowid_row_number(rowid) ROWNO,rowid,id,object_name,object_type
6 FROM undotest WHERE id in ( 11504, 11505);
OBJECT_ID REL_FNO BLOCKNO ROWNO ROWID ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73424 4 236 41 AAAR7QAAEAAAADsAAp 11504 DBMS_FEATURE_RMAN_BZ PROCEDURE
IP2
73424 4 236 42 AAAR7QAAEAAAADsAAq 11505 DBMS_FEATURE_RMAN_BA PROCEDURE
SIC
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 0 4 258 5 4 0 0 0
SQL > alter system flush buffer_cache;
System altered.
SQL > alter system dump datafile 4 block 195;
System altered.
SQL > alter system dump datafile 4 block 236;
System altered.
SQL > alter system dump undo header '_SYSSMU19$';
System altered.
SQL > alter system dump datafile 5 block 258;
System altered.
2 rows updated.
SQL > SELECT
2 dbms_rowid.rowid_object(rowid) object_id,
3 dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
4 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
5 dbms_rowid.rowid_row_number(rowid) ROWNO,rowid,id,object_name,object_type
6 FROM undotest WHERE id in ( 11504, 11505);
OBJECT_ID REL_FNO BLOCKNO ROWNO ROWID ID OBJECT_NAME OBJECT_TYPE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73424 4 236 41 AAAR7QAAEAAAADsAAp 11504 DBMS_FEATURE_RMAN_BZ PROCEDURE
IP2
73424 4 236 42 AAAR7QAAEAAAADsAAq 11505 DBMS_FEATURE_RMAN_BA PROCEDURE
SIC
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 0 4 258 5 4 0 0 0
SQL > alter system flush buffer_cache;
System altered.
SQL > alter system dump datafile 4 block 195;
System altered.
SQL > alter system dump datafile 4 block 236;
System altered.
SQL > alter system dump undo header '_SYSSMU19$';
System altered.
SQL > alter system dump datafile 5 block 258;
System altered.
(2)分析数据块dump文件
可以看到,SESSION A事务中第一个update语句修改的数据块(datafile 4 block 195)没有任何改变
Block header dump: 0x010000c3
Object id on Block? Y
seg /obj: 0x11ed0 csc: 0x00.f2e95 itc: 3 flg: E typ: 1 - DATA
brn: 1 bdba: 0x10000b8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn /Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C - - - 0 scn 0x0000.000f2e95
0x02 0x0013.000. 00000004 0x01400102. 0001. 02 - - - - 2 fsc 0x000a.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 - - - - 0 fsc 0x0000.00000000
bdba: 0x010000c3
data_block_dump, data header at 0x2b5f5d4e6a7c
.........省略trace 文件中后面的输出.............
事务中第二个update语句修改的数据块(4,236)上的事务信息与我们查询的一致,如下
Block header dump: 0x010000ec
Object id on Block? Y
seg /obj: 0x11ed0 csc: 0x00.f2e95 itc: 3 flg: E typ: 1 - DATA
brn: 0 bdba: 0x10000e8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn /Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C - - - 0 scn 0x0000.000f2e95
0x02 0x0013.000.00000004 0x01400102.0001.04 ---- 2 fsc 0x000a.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 - - - - 0 fsc 0x0000.00000000
bdba: 0x010000ec
data_block_dump, data header at 0x2b5f5d4e6a7c
..........省略一部分..........
tab 0, row 41, @0x38f
tl: 42 fb: - -H -FL - - lb: 0x2 cc: 4
col 0: [ 4] c3 02 10 05
col 1: [ 4] c3 02 13 03
col 2: [ 23]
44 42 4d 53 5f 46 45 41 54 55 52 45 5f 52 4d 41 4e 5f 42 5a 49 50 32
col 3: [ 4] 56 49 45 57
tab 0, row 42, @0x365
tl: 42 fb: - -H -FL - - lb: 0x2 cc: 4
col 0: [ 4] c3 02 10 06
col 1: [ 4] c3 02 13 04
col 2: [ 23]
.........省略trace 文件中后面的输出.............
Block header dump: 0x010000c3
Object id on Block? Y
seg /obj: 0x11ed0 csc: 0x00.f2e95 itc: 3 flg: E typ: 1 - DATA
brn: 1 bdba: 0x10000b8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn /Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C - - - 0 scn 0x0000.000f2e95
0x02 0x0013.000. 00000004 0x01400102. 0001. 02 - - - - 2 fsc 0x000a.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 - - - - 0 fsc 0x0000.00000000
bdba: 0x010000c3
data_block_dump, data header at 0x2b5f5d4e6a7c
.........省略trace 文件中后面的输出.............
事务中第二个update语句修改的数据块(4,236)上的事务信息与我们查询的一致,如下
Block header dump: 0x010000ec
Object id on Block? Y
seg /obj: 0x11ed0 csc: 0x00.f2e95 itc: 3 flg: E typ: 1 - DATA
brn: 0 bdba: 0x10000e8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn /Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C - - - 0 scn 0x0000.000f2e95
0x02 0x0013.000.00000004 0x01400102.0001.04 ---- 2 fsc 0x000a.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 - - - - 0 fsc 0x0000.00000000
bdba: 0x010000ec
data_block_dump, data header at 0x2b5f5d4e6a7c
..........省略一部分..........
tab 0, row 41, @0x38f
tl: 42 fb: - -H -FL - - lb: 0x2 cc: 4
col 0: [ 4] c3 02 10 05
col 1: [ 4] c3 02 13 03
col 2: [ 23]
44 42 4d 53 5f 46 45 41 54 55 52 45 5f 52 4d 41 4e 5f 42 5a 49 50 32
col 3: [ 4] 56 49 45 57
tab 0, row 42, @0x365
tl: 42 fb: - -H -FL - - lb: 0x2 cc: 4
col 0: [ 4] c3 02 10 06
col 1: [ 4] c3 02 13 04
col 2: [ 23]
.........省略trace 文件中后面的输出.............
(3)分析undo 段头dump文件
Undo Segment: _SYSSMU19$ (19)
********************************************************************************
...............省略一部分..............
TRN CTL:: seq: 0x0001 chd: 0x0001 ctl: 0x0021 inc: 0x00000000 nfb: 0x0000
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x01400102.0001.01 scn: 0x0000.000e61e6
Version: 0x01
FREE BLOCK POOL::
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
TRN TBL::
index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
------------------------------------------------------------------------------------------------
0x00 10 0x80 0x0004 0x0000 0x0000.00000000 0x01400102 0x0000.000.00000000 0x00000001 0x00000000 0
0x01 9 0x00 0x0003 0x0002 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x02 9 0x00 0x0003 0x0003 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x03 9 0x00 0x0003 0x0004 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x04 9 0x00 0x0003 0x0005 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x05 9 0x00 0x0003 0x0006 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
.........省略trace 文件中后面的输出.............
********************************************************************************
...............省略一部分..............
TRN CTL:: seq: 0x0001 chd: 0x0001 ctl: 0x0021 inc: 0x00000000 nfb: 0x0000
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x01400102.0001.01 scn: 0x0000.000e61e6
Version: 0x01
FREE BLOCK POOL::
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
TRN TBL::
index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
------------------------------------------------------------------------------------------------
0x00 10 0x80 0x0004 0x0000 0x0000.00000000 0x01400102 0x0000.000.00000000 0x00000001 0x00000000 0
0x01 9 0x00 0x0003 0x0002 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x02 9 0x00 0x0003 0x0003 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x03 9 0x00 0x0003 0x0004 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x04 9 0x00 0x0003 0x0005 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x05 9 0x00 0x0003 0x0006 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
.........省略trace 文件中后面的输出.............
undo段头上的事务表没有发生改变
(4)分析undo block dump文件
UNDO BLK:
xid: 0x0013.000. 00000004 seq: 0x1 cnt: 0x4 irb: 0x4 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1f58 0x02 0x1ef4 0x03 0x1e98 0x04 0x1e34
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x1 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* 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: 0x00000000.0000.00 ctl max scn: 0x0000.000e61e6 prv tx scn: 0x0000.000e61e6
txn start scn: scn: 0x0000.00000000 logon user: 85
prev brb: 0 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 70(0x46) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x2 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x01
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.01
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 71(0x47) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x3 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x02
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ec hdba: 0x010000aa --bdba:4,236;即我们update语句修改的数据块,与查询出来的信息一致
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 41(0x29) flag: 0x2c lock: 0 ckix: 0
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 ---转换为字符为‘PROCEDURE’,与我们更新前数据一致
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x4 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x03
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.03 --新发起的update语句,uba参数值与第一条不同( Rec #0x2 undo record记录) ,事务中的每个DML语句保存自己的uba,用于语句回滚
xid: 0x0013.000. 00000004 seq: 0x1 cnt: 0x4 irb: 0x4 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1f58 0x02 0x1ef4 0x03 0x1e98 0x04 0x1e34
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x1 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* 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: 0x00000000.0000.00 ctl max scn: 0x0000.000e61e6 prv tx scn: 0x0000.000e61e6
txn start scn: scn: 0x0000.00000000 logon user: 85
prev brb: 0 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 70(0x46) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x2 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x01
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.01
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000c3 hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 71(0x47) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x3 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x02
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ec hdba: 0x010000aa --bdba:4,236;即我们update语句修改的数据块,与查询出来的信息一致
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 41(0x29) flag: 0x2c lock: 0 ckix: 0
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 ---转换为字符为‘PROCEDURE’,与我们更新前数据一致
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x4 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x03
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.03 --新发起的update语句,uba参数值与第一条不同( Rec #0x2 undo record记录) ,事务中的每个DML语句保存自己的uba,用于语句回滚
KDO Op code: URP
row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ec hdba: 0x010000aa - -bdba: 4, 236;即我们 update语句修改的数据块,与查询出来的信息一致
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 42(0x2a) flag: 0x2c lock: 0 ckix: 0
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 - - -转换为字符为‘ PROCEDURE’,与我们更新前数据一致
End dump data blocks tsn: 6 file#: 5 minblk 258 maxblk 258
xtype: XA flags: 0x00000000 bdba: 0x010000ec hdba: 0x010000aa - -bdba: 4, 236;即我们 update语句修改的数据块,与查询出来的信息一致
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 42(0x2a) flag: 0x2c lock: 0 ckix: 0
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45 - - -转换为字符为‘ PROCEDURE’,与我们更新前数据一致
End dump data blocks tsn: 6 file#: 5 minblk 258 maxblk 258
六、再次在SESSION A中进行更新,当事务使用的undo block超过一个1个时,分析整个事务的undo record是怎么串联起来。
(1)在session A 中继续更新undotest,并查看事务信息
SQL
>
update undotest
set object_type
=
'VIEW'
where object_type
=
'TABLE'
and rownum
<
99;
98 rows updated.
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 0 4 259 5 20 0 0 0
UBABLK之前为258,现在查询出来为259,因此可以肯定目前事务使用已经超过一个UNDO block。
98 rows updated.
SQL > select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec,to_char(start_scnw, 'xxxxxxxx') start_scnw,
2 to_char(start_scnb, 'xxxxxxxx') start_scnb, start_scnb +start_scnw *power( 2, 32) start_scn
3 from v$ transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC START_SCNW START_SCNB START_SCN
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 0 4 259 5 20 0 0 0
UBABLK之前为258,现在查询出来为259,因此可以肯定目前事务使用已经超过一个UNDO block。
(2)DUMP 段头,undo 块,data block,这里就不再列举出来
SQL
>
alter
system flush buffer_cache;
System altered.
SQL > alter system dump datafile 5 block 259;
System altered.
SQL > alter system dump undo header '_SYSSMU19$';
System altered.
System altered.
SQL > alter system dump datafile 5 block 259;
System altered.
SQL > alter system dump undo header '_SYSSMU19$';
System altered.
(3)分析dump 出来的trace 文件
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Undo Segment: _SYSSMU19$ ( 19)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Extent Control Header
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 15
last map 0x00000000 #maps: 0 offset: 4080
Highwater:: 0x01400103 ext#: 0 blk#: 2 ext size: 7
#blocks in seg. hdr's freelists: 0
#blocks below: 0
mapblk 0x00000000 offset: 0
Unlocked
Map Header:: next 0x00000000 #extents: 2 obj#: 0 flag: 0x40000000
Extent Map
-----------------------------------------------------------------
0x01400101 length: 7
0x01400108 length: 8
Retention Table
-----------------------------------------------------------
Extent Number:0 Commit Time: 0
Extent Number:1 Commit Time: 0
TRN CTL:: seq: 0x0001 chd: 0x0001 ctl: 0x0021 inc: 0x00000000 nfb: 0x0000
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x01400102.0001.01 scn: 0x0000.000e61e6
Version: 0x01
FREE BLOCK POOL::
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
TRN TBL::
index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
------------------------------------------------------------------------------------------------
0x00 10 0x80 0x0004 0x0000 0x0000.00000000 0x01400103 0x0000.000.00000000 0x00000002 0x00000000 0
0x01 9 0x00 0x0003 0x0002 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x02 9 0x00 0x0003 0x0003 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x03 9 0x00 0x0003 0x0004 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
.........省略trace 文件中后面的输出.............
可以看到dba的地址已经发生改变,指向最新使用的undo block地址,即datafile 5,block 259
Undo Segment: _SYSSMU19$ ( 19)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Extent Control Header
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 15
last map 0x00000000 #maps: 0 offset: 4080
Highwater:: 0x01400103 ext#: 0 blk#: 2 ext size: 7
#blocks in seg. hdr's freelists: 0
#blocks below: 0
mapblk 0x00000000 offset: 0
Unlocked
Map Header:: next 0x00000000 #extents: 2 obj#: 0 flag: 0x40000000
Extent Map
-----------------------------------------------------------------
0x01400101 length: 7
0x01400108 length: 8
Retention Table
-----------------------------------------------------------
Extent Number:0 Commit Time: 0
Extent Number:1 Commit Time: 0
TRN CTL:: seq: 0x0001 chd: 0x0001 ctl: 0x0021 inc: 0x00000000 nfb: 0x0000
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x01400102.0001.01 scn: 0x0000.000e61e6
Version: 0x01
FREE BLOCK POOL::
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
TRN TBL::
index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
------------------------------------------------------------------------------------------------
0x00 10 0x80 0x0004 0x0000 0x0000.00000000 0x01400103 0x0000.000.00000000 0x00000002 0x00000000 0
0x01 9 0x00 0x0003 0x0002 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x02 9 0x00 0x0003 0x0003 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
0x03 9 0x00 0x0003 0x0004 0x0000.000e61e6 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 0
.........省略trace 文件中后面的输出.............
可以看到dba的地址已经发生改变,指向最新使用的undo block地址,即datafile 5,block 259
(4)分析undo block trace
1.下面是undo block datafile 5 block 259的dump trace文件
UNDO BLK:
xid: 0x0013.000. 00000004 seq: 0x1 cnt: 0x14 irb: 0x14 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1f88 0x02 0x1f28 0x03 0x1ec8 0x04 0x1e68 0x05 0x1e08
0x06 0x1da8 0x07 0x1d48 0x08 0x1ce8 0x09 0x1c88 0x0a 0x1c28
0x0b 0x1bc8 0x0c 0x1b68 0x0d 0x1b08 0x0e 0x1aa8 0x0f 0x1a48
0x10 0x19e8 0x11 0x1988 0x12 0x1928 0x13 0x18c8 0x14 0x1868
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x1 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x00
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x01400102
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.52 - -当一个事务使用多个undo block时,事务使用的undo块顺序,是根据这个参数串联起来,即undo chain
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 201(0xc9) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x2 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x01
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400103.0001.01
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 205(0xcd) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.................省略一部分................
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x13 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x12
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400103. 0001. 12
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 239(0xef) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x14 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004) --这个对应irb参数:0x14,也对应ITL中的UBA第三个参数:undo record的开始地址。
* Layer: 11 ( Row) opc: 1 rci 0x13
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400103. 0001. 13
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 241(0xf1) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45 ---转化为字符,可以发现与我们更新的旧值相同。符合我们的语气
End dump data blocks tsn: 6 file#: 5 minblk 259 maxblk 259
UNDO BLK:
xid: 0x0013.000. 00000004 seq: 0x1 cnt: 0x14 irb: 0x14 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0x01 0x1f88 0x02 0x1f28 0x03 0x1ec8 0x04 0x1e68 0x05 0x1e08
0x06 0x1da8 0x07 0x1d48 0x08 0x1ce8 0x09 0x1c88 0x0a 0x1c28
0x0b 0x1bc8 0x0c 0x1b68 0x0d 0x1b08 0x0e 0x1aa8 0x0f 0x1a48
0x10 0x19e8 0x11 0x1988 0x12 0x1928 0x13 0x18c8 0x14 0x1868
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x1 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x00
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x01400102
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.52 - -当一个事务使用多个undo block时,事务使用的undo块顺序,是根据这个参数串联起来,即undo chain
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 201(0xc9) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x2 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x01
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400103.0001.01
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 205(0xcd) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.................省略一部分................
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x13 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x12
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400103. 0001. 12
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 239(0xef) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x14 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004) --这个对应irb参数:0x14,也对应ITL中的UBA第三个参数:undo record的开始地址。
* Layer: 11 ( Row) opc: 1 rci 0x13
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400103. 0001. 13
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 241(0xf1) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45 ---转化为字符,可以发现与我们更新的旧值相同。符合我们的语气
End dump data blocks tsn: 6 file#: 5 minblk 259 maxblk 259
2.下面是undo block datafile 5 block 258(事务使用的第一个undo block)的dump trace文件
我们可以看到如下内容(省略无用信息), 注意undo record中的uba参数
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x4 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x03
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.03
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ec hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 42(0x2a) flag: 0x2c lock: 0 ckix: 0
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x5 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x04
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
我们可以看到如下内容(省略无用信息), 注意undo record中的uba参数
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x4 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x03
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.03
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ec hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 42(0x2a) flag: 0x2c lock: 0 ckix: 0
ncol: 4 nnew: 1 size: 5
col 3: [ 9] 50 52 4f 43 45 44 55 52 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x5 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x04
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
Rec #0x5 记录时我们最后一个update语句使用的第一个undo记录,我们可以看到,该记录中并没有保存事务中上一条语句使用的uba,因此我们可以知道,undo record中的uba参数无法跨越语句,只能在单个语句中将undo记录串联起来
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x6 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x05
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.05
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 2(0x2) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Rec #0x6 slt: 0x00 objn: 73424(0x00011ed0) objd: 73424 tblspc: 4(0x00000004)
* Layer: 11 ( Row) opc: 1 rci 0x05
Undo type: Regular undo Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post - 11) padding: 1
op: C uba: 0x01400102.0001.05
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x010000ab hdba: 0x010000aa
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 2(0x2) flag: 0x2c lock: 0 ckix: 80
ncol: 4 nnew: 1 size: 1
col 3: [ 5] 54 41 42 4c 45
七、一些结论
- UNDO段头中TRN CTL的uba参数:UNDO段头的事务表中最后(最新)一个事务的对应的undo block上的第一个undo record,即当这个回滚段头存在多个事务时,这个uba表示最新的事务的uba地址,这个地址在整个事务的周期内不发生改变(除非这个回滚段头上又分配了一个新的事务表),因此,这个地址指向的是事务使用的第一个undo block;
- UNDO BLOCK中undo record记录中的uba参数:如果事务中的一个DML语句需要使用多个undo record,则这个参数指向的是前一个undo record的记录,通过这个参数可以形成同一个DML语句的undo chain tx table。但是一个事务中的不同DML语句,无法通过该参数连接起来(形成undo chain),因为该参数,不能跨越DML语句。当一个事务使用多个undo block时,事务使用的undo块顺序,是根据这个参数串联起来;
- 数据块头的ITL中的uba参数:指向事务在这个数据块上的变更(修改)所使用的undo块中的最后一个undo record偏移量地址,针对这个数据块修改,这个uba是回滚的起点;
- UNDO record中的bdba表示block address ,hdba表示 segment header address
- undo块中不会直接保存rowid信息,但是oracle完全可以undo record中几个信息(bdba,slot,objd),生成数据变更是的具体地址(rowid);
- 一个事务所使用的undo记录顺序是通过undo record中的uba参数、rci参数,undo块上的irb,itl中的uba共同起作用来串联变更的顺序,事务的回滚也是根据这个undo chain按顺序完成。其中最关键的两个参数:undo record中的uba 形成单个dml语句的undo chain,rci参数可以跨越DML语句,可以指向事务中前一个dml语句使用的undo record;
最后部分其实有几张原理图想要附上,供大家更清晰的了解,不过不知道怎么上传到博客,有需要的朋友直接给我留言吧