表中的数据被delete之后并不会真正删除数据,而是打了一个删除标记,仅仅要还没有被覆盖就能够恢复回来。
实验步骤例如以下:
SYS@ORCL>create table bbed_test(x varchar2(20));
Table created.
SYS@ORCL>insert into bbed_test values('BADLY9');
1 row created.
SYS@ORCL>insert into bbed_test values('JP');
1 row created.
SYS@ORCL>commit;
Commit complete.
SYS@ORCL>select rowid, dbms_rowid.rowid_relative_fno(rowid)rel_fno,
2 dbms_rowid.rowid_block_number(rowid)blockno,
3 dbms_rowid.rowid_row_number(rowid) rowno
4 from bbed_test;
ROWID REL_FNO BLOCKNO ROWNO
------------------ ---------- ---------- ----------
AAAM0VAABAAAOuCAAA 1 60290 0
AAAM0VAABAAAOuCAAB 1 60290 1
SYS@ORCL>alter system flush buffer_cache;
System altered.
SYS@ORCL>alter system dump datafile 1 block 60290;
System altered.
SYS@ORCL>oradebug setmypid
Statement processed.
SYS@ORCL>oradebug tracefile_name
/u01/app/oracle/admin/ORCL/udump/orcl_ora_18509.trc
查看dump文件
block_row_dump:
tab 0, row 0, @0x1f96
tl: 10 fb: --H-FL-- lb: 0x1 cc: 1
col 0: [ 6] 42 41 44 4c 59 39
tab 0, row 1, @0x1f90
tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
col 0: [ 2] 4a 50
end_of_block_dump
红色标记的位置记录了该行数据的状态:
没有被删除的话是--H-FL--,其相应的值为0x2c
已经被删除的话是--HDFL--,其相应的值为0x3c
以下我们删除一行数据来看一下:
SYS@ORCL>delete bbed_test where x='BADLY9';
1 row deleted.
SYS@ORCL>commit;
Commit complete.
SYS@ORCL>select * from bbed_test;
X
--------------------
JP
SYS@ORCL> alter system flush buffer_cache;
System altered.
SYS@ORCL>alter system dump datafile 1 block 60290;
System altered.
查看dump文件
block_row_dump:
tab 0, row 0, @0x1f96
tl: 2 fb: --HDFL-- lb: 0x2
tab 0, row 1, @0x1f90
tl: 6 fb: --H-FL-- lb: 0x0 cc: 1
col 0: [ 2] 4a 50
end_of_block_dump
能够看到此时row 0的数据已经被标记为删除。
以下使用bbed工具将该条数据恢复回来:
BBED> set dba 1,60290
DBA 0x0040eb82 (4254594 1,60290)
BBED> f /c BADLY9
File: /u01/app/oracle/oradata/ORCL/system01.dbf (1)
Block: 60290 Offsets: 8182 to 8191 Dba:0x0040eb82
------------------------------------------------------------------------
4241444c 59390206 1e62
<32 bytes per line>
BBED> p *kdbr
rowdata[6]
----------
ub1 rowdata[6] @8178 0x3c
BBED> set offset 8178
OFFSET 8178
BBED> m /x 2c
File: /u01/app/oracle/oradata/ORCL/system01.dbf (1)
Block: 60290 Offsets: 8178 to 8191 Dba:0x0040eb82
------------------------------------------------------------------------
2c020106 4241444c 59390206 1e62
<32 bytes per line>
BBED> sum apply
Check value for File 1, Block 60290:
current = 0xc7d4, required = 0xc7d4
如今去库里查看一下
SYS@ORCL>alter system flush buffer_cache;
System altered.
SYS@ORCL>select * from bbed_test;
X
--------------------
BADLY9
JP
能够看到被delete的数据已经恢复回来。