標籤:
表中的資料被delete之後並不會真正刪除資料,而是打了一個刪除標記,僅僅要還沒有被覆蓋就能夠恢複回來。
實驗步驟例如以下:
[email protected]>create table bbed_test(x varchar2(20));
Table created.
[email protected]>insert into bbed_test values(‘BADLY9‘);
1 row created.
[email protected]>insert into bbed_test values(‘JP‘);
1 row created.
[email protected]>commit;
Commit complete.
[email protected]>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
[email protected]>alter system flush buffer_cache;
System altered.
[email protected]>alter system dump datafile 1 block 60290;
System altered.
[email protected]>oradebug setmypid
Statement processed.
[email protected]>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
以下我們刪除一行資料來看一下:
[email protected]>delete bbed_test where x=‘BADLY9‘;
1 row deleted.
[email protected]>commit;
Commit complete.
[email protected]>select * from bbed_test;
X
--------------------
JP
[email protected]> alter system flush buffer_cache;
System altered.
[email protected]>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
如今去庫裡查看一下
[email protected]>alter system flush buffer_cache;
System altered.
[email protected]>select * from bbed_test;
X
--------------------
BADLY9
JP
能夠看到被delete的資料已經恢複回來。
【Oracle】使用bbed恢複delete的資料