06 使用bbed修复delete的数据--01
根据rowid查看数据文件和block号
SYS@ orcl >select rowid,id,name,DBMS_ROWID.ROWID_RELATIVE_FNO(rowid) file#,DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid) block# from test.t1 where id=1; ROWID ID NAME FILE# BLOCK# ------------------ ---------- -------------------------------------------------- ---------- ---------- AAAVVFAAFAAAAiOAAA 1 AAAAA 5 2190
使用dump命令查看
SYS@ orcl >alter system dump datafile 5 block 2190; System altered. SYS@ orcl >select * from v$diag_info; [root@DSI ~]# more /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_3081.trc *** 2019-05-27 15:48:20.883 *** SESSION ID:(125.5) 2019-05-27 15:48:20.883 *** CLIENT ID:() 2019-05-27 15:48:20.883 *** SERVICE NAME:(SYS$USERS) 2019-05-27 15:48:20.883 *** MODULE NAME:(sqlplus@DSI (TNS V1-V3)) 2019-05-27 15:48:20.883 *** ACTION NAME:() 2019-05-27 15:48:20.883 kwqmnich: current time:: 7: 48: 20: 0 kwqmnich: instance no 0 repartition flag 1 kwqmnich: initialized job cache structure Start dump data blocks tsn: 5 file#:5 minblk 2190 maxblk 2190 *** 2019-05-29 16:15:55.111 Block dump from cache: Dump of buffer cache at level 4 for tsn=5 rdba=20973710 BH (0x7e7dcdc8) file#: 5 rdba: 0x0140088e (5/2190) class: 1 ba: 0x7e4b6000 set: 5 pool: 3 bsz: 8192 bsi: 0 sflg: 1 pwc: 70,28 dbwrid: 0 obj: 87365 objn: 87365 tsn: 5 afn: 5 hint: f hash: [0x8d5a4700,0x8d5a4700] lru: [0x7e7dcd80,0x7f7dcc48] ckptq: [NULL] fileq: [NULL] objq: [0x7e7dcda8,0x885b38e0] objaq: [0x7e7dcdb8,0x885b38d0] st: XCURRENT md: NULL fpin: 'kdswh01: kdstgr' tch: 4 flags: only_sequential_access LRBA: [0x0.0.0] LSCN: [0x0.0] HSCN: [0xffff.ffffffff] HSUB: [65535] Block dump from disk: buffer tsn: 5 rdba: 0x0140088e (5/2190) scn: 0x0000.008dcadb seq: 0x02 flg: 0x06 tail: 0xcadb0602 frmt: 0x02 chkval: 0x5956 type: 0x06=trans data Hex dump of block: st=0, typ_found=1 Dump of memory from 0x00007FC3EFE12200 to 0x00007FC3EFE14200 7FC3EFE12200 0000A206 0140088E 008DCADB 06020000 [......@.........] 7FC3EFE12210 00005956 00000001 00015545 008DCAC7 [VY......EU......] 7FC3EFE12220 00000000 00320002 01400888 000D0001 [......2...@.....] 7FC3EFE12230 000043A9 00C001B0 0029010D 00002001 [.C........).. ..] 7FC3EFE12240 008DCAC8 001B0004 000043A8 00C1973B [.........C..;...] 7FC3EFE12250 00340115 00002001 008DCADB 00000000 [..4.. ..........] 7FC3EFE12260 00000000 00020100 0016FFFF 1F5A1F70 [............p.Z.] 7FC3EFE12270 00001F5A 1F840002 00001F70 00000000 [Z.......p.......] 7FC3EFE12280 00000000 00000000 00000000 00000000 [................] Repeat 500 times 7FC3EFE141D0 00000000 0203022C 620503C1 62626262 [....,......bbbbb] 7FC3EFE141E0 05777807 1B1C0F16 0203012C 410502C1 [.xw.....,......A] 7FC3EFE141F0 41414141 05777807 291B0F16 CADB0602 [AAAA.xw....)....] Block header dump: 0x0140088e Object id on Block? Y seg/obj: 0x15545 csc: 0x00.8dcac7 itc: 2 flg: E typ: 1 - DATA brn: 0 bdba: 0x1400888 ver: 0x01 opc: 0 inc: 0 exflg: 0 Itl Xid Uba Flag Lck Scn/Fsc 0x01 0x0001.00d.000043a9 0x00c001b0.010d.29 --U- 1 fsc 0x0000.008dcac8 0x02 0x0004.01b.000043a8 0x00c1973b.0115.34 --U- 1 fsc 0x0000.008dcadb bdba: 0x0140088e data_block_dump,data header at 0x7fc3efe12264 =============== tsiz: 0x1f98 hsiz: 0x16 pbl: 0x7fc3efe12264 76543210 flag=-------- ntab=1 nrow=2 frre=-1 fsbo=0x16 fseo=0x1f70 avsp=0x1f5a tosp=0x1f5a 0xe:pti[0] nrow=2 offs=0 0x12:pri[0] offs=0x1f84 0x14:pri[1] offs=0x1f70 block_row_dump: tab 0, row 0, @0x1f84 ##具体的数据 tl: 20 fb: --H-FL-- lb: 0x1 cc: 3 col 0: [ 2] c1 02 col 1: [ 5] 41 41 41 41 41 col 2: [ 7] 78 77 05 16 0f 1b 29 tab 0, row 1, @0x1f70 tl: 20 fb: --H-FL-- lb: 0x2 cc: 3
使用bbed进行查看
BBED> set file 5 block 2190 FILE# 5 BLOCK# 2190 BBED> map /v BBED> p ktbbh BBED> p kdbh struct kdbh, 14 bytes @100 ub1 kdbhflag @100 0x00 (NONE) sb1 kdbhntab @101 1 sb2 kdbhnrow @102 2 sb2 kdbhfrre @104 -1 sb2 kdbhfsbo @106 22 sb2 kdbhfseo @108 8048 sb2 kdbhavsp @110 8026 sb2 kdbhtosp @112 8026 BBED> p kdbr sb2 kdbr[0] @118 8068 sb2 kdbr[1] @120 8048 BBED> p *kdbr[0] rowdata[20] ----------- ub1 rowdata[20] @8168 0x2c BBED> x/rnccccc ##对应行的值 rowdata[20] @8168 ----------- flag@8168: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8169: 0x01 cols@8170: 3 col 0[2] @8171: 1 col 1[5] @8174: AAAAA col 2[7] @8180: xw....) SYS@ orcl >select dump(1,'16') from dual; DUMP(1,'16') ----------------- Typ=2 Len=2: c1,2 SYS@ orcl >select dump('AAAAA','16') from dual; DUMP('AAAAA','16') ---------------------------- Typ=96 Len=5: 41,41,41,41,41
表记录
SYS@ orcl >select * from test.t1; ID NAME DATE1 ---------- -------------------------------------------------- --------- 1 AAAAA 22-MAY-19 2 bbbbb 22-MAY-19 3 tt 23-MAY-19
Insert 一条记录,没提交事务,会写入DataBlock?
TEST@ orcl >create table t2 (id number ,name varchar2(20)); TEST@ orcl >insert into t2 values(1,'aaa'); TEST@ orcl >select rowid,id,name,DBMS_ROWID.ROWID_RELATIVE_FNO(rowid) file#,DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid) block# from test.t2; ROWID ID NAME FILE# BLOCK# ------------------ ---------- -------------------------------------------------- ---------- ---------- AAAVWKAAFAAAAiXAAA 1 aaa 5 2199 [oracle@DSI ~]$ sqlplus test/test SQL> alter system flush buffer_cache; System altered. SQL> select rowid,id,name,DBMS_ROWID.ROWID_RELATIVE_FNO(rowid) file#,DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid) block# from test.t2; no rows selected SQL> alter system dump datafile 5 block 2199; System altered. SQL> select * from v$diag_info;
dump查看
[oracle@DSI ~]$ more /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_13566.trc 7F08FBDDA9D0 027C5507 C1020004 02800113 C20302C1 [.U|.............] 7F08FBDDA9E0 00AC2005 04000402 71410000 000000DB [. ........Aq....] 7F08FBDDA9F0 012C7141 02C10202 61616103 72060603 [Aq,......aaa...r] Block header dump: 0x01400897 Object id on Block? Y seg/obj: 0x1558a csc: 0x00.917206 itc: 2 flg: E typ: 1 - DATA brn: 0 bdba: 0x1400890 ver: 0x01 opc: 0 inc: 0 exflg: 0 Itl Xid Uba Flag Lck Scn/Fsc 0x01 0x0008.00b.00007877 0x00c00389.016c.15 ---- 1 fsc 0x0000.00000000 ##对应的记录没有提交Flag=0 0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000 bdba: 0x01400897 data_block_dump,data header at 0x7f08fbdd8a64 =============== tsiz: 0x1f98 hsiz: 0x14 pbl: 0x7f08fbdd8a64 76543210 flag=-------- ntab=1 nrow=1 frre=-1 fsbo=0x14 fseo=0x1f8e avsp=0x1f7a tosp=0x1f7a 0xe:pti[0] nrow=1 offs=0 0x12:pri[0] offs=0x1f8e block_row_dump: tab 0, row 0, @0x1f8e tl: 10 fb: --H-FL-- lb: 0x1 cc: 2 ##0x1代表在那个事务槽 col 0: [ 2] c1 02 col 1: [ 3] 61 61 61 end_of_block_dump End dump data blocks tsn: 5 file#: 5 minblk 2199 maxblk 2199 从dump上面看数据已经写入了block
bbed查看
BBED> set file 5 block 2199 BBED> p ktbbh ub2 ktbitflg @60 0x0001 (NONE) ##01代表锁了1行记录,00表示没有提交 BBED> dump File: /u01/app/oracle/oradata/orcl/test01.dbf (5) Block: 2199 Offsets: 0 to 8191 Dba:0x01400897 ------------------------------------------------------------------------ 06a20000 97084001 06729100 00000304 0ed50000 01000000 8a550100 06729100 00000000 02003200 90084001 08000b00 77780000 8903c000 6c011500 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00010100 ffff1400 8e1f7a1f 7a1f0000 01008e1f e61b0500 06000700 .. 05207c02 040002c1 13018002 c10303c2 024a7c02 040002c1 13018002 c10a03c2 07567c02 040002c1 13018002 c10503c2 07557c02 040002c1 13018002 c10303c2 05207c02 040002c1 13018002 c10203c2 024a7c02 040002c1 13018002 c10a03c2 07567c02 040002c1 13018002 c10403c2 07557c02 040002c1 13018002 c10203c2 0520ac00 02040004 00004171 db000000 41712c01 0202c102 03616161 03060672 ##尾部校验 BBED> dump /v offset 8000 count 200 File: /u01/app/oracle/oradata/orcl/test01.dbf (5) Block: 2199 Offsets: 8000 to 8191 Dba:0x01400897 flg= 0x800 /*transaction is commited*/ 0x2000 /* commit time is upper bound*/ 0x1000 /* this trac is actice as of ktbbhcsc*/
使用BBED手工修复DELETE数据
TEST@ orcl >select * from t2; ID NAME ---------- -------------------------------------------------- 1 aaa 2 bbbbb 3 ccccc TEST@ orcl >alter system flush buffer_cache; TEST@ orcl >select rowid,id,name,DBMS_ROWID.ROWID_RELATIVE_FNO(rowid) file#,DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid) block# from test.t2; ROWID ID NAME FILE# BLOCK# ------------------ ---------- -------------------------------------------------- ---------- ---------- AAAVWKAAFAAAAiXAAA 1 aaa 5 2199 AAAVWKAAFAAAAiXAAB 2 bbbbb 5 2199 AAAVWKAAFAAAAiXAAC 3 ccccc 5 2199
在bbed查看是否提交,也可以使用dump命令进行查看
BBED> set file 5 block 2199 FILE# 5 BLOCK# 2199 BBED> map /v File: /u01/app/oracle/oradata/orcl/test01.dbf (5) Block: 2199 Dba:0x01400897 ------------------------------------------------------------ KTB Data Block (Table/Cluster) struct kdbh, 14 bytes @100 ub1 kdbhflag @100 BBED> p ktbbhitl ub2 ktbitflg @60 0x2001 (KTBFUPB) BBED> p kdbr sb2 kdbr[0] @118 8078 sb2 kdbr[1] @120 8066 sb2 kdbr[2] @122 8054 BBED> p *kdbr[0] rowdata[24] ----------- ub1 rowdata[24] @8178 0x2c ##位置在相对位置加了100 ---8078+100(Assm),如果Mssm是加92 BBED> x/rncccccc rowdata[24] @8178 ----------- flag@8178: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8179: 0x01 cols@8180: 2 ##2个列 col 0[2] @8181: 1 col 1[3] @8184: aaa
删除测试
TEST@ orcl >delete from t2 where id=3; 1 row deleted. TEST@ orcl >commit; Commit complete. TEST@ orcl >alter system flush buffer_cache; System altered. bbed重新登录一次 BBED> exit BBED> p kdbr sb2 kdbr[0] @118 8078 sb2 kdbr[1] @120 8066 sb2 kdbr[2] @122 8054 BBED> p *kdbr[2] rowdata[0] ---------- ub1 rowdata[0] @8154 0x3c ##标记是3c,表示已经被删除 BBED> x/rncccccc rowdata[0] @8154 ##相对位置加100 ---------- flag@8154: 0x3c (KDRHFL, KDRHFF, KDRHFD, KDRHFH) lock@8155: 0x01 cols@8156: 0 TEST@ orcl >select * from t2; ID NAME ---------- -------------------------------------------------- 1 aaa 2 bbbbb 这里把3c修改成2c BBED> modify /x 2c offset 8154 ##注意这里的位置是8154,而不是8054 File: /u01/app/oracle/oradata/orcl/test01.dbf (5) Block: 2199 Offsets: 8154 to 8191 Dba:0x01400897 ------------------------------------------------------------------------ 2c010202 c1040563 63636363 2c000202 c1030562 62626262 2c000202 c1020361 61610106 6b77 <32 bytes per line> BBED> sum apply Check value for File 5, Block 2199: current = 0xf7f4, required = 0xf7f4
刷新一次,被删除的记录找到 TEST@ orcl >alter system flush buffer_cache; System altered. TEST@ orcl >select * from t2; ID NAME ---------- -------------------------------------------------- 1 aaa 2 bbbbb 3 ccccc
下一篇介绍使用bbed进行update数据的测试和恢复