实验1:利用BBED工具恢复删除的数据行

       当我们误删除数据行,UNDO已经被覆盖,数据量少的话可以考虑使用BBED恢复删除的数据行。

SQL> create table perry(id number,name varchar2(10)) tablespace perry;

SQL> insert into perry  values (1111,'aaaa') ;

已创建 1 行。

SQL> insert into perry  values (2222,'bbbb') ;

已创建 1 行。

SQL> insert into perry  values (3333,'cccc') ;

已创建 1 行。

SQL> commit;

提交完成。

SQL> alter system flush buffer_cache;   --让插入的数据写入数据文件。

系统已更改。

SQL>  select dbms_rowid.rowid_object(rowid) object_id,
  2     dbms_rowid.rowid_relative_fno(rowid) file_id,

  3     dbms_rowid.rowid_block_number(rowid) block_id,

  4     dbms_rowid.rowid_row_number(rowid) num

  5     from perry;

 OBJECT_ID    FILE_ID   BLOCK_ID        NUM
---------- ---------- ---------- ----------
     52508          6         16          0
     52508          6         16          1
     52508          6         16          2


SQL> select * from perry ;


        ID NAME
---------- ----------
      1111 aaaa
      2222 bbbb
      3333 cccc

SQL> delete from perry where id=2222;   --删除一行数据,下面就是来恢复这行数据。

已删除 1 行。

SQL> alter system flush buffer_cache;

系统已更改。

SQL> select dbms_rowid.rowid_object(rowid) object_id,
  2     dbms_rowid.rowid_relative_fno(rowid) file_id,

  3     dbms_rowid.rowid_block_number(rowid) block_id,

  4     dbms_rowid.rowid_row_number(rowid) num

  5     from perry;

 OBJECT_ID    FILE_ID   BLOCK_ID        NUM
---------- ---------- ---------- ----------
     52508          6         16          0
     52508          6         16          2

登陆BBED

[oracle@test ~]$ bbed parfile=/opt/bbed/bbed.par  
Password: 

BBED: Release 2.0.0.0.0 - Limited Production on Fri Aug 22 11:04:20 2014

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED> set dba 6,16

 DBA             0x01800010 (25165840 6,16)

BBED> p kdbr --可以看到3行数据,我们删除的那行数据还在,看来并未从数据文件真正删除!
sb2 kdbr[0]                                 @118      8076
sb2 kdbr[1]                                 @120      8064
sb2 kdbr[2]                                 @122      8052


BBED> p rowdata --表perry存储3行记录占用了36个字节。

ub1 rowdata[0]                              @8152     0x2c --FLAG行标记:HFL(44or0x2c)代表正常记录,HDFL(60or0x3c)代表删除了该记录。
ub1 rowdata[1]                              @8153     0x00 --0号事务槽
ub1 rowdata[2]                              @8154     0x02 --表字段的个数
ub1 rowdata[3]                              @8155     0x03 --id字段占用的字节数,是表第三条记录,oracle数据行从块底向上插入。
ub1 rowdata[4]                              @8156     0xc2 
ub1 rowdata[5]                              @8157     0x22
ub1 rowdata[6]                              @8158     0x22   --从8156至8158是ID字段内容


SQL> select dump(3333,16) from dual ;

DUMP(3333,16)
---------------------
Typ=2 Len=3: c2,22,22

ub1 rowdata[7]                              @8159     0x04 --name字段占用字节数
ub1 rowdata[8]                              @8160     0x63 
ub1 rowdata[9]                              @8161     0x63
ub1 rowdata[10]                             @8162     0x63
ub1 rowdata[11]                             @8163     0x63 --从8160至8163是name字段内容


ub1 rowdata[12]                             @8164     0x3c --此处就是删除的第二条记录,offset=8164
ub1 rowdata[13]                             @8165     0x02
ub1 rowdata[14]                             @8166     0x02
ub1 rowdata[15]                             @8167     0x03
ub1 rowdata[16]                             @8168     0xc2
ub1 rowdata[17]                             @8169     0x17
ub1 rowdata[18]                             @8170     0x17
ub1 rowdata[19]                             @8171     0x04
ub1 rowdata[20]                             @8172     0x62
ub1 rowdata[21]                             @8173     0x62
ub1 rowdata[22]                             @8174     0x62
ub1 rowdata[23]                             @8175     0x62
ub1 rowdata[24]                             @8176     0x2c
ub1 rowdata[25]                             @8177     0x00
ub1 rowdata[26]                             @8178     0x02
ub1 rowdata[27]                             @8179     0x03
ub1 rowdata[28]                             @8180     0xc2
ub1 rowdata[29]                             @8181     0x0c
ub1 rowdata[30]                             @8182     0x0c
ub1 rowdata[31]                             @8183     0x04
ub1 rowdata[32]                             @8184     0x61
ub1 rowdata[33]                             @8185     0x61
ub1 rowdata[34]                             @8186     0x61
ub1 rowdata[35]                             @8187     0x61

BBED> set offset 8164  --定位到8164
        OFFSET          8164

BBED> d
 File: /oradata/susdata/perry01.dbf (6)
 Block: 16               Offsets: 8164 to 8191           Dba:0x01800010
------------------------------------------------------------------------
 3c020203 c2171704 62626262 2c000203 c20c0c04 61616161 0106bcb7 

 <32 bytes per line>

BBED> m /x 2c --把3C修改为2C,即把flag修改成-HFL 。


Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
 File: /oradata/susdata/perry01.dbf (6)
 Block: 16               Offsets: 8164 to 8191           Dba:0x01800010
------------------------------------------------------------------------
 2c020203 c2171704 62626262 2c000203 c20c0c04 61616161 0106bcb7 

 <32 bytes per line>

BBED> sum apply --使修改生效
Check value for File 6, Block 16:
current = 0x967e, required = 0x967e

BBED> verify
DBVERIFY - Verification starting
FILE = /oradata/susdata/perry01.dbf
BLOCK = 16

Block Checking: DBA = 25165840, Block Type = KTB-managed data block
data header at 0x2a96dbd264
kdbchk: the amount of space used is not equal to block size
        used=60 fsc=10 avsp=8028 dtl=8088
Block 16 failed with check code 6110

DBVERIFY - Verification complete

Total Blocks Examined         : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing   (Data) : 1
Total Blocks Processed (Index): 0
Total Blocks Failing   (Index): 0
Total Blocks Empty            : 0
Total Blocks Marked Corrupt   : 0
Total Blocks Influx           : 0

SQL> select * from perry ; --删除的数据并没有出现

        ID NAME
---------- ----------
      1111 aaaa
      3333 cccc

SQL> alter system flush buffer_cache; --刷新下buffer cache

系统已更改。

SQL> select * from perry;

        ID NAME
---------- ----------
      1111 aaaa
      2222 bbbb
      3333 cccc

     数据行找回来了,很多网友认为恢复已经完成,其实还没有结束。可以看到在执行verify命令的输出,虽然没有损坏,但是使用空间不对,因为多了一行,使用空间肯定比之前占用的长度大了。

kdbchk: the amount of space used is not equal to block size

        used=60 fsc=10 avsp=8028 dtl=8088  --空间使用信息


BBED> p kdbh  --数据块头信息
struct kdbh, 14 bytes                       @100     
   ub1 kdbhflag                             @100      0x00 (NONE)
   b1 kdbhntab                              @101      1
   b2 kdbhnrow                              @102      3
   sb2 kdbhfrre                             @104     -1
   sb2 kdbhfsbo                             @106      24
   sb2 kdbhfseo                             @108      8052
   b2 kdbhavsp                              @110      8028
   b2 kdbhtosp                              @112      8040

--可以看到,kdbhtosp值和我们实际值不一致,kdbhtosp = dtl(8088) - used(60)=8028

SQL> select to_char(8028,'xxxxx') from dual;

TO_CHA
------
  1f5c

--要修改成这个值,记得根据操作系统平台不同,字节序不同。

BBED> m  /x 5c1f  offset 112
File: /oradata/susdata/perry01.dbf (6)
 Block: 16               Offsets:  112 to  623           Dba:0x01800010
------------------------------------------------------------------------
 5c1f0000 03008c1f 801f741f 992dc000 992dc000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 02000000 00200000 00000000 34140000 00000000 9a2dc000 01000000 992dc000 
 9a2dc000 00000000 00000000 00000000 00000000 00000000 01000000 00000000 
 8fa30000 00000010 992dc000 08000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 

 <32 bytes per line>

BBED> sum apply
Check value for File 6, Block 16:
current = 0x964a, required = 0x964a

BBED> verify
DBVERIFY - Verification starting
FILE = /oradata/susdata/perry01.dbf
BLOCK = 16

Block Checking: DBA = 25165840, Block Type = KTB-managed data block
data header at 0x2a96dbd264
kdbchk: the amount of space used is not equal to block size

        used=60 fsc=10 avsp=8028 dtl=8088 -- --还是不一致,发现fsc是10,但是我们实际恢复过来是没有预留空间的。所以把fsc改为00 。

Block 16 failed with check code 6110

DBVERIFY - Verification complete

Total Blocks Examined         : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing   (Data) : 1
Total Blocks Processed (Index): 0
Total Blocks Failing   (Index): 0
Total Blocks Empty            : 0
Total Blocks Marked Corrupt   : 0
Total Blocks Influx           : 0

BBED>  p ktbbhitl[1]
struct ktbbhitl[1], 24 bytes                @68      
   struct ktbitxid, 8 bytes                 @68      
      ub2 kxidusn                           @68       0x0009
      ub2 kxidslt                           @70       0x000e
      ub4 kxidsqn                           @72       0x00000166
   struct ktbituba, 8 bytes                 @76      
      ub4 kubadba                           @76       0x00800108
      ub2 kubaseq                           @80       0x00f7
      ub1 kubarec                           @82       0x1b
   ub2 ktbitflg                             @84       0x0001 (NONE)
   union _ktbitun, 2 bytes                  @86      
      b2 _ktbitfsc                          @86       10 --此值就是上面看到的fsc=10


      ub2 _ktbitwrp                         @86       0x000a
   ub4 ktbitbas                             @88       0x00000000


BBED>   m /x 00 offset 86    --修改成00       
 File: /oradata/susdata/perry01.dbf (6)
 Block: 16               Offsets:   86 to  597           Dba:0x01800010
------------------------------------------------------------------------
 00000000 00000000 00000000 00000001 0300ffff 1800741f 5c1f5c1f 00000300 
 8c1f801f 741f992d c000992d c0000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000200 00000020 
 00000000 00003414 00000000 00009a2d c0000100 0000992d c0009a2d c0000000 
 00000000 00000000 00000000 00000000 00000100 00000000 00008fa3 00000000 
 0010992d c0000800 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 

 <32 bytes per line>

BBED> sum apply 
Check value for File 6, Block 16:
current = 0x9640, required = 0x9640

BBED> verify
DBVERIFY - Verification starting
FILE = /oradata/susdata/perry01.dbf
BLOCK = 16

DBVERIFY - Verification complete

Total Blocks Examined         : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing   (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing   (Index): 0
Total Blocks Empty            : 0
Total Blocks Marked Corrupt   : 0
Total Blocks Influx           : 0

至此,可以看出已经一致了,恢复行数据已经完成。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26008584/viewspace-1255930/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26008584/viewspace-1255930/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值