oracle中一個事務是如何使用redo的以及redo record和change vector的關係

warehouse發表於2013-01-27

oracle使用redo來恢復應該是以redo record為單位的

[@more@]

SQL> select * from tt;

ID NAME
---------- --------------------
1 a
2 b
3 c

SQL> update tt set name='e';

3 rows updated.

SQL> commit;

Commit complete.

SQL> alter system dump logfile 'E:ORACLEORADATATESTREDO04.LOG';

System altered.


SQL> select distinct sid from v$mystat;

SID
----------
7

SQL> select sid,serial#,process from v$session where sid=7;

SID SERIAL# PROCESS
---------- ---------- ------------------------------------------------
7 43 2360:4200

--================================
REDO RECORD - Thread:1 RBA: 0x000056.0000c741.0010 LEN: 0x0250 VLD: 0x05
SCN: 0x0000.0080d6cf SUBSCN: 1 01/27/2013 12:42:17
--================================
--這裡的change就是指change vectors,就是人們常說的改變向量,我這個例子裡
CHANGE #1就是在undo segment header block裡分配slot,slot號是slt: 0x001e
--================================
CHANGE #1 TYP:0 CLS:39 AFN:5 DBA:0x01400090 OBJ:4294967295 SCN:0x0000.0080d6bf SEQ:1 OP:5.2 ENC:0 RBL:0
ktudh redo: slt: 0x001e sqn: 0x00001620 flg: 0x0012 siz: 156 fbi: 0
uba: 0x014015fd.06e0.21 pxid: 0x0000.000.00000000
--================================
--change #2是undo block,用來保留修改前的資料a,a的ascii碼的16進位制數是61,從change #2的最下面
可以找到:col 1: [ 1] 61
--================================
CHANGE #2 TYP:0 CLS:40 AFN:5 DBA:0x014015fd OBJ:4294967295 SCN:0x0000.0080d6be SEQ:3 OP:5.1 ENC:0 RBL:0
ktudb redo: siz: 156 spc: 3458 flg: 0x0012 seq: 0x06e0 rec: 0x21
xid: 0x000c.01e.00001620
ktubl redo: slt: 30 rci: 0 opc: 11.1 [objn: 19949 objd: 19949 tsn: 4]
Undo type: Regular undo Begin trans Last buffer split: No
Temp Object: No
Tablespace Undo: No
0x00000000 prev ctl uba: 0x014015fd.06e0.1e
prev ctl max cmt scn: 0x0000.0080d08c prev tx cmt scn: 0x0000.0080d097
txn start scn: 0xffff.ffffffff logon user: 56 prev brb: 20977146 prev bcl: 0 BuExt idx: 0 flg2: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post-11) padding: 0
op: Z
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01000cf3 hdba: 0x01000cf2
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 0
ncol: 2 nnew: 1 size: 0
col 1: [ 1] 61
--===========================
change #3就是對資料庫block的修改了。
--===========================
CHANGE #3 TYP:0 CLS:1 AFN:4 DBA:0x01000cf3 OBJ:19949 SCN:0x0000.0080d6a6 SEQ:3 OP:11.5 ENC:0 RBL:0
KTB Redo
op: 0x01 ver: 0x01
compat bit: 4 (post-11) padding: 0
op: F xid: 0x000c.01e.00001620 uba: 0x014015fd.06e0.21
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01000cf3 hdba: 0x01000cf2
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) flag: 0x2c lock: 2 ckix: 0
ncol: 2 nnew: 1 size: 0
col 1: [ 1] 65
--===============================
change #4記錄的貌似是提交資訊以及發起這個事務的session以及client端的一些資訊。
--===============================
CHANGE #4 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ:0 OP:5.19 ENC:0
session number = 7
serial number = 43
current username = B
login username = B
client info =
OS username = LENOVO-382E0EF1Owner
Machine name = MSHOMELENOVO-382E0EF1
OS terminal = LENOVO-382E0EF1
OS process id = 2360:4200
OS program name = sqlplus.exe
transaction name =
version 186646784
audit sessionid 5892380
Client Id =
--=============================
下面這個REDO RECORD是對第二條資料修改記錄的redo資訊,只有2個change,
第一個change是undo block的資訊,第二個是data block的資訊
--=============================
REDO RECORD - Thread:1 RBA: 0x000056.0000c742.0070 LEN: 0x010c VLD: 0x01
SCN: 0x0000.0080d6cf SUBSCN: 2 01/27/2013 12:42:17
CHANGE #1 TYP:0 CLS:40 AFN:5 DBA:0x014015fd OBJ:4294967295 SCN:0x0000.0080d6cf SEQ:1 OP:5.1 ENC:0 RBL:0
ktudb redo: siz: 112 spc: 3300 flg: 0x0022 seq: 0x06e0 rec: 0x22
xid: 0x000c.01e.00001620
ktubu redo: slt: 30 rci: 33 opc: 11.1 objn: 19949 objd: 19949 tsn: 4
Undo type: Regular undo Undo type: Last buffer split: No
Tablespace Undo: No
0x00000000
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post-11) padding: 0
op: C uba: 0x014015fd.06e0.21
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01000cf3 hdba: 0x01000cf2
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 1(0x1) flag: 0x2c lock: 0 ckix: 0
ncol: 2 nnew: 1 size: 0
col 1: [ 1] 62
CHANGE #2 TYP:0 CLS:1 AFN:4 DBA:0x01000cf3 OBJ:19949 SCN:0x0000.0080d6cf SEQ:1 OP:11.5 ENC:0 RBL:0
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post-11) padding: 0
op: C uba: 0x014015fd.06e0.22
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01000cf3 hdba: 0x01000cf2
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 1(0x1) flag: 0x2c lock: 2 ckix: 0
ncol: 2 nnew: 1 size: 0
col 1: [ 1] 65
--=============================
下面這個REDO RECORD是對第三條資料修改記錄的redo資訊,只有2個change,
第一個change是undo block的資訊,第二個是data block的資訊
--=============================
REDO RECORD - Thread:1 RBA: 0x000056.0000c742.017c LEN: 0x010c VLD: 0x01
SCN: 0x0000.0080d6cf SUBSCN: 3 01/27/2013 12:42:17
CHANGE #1 TYP:0 CLS:40 AFN:5 DBA:0x014015fd OBJ:4294967295 SCN:0x0000.0080d6cf SEQ:2 OP:5.1 ENC:0 RBL:0
ktudb redo: siz: 112 spc: 3186 flg: 0x0022 seq: 0x06e0 rec: 0x23
xid: 0x000c.01e.00001620
ktubu redo: slt: 30 rci: 34 opc: 11.1 objn: 19949 objd: 19949 tsn: 4
Undo type: Regular undo Undo type: Last buffer split: No
Tablespace Undo: No
0x00000000
KDO undo record:
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post-11) padding: 0
op: C uba: 0x014015fd.06e0.22
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01000cf3 hdba: 0x01000cf2
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 2(0x2) flag: 0x2c lock: 0 ckix: 0
ncol: 2 nnew: 1 size: 0
col 1: [ 1] 63
CHANGE #2 TYP:0 CLS:1 AFN:4 DBA:0x01000cf3 OBJ:19949 SCN:0x0000.0080d6cf SEQ:2 OP:11.5 ENC:0 RBL:0
KTB Redo
op: 0x02 ver: 0x01
compat bit: 4 (post-11) padding: 0
op: C uba: 0x014015fd.06e0.23
KDO Op code: URP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01000cf3 hdba: 0x01000cf2
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 2(0x2) flag: 0x2c lock: 2 ckix: 0
ncol: 2 nnew: 1 size: 0
col 1: [ 1] 65

--================================
上面試驗我們能夠很清楚的知道修改一條資料oracle會產生一個REDO RECORD,那怕被
修改的資料是在同一個block上。一個REDO RECORD可能會包含若干個change vector,
這樣看來REDO RECORD是oarcle使用redo恢復時可用的最小單位了。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/19602/viewspace-1060161/,如需轉載,請註明出處,否則將追究法律責任。

相關文章