赞
踩
oracle的一个特点就是保存数据(这里数据包括任何对data block,undo block的修改)的时候以两种形式保存。一种是保存在数据文件里以数据块(data block)形式保存(最新数据也可能是存在oracle内存里的'脏块'--也是数据块--等待被刷新到数据文件中);另外一种以描述如何产生这些数据块的指令保存在重做日志文件里(最新的重做日志存在在oracle内存里等待刷新到重做日志文件中)。同时,oracle为了能够回滚事务,在修改数据之前都要保存一份数据的前镜像到undo文件里。完整的修改流程步骤如下:
这里就要涉及到data block, undo block和redo block三种块,我们具体看看内部结构。
准备表
alter system dump datafile 16 block min 99083 block max 99083 ;
dump结果(删掉暂不关注的部分)
*** 2012-04-22 10:56:00.893
Start dump data blocks tsn: 7 file#:16 minblk 99083 maxblk 99083
Block dump from cache:
Dump of buffer cache at level 4 for tsn=7, rdba=67207947
Block header dump: 0x0401830b
Object id on Block? Y
seg/obj: 0x17de0 csc: 0x8cf.a6277f02 itc: 2 flg: E typ: 1 - DATA typ:表示block type
brn: 0 bdba: 0x4018300 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc xid:undo_segment.undo_slot.undo_sequence, uba:undo record address, abosolute block address.block sequence number.record within block
0x01 0x000a.003.0000f3bb 0x00c00ae8.8c20.03 --U- 1 fsc 0x0000.a6277f03
0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
bdba: 0x0401830b
data_block_dump,data header at 0x2b9ab59d1a64
===============
tsiz: 0x1f98
hsiz: 0x14
pbl: 0x2b9ab59d1a64
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x1f2d
avsp=0x1f19
tosp=0x1f19
0xe:pti[0] nrow=1 ffs=0
0x12:pri[0] ffs=0x1f2d
block_row_dump:
tab 0, row 0, @0x1f2d
tl: 107 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 2] c1 02
col 1: [100]
78 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
end_of_block_dump
End dump data blocks tsn: 7 file#: 16 minblk 99083 maxblk 99083
tl: 107 fb: --H-FL-- lb: 0x1 cc: 2
数据行上的lb:0x1就指向该行在事务槽(itl)中的记录。
0x01 0x000a.003.0000f3bb 0x00c00ae8.8c20.03 --U- 1 fsc 0x0000.a6277f03
这个itl信息描述了该事务的状态(为U表示已经提交,但是没有做commit cleanout操作),以及该事务的XID(表示该事务在回滚段头的事务表中的位置信息,任何事务开始时必须申请在回滚段头的事务表transaction table中申请一个位置),以及该事务的最后一次undo record地址(用于快速回滚,比如说构建一致性读时要读取undo block)
开启一个事务,修改不提交
update t1 set v1=rpad('x',100) where id=1;
alter system checkpoint;
alter system dump datafile 16 block min 99083 block max 99083 ;
Start dump data blocks tsn: 7 file#:16 minblk 99083 maxblk 99083
Block dump from cache:
Dump of buffer cache at level 4 for tsn=7, rdba=67207947
Block header dump: 0x0401830b
Object id on Block? Y
seg/obj: 0x17de0 csc: 0x8cf.a6280065 itc: 2 flg: E typ: 1 - DATA
brn: 0 bdba: 0x4018300 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x000a.003.0000f3bb 0x00c00ae8.8c20.03 C--- 0 scn 0x08cf.a6277f03
0x02 0x0008.00c.0000d259 0x00c00c7f.810b.07 ---- 1 fsc 0x0062.00000000
bdba: 0x0401830b
data_block_dump,data header at 0x2ac9ae2d9a64
===============
tsiz: 0x1f98
hsiz: 0x14
pbl: 0x2ac9ae2d9a64
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x1f25
avsp=0x1f19
tosp=0x1f7b
0xe:pti[0] nrow=1 ffs=0
0x12:pri[0] ffs=0x1f25
block_row_dump:
tab 0, row 0, @0x1f25
tl: 8 fb: --H-FL-- lb: 0x2 cc: 2
col 0: [ 2] c1 02
col 1: [ 1] 79
end_of_block_dump
End dump data blocks tsn: 7 file#: 16 minblk 99083 maxblk 99083
Undo Segment Header
===================
Start dump data blocks tsn: 2 file#:3 minblk 240 maxblk 240
Block dump from cache:
Dump of buffer cache at level 4 for tsn=2, rdba=12583152
TRN CTL:: seq: 0x810c chd: 0x000e ctl: 0x0001 inc: 0x00000000 nfb: 0x0001
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x00c000f1.810c.07 scn: 0x08cf.a62808da
Version: 0x01
FREE BLOCK POOL::
uba: 0x00c000f1.810c.08 ext: 0x0 spc: 0x1cd6
uba: 0x00000000.810b.05 ext: 0x2 spc: 0x1428
uba: 0x00000000.810b.05 ext: 0x2 spc: 0xad8
uba: 0x00000000.5ec2.01 ext: 0x2 spc: 0x1f84
uba: 0x00000000.0000.00 ext: 0x0 spc: 0x0
TRN TBL::
index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
------------------------------------------------------------------------------------------------
0x00 9 0x00 0xd25c 0x000d 0x08cf.a6280b16 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076357
0x01 9 0x00 0xd25e 0xffff 0x08cf.a6280fdc 0x00c000f1 0x0000.000.00000000 0x00000001 0x00000000 1335076926
0x02 9 0x00 0xd25f 0x0001 0x08cf.a6280ea4 0x00c000f1 0x0000.000.00000000 0x00000001 0x00000000 1335076768
0x03 9 0x00 0xd1cb 0x0002 0x08cf.a6280ea0 0x00c000f1 0x0000.000.00000000 0x00000001 0x00000000 1335076764
0x04 9 0x00 0xd264 0x0016 0x08cf.a6280a38 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076237
0x05 9 0x00 0xd263 0x0018 0x08cf.a6280d77 0x00c00c7f 0x0000.000.00000000 0x00000001 0x00000000 1335076619
0x06 9 0x00 0xd267 0x0004 0x08cf.a62809d9 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076188
0x07 9 0x00 0xd265 0x000f 0x08cf.a6280ba5 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076418
0x08 9 0x00 0xd261 0x001b 0x08cf.a628099b 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 1335076177
0x09 9 0x00 0xd22c 0x0017 0x08cf.a6280c58 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076505
0x0a 9 0x00 0xd1f1 0x001a 0x08cf.a6280bd7 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076453
0x0b 9 0x00 0xd25a 0x0000 0x08cf.a6280a5b 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076240
0x0c 10 0x80 0xd259 0x0002 0x08cf.a6280e19 0x00c00c7f 0x0000.000.00000000 0x00000001 0x00000000 0
0x0d 9 0x00 0xd25c 0x0019 0x08cf.a6280b22 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076357
0x0e 9 0x00 0xd0c9 0x0015 0x08cf.a62808fa 0x00c00c7c 0x0000.000.00000000 0x00000002 0x00000000 1335076118
0x0f 9 0x00 0xd25a 0x001e 0x08cf.a6280bab 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076418
0x10 9 0x00 0xd262 0x001d 0x08cf.a6280b37 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076358
0x11 9 0x00 0xd256 0x0012 0x08cf.a6280de7 0x00c00c7f 0x0000.000.00000000 0x00000001 0x00000000 1335076666
0x12 9 0x00 0xd264 0x0003 0x08cf.a6280e21 0x00c000f1 0x0000.000.00000000 0x00000001 0x00000000 1335076712
0x13 9 0x00 0xd258 0x001f 0x08cf.a6280b58 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076366
0x14 9 0x00 0xd1ba 0x0011 0x08cf.a6280dcc 0x00c00c7f 0x0000.000.00000000 0x00000001 0x00000000 1335076658
0x15 9 0x00 0xd25b 0x0008 0x08cf.a628094c 0x00c00c7c 0x0000.000.00000000 0x00000001 0x00000000 1335076153
0x16 9 0x00 0xd1ec 0x000b 0x08cf.a6280a3a 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076237
0x17 9 0x00 0xd259 0x001c 0x08cf.a6280c74 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076528
0x18 9 0x00 0xd179 0x0014 0x08cf.a6280db2 0x00c00c7f 0x0000.000.00000000 0x00000001 0x00000000 1335076657
0x19 9 0x00 0xd252 0x0010 0x08cf.a6280b35 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076358
0x1a 9 0x00 0xd25a 0x0009 0x08cf.a6280c2a 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076486
0x1b 9 0x00 0xd260 0x0006 0x08cf.a62809ad 0x00c00c7d 0x0000.000.00000000 0x00000001 0x00000000 1335076186
0x1c 9 0x00 0xd25d 0x0020 0x08cf.a6280d33 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076598
0x1d 9 0x00 0xd25c 0x0013 0x08cf.a6280b3b 0x00c00c7e 0x0000.000.00000000 0x00000002 0x00000000 1335076358
0x1e 9 0x00 0xd25d 0x000a 0x08cf.a6280bd5 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076453
0x1f 9 0x00 0xd1f1 0x0007 0x08cf.a6280b5d 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076368
0x20 9 0x00 0xd1ee 0x0021 0x08cf.a6280d4a 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076608
0x21 9 0x00 0xd25d 0x0005 0x08cf.a6280d5f 0x00c00c7e 0x0000.000.00000000 0x00000001 0x00000000 1335076608
TRN CTL:: seq: 0x810c chd: 0x000e ctl: 0x0001 inc: 0x00000000 nfb: 0x0001
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x00c000f1.810c.07 scn: 0x08cf.a62808da
Transaction Control(TRN CTL::),记录了这个回滚段首的transaction table汇总信息。
seq:表示block sequence,每修改一次ctl,seq就递增一次。
chd:表示可用的slot链表中的第一个slot编号,也就是下一个被重用的slot编号。slot的使用顺序是总找一个最早的未使用的slot。
ctl:表示可用的slot链表的最后一个slot编号。
uba:当前在使用的slot最近修改的事务的第一个undo record address。这个uba对应的undo record里保存了之前的trn ctl信息(包括之前的uba信息),所以transaction control的历史信息是通过这个uba信息去回溯的,这点不同于data block的回滚。
scn:最近一个被重用的slot的事务提交时的scn信息,也即是这个transaction table里直接记录的所有已提交的事务中最早的scn。
Transaction Table(TRN TBL::),记录了这个回滚段首的transaction table详细信息。每行记录称为一个slot,index是slot的编号,可以重用state=9的slot。wrap#表示重用次数。
index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
------------------------------------------------------------------------------------------------
0x0c 10 0x80 0xd259 0x0002 0x08cf.a6280e19 0x00c00c7f 0x0000.000.00000000 0x00000001 0x00000000 0
index:slot编号
state:表示这行记录的状态:9,不活动;10,活动
cflags:表示这行记录上的事务状态:0x0,无事务;0x20,事务死掉;0x80,活动事务;0x90,事务已死,正在回滚
wrap#:slot重用次数
uel:slot链表中的下一个slot编号,活动的事务slot在一个链表中,不活动的事务slot在一个链表中
scn:表示该slot事务最后一次修改对应的scn信息
dba:表示该slot事务最后一次修改对应的undo 记录地址。回滚事务的时候从这个dba开始。
nub:这个事务使用的undo block数量。如果正在回滚,这个数量会递减。
cmt:最近的提交时间,精确到秒,是个差值,自1970年1月1日midnight(UTC)
********************************************************************************
Undo Segment: _SYSSMU8_625026625$ (8)
xid: 0x0008.00c.0000d259
Low Blk : (0, 0)
High Blk : (2, 127)
Object Id : ALL
Layer : ALL
Opcode : ALL
Level : 2
********************************************************************************
UNDO BLK: Extent: 2 Block: 127 dba (file#, block#): 3,0x00000c7f
xid: 0x0008.00c.0000d259 seq: 0x810b cnt: 0x7 irb: 0x7 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
---------------------------------------------------------------------------
0x01 0x1f98 0x02 0x1f2c 0x03 0x1e8c 0x04 0x1dc8 0x05 0x1d78
0x06 0x1d0c 0x07 0x1bfc
*-----------------------------
* Rec #0x7 slt: 0x0c objn: 97760(0x00017de0) objd: 97760 tblspc: 7(0x00000007)
* 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: 0x00c00c7f.810b.05 ctl max scn: 0x08cf.a6280806 prv tx scn: 0x08cf.a628082d
txn start scn: scn: 0x08cf.a6280e19 logon user: 92
prev brb: 12586107 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: 0x0401830b hdba: 0x04018303
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 0
ncol: 2 nnew: 1 size: 99
col 1: [100]
78 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
注:
alter system dump logfile'/u01/arch/lp4pldev/1_89486_758821170.dbf' dba min 16 99083 dba max 16 99083 ;
*** 2012-04-22 17:17:56.358
Initial buffer sizes: read 1024K, overflow 832K, change 805K
Log read is SYNCHRONOUS though disk_asynch_io is enabled!
DUMP OF REDO FROM FILE '/u01/arch/lp4pldev/1_89486_758821170.dbf'
Opcodes *.*
......
REDO RECORD - Thread:1 RBA: 0x015d8e.000000bc.0010 LEN: 0x0268 VLD: 0x05
SCN: 0x08cf.a6280e19 SUBSCN: 1 04/22/2012 14:38:25
(LWN RBA: 0x015d8e.000000bc.0010 LEN: 0002 NST: 04d SCN: 0x08cf.a6280e18)
CHANGE #1 TYP:0 CLS:31 AFN:3 DBA:0x00c000f0 OBJ:4294967295 SCN:0x08cf.a6280de7 SEQ:1 OP:5.2 ENC:0 RBL:0
ktudh redo: slt: 0x000c sqn: 0x0000d259 flg: 0x0012 siz: 272 fbi: 0
uba: 0x00c00c7f.810b.07 pxid: 0x0000.000.00000000
CHANGE #2 TYP:0 CLS:32 AFN:3 DBA:0x00c00c7f OBJ:4294967295 SCN:0x08cf.a6280de6 SEQ:2 OP:5.1 ENC:0 RBL:0
ktudb redo: siz: 272 spc: 7406 flg: 0x0012 seq: 0x810b rec: 0x07
xid: 0x0008.00c.0000d259
ktubl redo: slt: 12 rci: 0 opc: 11.1 [objn: 97760 objd: 97760 tsn: 7]
Undo type: Regular undo Begin trans Last buffer split: No
Temp Object: No
Tablespace Undo: No
0x00000000 prev ctl uba: 0x00c00c7f.810b.05
prev ctl max cmt scn: 0x08cf.a6280806 prev tx cmt scn: 0x08cf.a628082d
txn start scn: 0xffff.ffffffff logon user: 92 prev brb: 12586107 prev bcl: 0 BuExt idx: 0 flg2: 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: 0x0401830b hdba: 0x04018303
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 0
ncol: 2 nnew: 1 size: 99
col 1: [100]
78 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
CHANGE #3 TYP:0 CLS:1 AFN:16 DBA:0x0401830b OBJ:97760 SCN:0x08cf.a6280ce6 SEQ:2 OP:11.5 ENC:0 RBL:0
KTB Redo
op: 0x01 ver: 0x01
compat bit: 4 (post-11) padding: 1
op: F xid: 0x0008.00c.0000d259 uba: 0x00c00c7f.810b.07
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x0401830b hdba: 0x04018303
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 2 ckix: 0
ncol: 2 nnew: 1 size: -99
col 1: [ 1] 79
CHANGE #4 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ:0 OP:5.20 ENC:0
session number = 1155
serial number = 65179
transaction name =
version 186647040
audit sessionid 6686373
Client Id =
login username = B2BDBA
REDO RECORD - Thread:1 RBA: 0x015d8e.00000161.0010 LEN: 0x0070 VLD: 0x06
SCN: 0x08cf.a6280e97 SUBSCN: 1 04/22/2012 14:39:15
(LWN RBA: 0x015d8e.00000161.0010 LEN: 0001 NST: 04d SCN: 0x08cf.a6280e96)
CHANGE #1 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ:0 OP:23.1 ENC:0
Block Written - afn: 16 rdba: 0x0401830b BFT:(1024,67207947) non-BFT:(16,99083)
scn: 0x08cf.a6280e19 seq: 0x01 flg:0x04
END OF REDO DUMP
----- Redo read statistics for thread 1 -----
Read rate (SYNC): 345Kb in 0.01s => 33.69 Mb/sec
Total redo bytes: 345Kb Longest record: 0Kb, moves: 0/505 moved: 0Mb (0%)
Longest LWN: 6Kb, reads: 411
Last redo scn: 0x08cf.a6280fcd (9687938895821)
Change vector header moves = 68/1156 (5%)
----------------------------------------------
注:
REDO RECORD - Thread:1 RBA: 0x015d8e.000000bc.0010 LEN: 0x0268 VLD: 0x05
SCN: 0x08cf.a6280e19 SUBSCN: 1 04/22/2012 14:38:25
(LWN RBA: 0x015d8e.000000bc.0010 LEN: 0002 NST: 04d SCN: 0x08cf.a6280e18)
RBA:Redo Byte Address, 10 bytes,由log sequence number, block number within redo log, byte number within block
CHANGE #1 TYP:0 CLS:31 AFN:3 DBA:0x00c000f0 OBJ:4294967295 SCN:0x08cf.a6280de7 SEQ:1 OP:5.2 ENC:0 RBL:0
ktudh redo: slt: 0x000c sqn: 0x0000d259 flg: 0x0012 siz: 272 fbi: 0
uba: 0x00c00c7f.810b.07 pxid: 0x0000.000.00000000
change vector:描述data block的变化(包括data blocks,undo block,undo segment header)
TYP:change type
CLS:change class:1,data block; 31,segment header for undo segment header; 32,data blocks for undo segment
AFN:absolute file number
DBA:Relative Database Block Address
OP:operation code:4,block cleanout; 5,transaction management; 10,index operations; 11 row operations
5.2 update transaction table in undo segment header
CHANGE #3 TYP:0 CLS:1 AFN:16 DBA:0x0401830b OBJ:97760 SCN:0x08cf.a6280ce6 SEQ:2 OP:11.5 ENC:0 RBL:0
KTB Redo
op: 0x01 ver: 0x01
compat bit: 4 (post-11) padding: 1
op: F xid: 0x0008.00c.0000d259 uba: 0x00c00c7f.810b.07
KDO Op code: URP row dependencies Disabled
11.5 URP update row
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9253450/viewspace-721983/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9253450/viewspace-721983/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。