Oracle bbed Recovery Delete data instance _oracle

Source: Internet
Author: User
Tags bitmask commit dba

Recover deleted data
First, create the simulation environment

Copy Code code as follows:

Sql> CREATE TABLE Hr.xifenfei (ID number,name varchar2) tablespace xff;
Table created.
sql> INSERT INTO Hr.xifenfei values (1, ' Xifenfei ');
1 row created.
sql> INSERT INTO Hr.xifenfei values (2, ' xff ');
1 row created.
Sql> commit;
Commit complete.
Sql> select * from Hr.xifenfei;
ID NAME
———- ——————–
1 Xifenfei
2 Xff
Sql> Select rowID,
2 Dbms_rowid.rowid_relative_fno (ROWID) Rel_fno,
3 Dbms_rowid.rowid_block_number (ROWID) Blockno,
4 Dbms_rowid.rowid_row_number (ROWID) rowno
5 from Hr.xifenfei;
ROWID rel_fno Blockno Rowno
—————— ———- ———- ———-
AAAHY3AACAAAAISAAA 2 530 0
Aaahy3aacaaaaisaab 2 530 1
Query File#,block, back restore to use
Sql> Delete from Hr.xifenfei where id=2;
1 row deleted.
Sql> commit;
Commit complete.
Sql> select * from Hr.xifenfei;
ID NAME
———- ——————–
1 Xifenfei
sql> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

Second, bbed restore delete data
Copy Code code as follows:

[Oracle@localhost ~]$ bbed parfile=/tmp/parfile.cnf
Password:
Bbed:release 2.0.0.0.0–limited Production on Mon Aug 22 01:52:52 2011
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
************* !!! For Oracle Internal with only!!! ***************
Bbed> Show All
file# 2
block# 1
OFFSET 0
DBA 0x00800001 (8388609 2,1)
Filename/opt/oracle/oradata/xifenfei/xff01.dbf
Bifile BIFILE.BBD
Listfile/tmp/list
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBase Dec
Obase Dec
WIDTH 80
COUNT 512
LOGFILE LOG.BBD
SPOOL No
Bbed> Set DBA 2,530
DBA 0x00800212 (8389138 2,530)
Bbed> find/c Xff
File:/opt/oracle/oradata/xifenfei/xff01.dbf (2)
block:530 offsets:8170 to 8191 dba:0x00800212
————————————————————————
7866662c 000202c1 02087869 66656e66 65690106 80e2
<32 bytes per line>
Bbed> dump/v
File:/opt/oracle/oradata/xifenfei/xff01.dbf (2)
block:530 offsets:8170 to 8191 dba:0x00800212
——————————————————-
7866662c 000202c1 02087869 66656e66 l xff,...... xifenf
65690106 80e2 l ei ....
<16 bytes per line>
bbed> dump/v Offset 8160
File:/opt/oracle/oradata/xifenfei/xff01.dbf (2)
block:530 offsets:8160 to 8191 dba:0x00800212
——————————————————-
0000003c 020202c1 03037866 662c0002 L. <......xff,..
02c10208 78696665 6e666569 010680e2 l .... Xifenfei .....
<16 bytes per line>
bbed> dump/v Offset 8164
File:/opt/oracle/oradata/xifenfei/xff01.dbf (2)
block:530 offsets:8164 to 8191 dba:0x00800212
——————————————————-
020202C1 03037866 662c0002 02c10208 L. Xff,......
78696665 6e666569 010680e2 l Xifenfei ....
<16 bytes per line>
bbed> dump/v Offset 8162
File:/opt/oracle/oradata/xifenfei/xff01.dbf (2)
block:530 offsets:8162 to 8191 dba:0x00800212
——————————————————-
003c0202 02c10303 7866662c 000202c1 L. <......xff,....
02087869 66656e66 65690106 80e2 L.. Xifenfei .....
<16 bytes per line>
bbed> dump/v Offset 8163
File:/opt/oracle/oradata/xifenfei/xff01.dbf (2)
block:530 offsets:8163 to 8191 dba:0x00800212
——————————————————-
3c020202 c1030378 66662c00 0202c102 l <......xff,.....
08786966 656e6665 69010680 E2 L. Xifenfei .....
<16 bytes per line>
By trying to infer that the offset of 3c
Bbed> modify/x 2c
Warning:contents of previous bifile would be lost. Proceed? (y/n) Y
File:/opt/oracle/oradata/xifenfei/xff01.dbf (2)
block:530 offsets:8163 to 8191 dba:0x00800212
————————————————————————
2c020202 c1030378 66662c00 0202c102 08786966 656e6665 69010680 E2
<32 bytes per line>
Modify 3c to 2c
bbed> sum apply
Check value for File 2, block 530:
Current = 0xb1b9, required = 0xb1b9

iii. results of the reconciliation
Copy Code code as follows:

Sql> Startup
ORACLE instance started.
Total System Global area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database buffers 33554432 bytes
Redo buffers 667648 bytes
Database mounted.
Database opened.
Sql> select * from Hr.xifenfei;
ID NAME
———- ——————–
1 Xifenfei
2 Xff

Description
1 if the data is not deleted: The value of row flag is 32+8+4=44 or 0x2c
2 If the data is deleted: The value of row flag is 32+16+8+4=60 or 0x3c

Retrieve deleted data

Create mock table data
Copy Code code as follows:

Sql> CREATE TABLE T_xifenfei (ID number,name varchar2 (10));

Table created.

sql> INSERT INTO T_xifenfei values (1, ' Xifenfei ');

1 row created.

sql> INSERT INTO T_xifenfei values (2, ' Xifenfei ');

1 row created.

Sql> commit;

Commit complete.
Dump data block
Sql> alter system flush Buffer_cache;

System altered.

Sql> Select Rowid,id,name,
2 Dbms_rowid.rowid_relative_fno (ROWID) Rel_fno,
3 Dbms_rowid.rowid_block_number (ROWID) Blockno,
4 Dbms_rowid.rowid_row_number (ROWID) rowno
5 from Chf.t_xifenfei;

ROWID ID NAME rel_fno blockno rowno
------------------ ---------- ---------- ---------- ---------- ----------
AAASDMAAEAAAACVAAA 1 Xifenfei 4 175 0
Aaasdmaaeaaaacvaab 2 Xifenfei 4 175 1

sql> alter system dump DATAFILE 4 block 175;

System altered.
Dump file contents
Block_row_dump:
tab 0, row 0, @0x1f89
TL:15 FB:--h-fl--lb:0x1 Cc:2
Col 0: [2] C1 02
Col 1: [8] 6e 66 65 69
tab 0, row 1, @0x1f7a
TL:15 FB:--h-fl--lb:0x1 Cc:2
Col 0: [2] C1 03
Col 1: [8] 4e 46 45 49
End_of_block_dump
2012-05-01 05:09:29.287714:kjbmbassert [0XAF.4]
End dump data blocks Tsn:4 file#: 4 minblk 175 maxblk 175

Delete table Data
Copy Code code as follows:

Sql> Delete from T_xifenfei;

2 rows deleted.

Sql> commit;

Commit complete.

Sql> alter system flush Buffer_cache;

System altered.

sql> alter system dump DATAFILE 4 block 175;

System altered.
Dump file contents
Block_row_dump:
tab 0, row 0, @0x1f89
Tl:2 FB:--hdfl--lb:0x2
tab 0, row 1, @0x1f7a
Tl:2 FB:--hdfl--lb:0x2
End_of_block_dump
2012-05-01 05:13:35.214357:kjbmbassert [0XAF.4]
End dump data blocks Tsn:4 file#: 4 minblk 175 maxblk 175
By comparing these two dump files, we found
1. Data content is deleted, not really deleted, but to add an identity bit (FD:---D----)
2.fb:--h-fl--(head of row Piece+first data piece+last data piece)
It has 8 options for each option value corresponding to bitmask, 32+8+4=44 or 0x2c
3. If a row is removed, row flag is updated and the deleted in bitmask is set to 16.
At this point row flag is: 32+16+8+4 = or 0x3c.
4. If we want to retrieve the data to be deleted, we need to change the 3c to 2c.

Close Database
Copy Code code as follows:

Sql> select * from Chf.t_xifenfei;

No rows selected

Sql> select name from V$datafile where file#=4;

NAME
------------------------------------------------
/tmp/user01.dbf

sql> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
bbed Modify Data
bbed> set filename '/tmp/user01.dbf '
Filename/tmp/user01.dbf

Bbed> Set block 175
block# 175

Bbed> Set BlockSize 8192
BLOCKSIZE 8192

Bbed> Set Mode Edit
MODE Edit

Bbed> Map
File:/tmp/user01.dbf (0)
block:175 dba:0x00000000
------------------------------------------------------------
KTB Data block (table/cluster)

struct KCBH, Bytes @0

struct KTBBH, Bytes @20

struct KDBH, Bytes @100

struct kdbt[1], 4 bytes @114

SB2 Kdbr[2] @118

Ub1 freespace[8036] @122

Ub1 Rowdata[30] @8158

UB4 Tailchk @8188

Bbed> P *kdbr[0]
ROWDATA[15]
-----------
Ub1 rowdata[15] @8173 0x3c

Bbed> P *kdbr[1]
ROWDATA[0]
----------
Ub1 Rowdata[0] @8158 0x3c

Bbed> m/x 2c Offset 8158
File:/tmp/user01.dbf (0)
block:175 offsets:8158 to 8191 dba:0x00000000
------------------------------------------------------------------------
2c630202 c1030858 4946454e 46454932 630202c1 02087869 66656e66 65690106
b47e

<32 bytes per line>

Bbed> m/x 2c offset 8173
File:/tmp/user01.dbf (0)
block:175 offsets:8173 to 8191 dba:0x00000000
------------------------------------------------------------------------
2c630202 c1020878 6966656e 66656901 06b47e

<32 bytes per line>

bbed> sum apply
Check value for File 0, block 175:
Current = 0x4d13, required = 0x4d13

Start Database Validation
Copy Code code as follows:

Sql> Startup
ORACLE instance started.

Total System Global area 535662592 bytes
Fixed Size 1346140 bytes
Variable Size 411043236 bytes
Database buffers 117440512 bytes
Redo buffers 5832704 bytes
Database mounted.
Database opened.
Sql> select * from Chf.t_xifenfei;

ID NAME
---------- ----------
1 Xifenfei
2 Xifenfei

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.