[20121009]學習bbed-恢復刪除的資料.txt

lfree發表於2012-10-09
[20121009]學習bbed-恢復刪除的資料.txt

最近一段時間學習bbed,今天試驗使用它恢復刪除資料.接著前面的練習:

http://space.itpub.net/267265/viewspace-745846

SQL> select dbms_rowid.rowid_relative_fno(rowid) rfile#,dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block#,dbms_rowid.ROWID_ROW_NUMBER(rowid) row#,dept1.* from dept1;

    RFILE#     BLOCK#       ROW#     DEPTNO DNAME          LOC
---------- ---------- ---------- ---------- -------------- -------------
         8        131          0         50 TEST           TEST
         8        131          1         10 ACCOUNTING     NEW YORK
         8        131          2         20 RESEARCH       DALLAS
         8        131          3         30 SALES          CHICAGO
         8        131          4         40 OPERATIONS     BOSTON

SQL> delete from dept1 where deptno=50;
1 row deleted.

SQL> commit ;
Commit complete.

接著關閉資料庫.要恢復這條記錄方法很多,bbed並不是最好,只不過想透過它學習bbed的命令.

1.配置並啟動bbed:

BBED> set dba 8,131
        DBA             0x02000083 (33554563 8,131)

BBED> map /v
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 131                                   Dba:0x02000083
------------------------------------------------------------
 KTB Data Block (Table/Cluster)

 struct kcbh, 20 bytes                      @0
    ub1 type_kcbh                           @0
    ub1 frmt_kcbh                           @1
    ub1 spare1_kcbh                         @2
    ub1 spare2_kcbh                         @3
    ub4 rdba_kcbh                           @4
    ub4 bas_kcbh                            @8
    ub2 wrp_kcbh                            @12
    ub1 seq_kcbh                            @14
    ub1 flg_kcbh                            @15
    ub2 chkval_kcbh                         @16
    ub2 spare3_kcbh                         @18

 struct ktbbh, 96 bytes                     @20
    ub1 ktbbhtyp                            @20
    union ktbbhsid, 4 bytes                 @24
    struct ktbbhcsc, 8 bytes                @28
    sb2 ktbbhict                            @36
    ub1 ktbbhflg                            @38
    ub1 ktbbhfsl                            @39
    ub4 ktbbhfnx                            @40
    struct ktbbhitl[3], 72 bytes            @44

 struct kdbh, 14 bytes                      @124
    ub1 kdbhflag                            @124
    sb1 kdbhntab                            @125
    sb2 kdbhnrow                            @126
    sb2 kdbhfrre                            @128
    sb2 kdbhfsbo                            @130
    sb2 kdbhfseo                            @132
    sb2 kdbhavsp                            @134
    sb2 kdbhtosp                            @136

 struct kdbt[1], 4 bytes                    @138
    sb2 kdbtoffs                            @138
    sb2 kdbtnrow                            @140

 sb2 kdbr[5]                                @142

 ub1 freespace[7928]                        @152

 ub1 rowdata[108]                           @8080

 ub4 tailchk                                @8188

--使用map命令可以完整的顯示塊結構.如果要理解這些可以看看<>的文件.
--kbdr對應的就是row directory.

BBED> p *kdbr[1]
rowdata[66]
-----------
ub1 rowdata[66]                             @8146     0x2c

BBED> x /2rncc
rowdata[66]                                 @8146
-----------
flag@8146: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8147: 0x00
cols@8148:    3

col    0[2] @8149: 10
col   1[10] @8152: ACCOUNTING
col    2[8] @8163: NEW YORK

rowdata[92]                                 @8172
-----------
flag@8172: 0x3c (KDRHFL, KDRHFF, KDRHFD, KDRHFH)
lock@8173: 0x02
cols@8174:    0

--這裡的*可以理解C語言的指標.意思應該差不多了.
--x命令中的/2表示顯示2個,注意oracle資料插入從塊底插入的,而這裡的顯示從上到下,相反的.

--可以發現*kdbr[0]對應的flag=0x3c.而正常的記錄顯示是0x2c.也就是差 KDRHFD.
--也就是修改8172處 3c變成 2c.

BBED> modify /x 2c offset 8172
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 131                                                                    Offsets: 8172 to 8191                                                                 Dba:0x02000083
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 2c020302 c1330454 45535404 54455354 0206b2e3

 <80 bytes per line>

BBED> p *kdbr[1]
rowdata[66]
-----------
ub1 rowdata[66]                             @8146     0x2c

BBED> x /2rncc
rowdata[66]                                 @8146
-----------
flag@8146: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8147: 0x00
cols@8148:    3

col    0[2] @8149: 10
col   1[10] @8152: ACCOUNTING
col    2[8] @8163: NEW YORK

rowdata[92]                                 @8172
-----------
flag@8172: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8173: 0x02
cols@8174:    3

col    0[2] @8175: 50
col    1[4] @8178: TEST
col    2[4] @8183: TEST

--OK,裡面的資訊顯示正常.再更新檢查和就可以了.
BBED> sum
Check value for File 8, Block 131:
current = 0x09e4, required = 0x09f4

BBED> sum apply
Check value for File 8, Block 131:
current = 0x09f4, required = 0x09f4

2.重新啟動資料庫,檢查:
SQL> select rowid ,dbms_rowid.rowid_relative_fno(rowid) rfile#,dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block#,dbms_rowid.ROWID_ROW_NUMBER(rowid) row#,dept1.* from scott.dept1;

ROWID                  RFILE#     BLOCK#       ROW#     DEPTNO DNAME          LOC
------------------ ---------- ---------- ---------- ---------- -------------- -------------
AAAcC1AAIAAAACDAAA          8        131          0         50 TEST           TEST
AAAcC1AAIAAAACDAAB          8        131          1         10 ACCOUNTING     NEW YORK
AAAcC1AAIAAAACDAAC          8        131          2         20 RESEARCH       DALLAS
AAAcC1AAIAAAACDAAD          8        131          3         30 SALES          CHICAGO
AAAcC1AAIAAAACDAAE          8        131          4         40 OPERATIONS     BOSTON

--刪除的資料恢復了.關閉資料庫.再進入bbed看看.

3.使用bbed的檢查命令:
BBED> set dba 8,131
        DBA             0x02000083 (33554563 8,131)

BBED> verify
DBVERIFY - Verification starting
FILE = /u01/app/oracle11g/oradata/test/test01.dbf
BLOCK = 131

Block Checking: DBA = 33554563, Block Type = KTB-managed data block
data header at 0x2a97fb327c
kdbchk: the amount of space used is not equal to block size
        used=136 fsc=14 avsp=7928 dtl=8064
Block 131 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
Message 531 not found;  product=RDBMS; facility=BBED

--使用dbv檢查也是一樣.我是關閉資料庫進行這些操作,看來遺漏了什麼.
$ dbv file=test01.dbf

DBVERIFY: Release 11.2.0.1.0 - Production on Tue Oct 9 08:39:53 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle11g/oradata/test/test01.dbf
Block Checking: DBA = 33554563, Block Type = KTB-managed data block
data header at 0x2a980bb07c
kdbchk: the amount of space used is not equal to block size
        used=136 fsc=14 avsp=7928 dtl=8064
Page 131 failed with check code 6110

DBVERIFY - Verification complete

Total Pages Examined         : 8192
Total Pages Processed (Data) : 1566
Total Pages Failing   (Data) : 1
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 161
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 6465
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 3010061234 (0.3010061234)

參考這篇文件:
http://space.itpub.net/22664653/viewspace-704382

BBED> p kdbh
struct kdbh, 14 bytes                       @124
   ub1 kdbhflag                             @124      0x00 (NONE)
   sb1 kdbhntab                             @125      1
   sb2 kdbhnrow                             @126      5
   sb2 kdbhfrre                             @128     -1
   sb2 kdbhfsbo                             @130      28
   sb2 kdbhfseo                             @132      7956
   sb2 kdbhavsp                             @134      7928
   sb2 kdbhtosp                             @136      7944

kdbhavsp => 表示Avaiable space in the block.
kdbhtosp => 表示Toatl avaiable space when all TXs commit;

--估計修改kdbhtosp=7928 ,這樣就一致了.因為刪除記錄時,這些空間被回收,從前面的顯示也可以看出.


BBED> dump /v offset 134 count 4
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 131                                                         Offsets:  134 to  137                                                      Dba:0x02000083
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 f81e081f                                                                                                    l ....

 <48 bytes per line>

BBED> modify /x f81e offset 136
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 131                                                                    Offsets:  136 to  139                                                                 Dba:0x02000083
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 f81e0000

 <80 bytes per line>

BBED> dump /v offset 134 count 4
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 131                                                         Offsets:  134 to  137                                                      Dba:0x02000083
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 f81ef81e                                                                                                    l ....

 <48 bytes per line>

BBED> p kdbh
struct kdbh, 14 bytes                       @124
   ub1 kdbhflag                             @124      0x00 (NONE)
   sb1 kdbhntab                             @125      1
   sb2 kdbhnrow                             @126      5
   sb2 kdbhfrre                             @128     -1
   sb2 kdbhfsbo                             @130      28
   sb2 kdbhfseo                             @132      7956
   sb2 kdbhavsp                             @134      7928
   sb2 kdbhtosp                             @136      7928

--OK ,修改正確了.
BBED> sum
Check value for File 8, Block 131:
current = 0x09f4, required = 0x0804

BBED> sum apply
Check value for File 8, Block 131:
current = 0x0804, required = 0x0804

BBED> verify
DBVERIFY - Verification starting
FILE = /u01/app/oracle11g/oradata/test/test01.dbf
BLOCK = 131

Block Checking: DBA = 33554563, Block Type = KTB-managed data block
data header at 0x2a97fb327c
kdbchk: the amount of space used is not equal to block size
        used=136 fsc=14 avsp=7928 dtl=8064
Block 131 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
Message 531 not found;  product=RDBMS; facility=BBED

--發現問題依舊.看來按照文件需要修改itl.

BBED> p ktbbhitl
struct ktbbhitl[0], 24 bytes                @44
   struct ktbitxid, 8 bytes                 @44
      ub2 kxidusn                           @44       0xffff
      ub2 kxidslt                           @46       0x0000
      ub4 kxidsqn                           @48       0x00000000
   struct ktbituba, 8 bytes                 @52
      ub4 kubadba                           @52       0x00000000
      ub2 kubaseq                           @56       0x0000
      ub1 kubarec                           @58       0x00
   ub2 ktbitflg                             @60       0x8000 (KTBFCOM)
   union _ktbitun, 2 bytes                  @62
      sb2 _ktbitfsc                         @62       0
      ub2 _ktbitwrp                         @62       0x0000
   ub4 ktbitbas                             @64       0xb369e382
struct ktbbhitl[1], 24 bytes                @68
   struct ktbitxid, 8 bytes                 @68
      ub2 kxidusn                           @68       0x0008
      ub2 kxidslt                           @70       0x0006
      ub4 kxidsqn                           @72       0x00002303
   struct ktbituba, 8 bytes                 @76
      ub4 kubadba                           @76       0x00c03b6d
      ub2 kubaseq                           @80       0x116e
      ub1 kubarec                           @82       0x07
   ub2 ktbitflg                             @84       0x2001 (KTBFUPB)
   union _ktbitun, 2 bytes                  @86
      sb2 _ktbitfsc                         @86       14
      ub2 _ktbitwrp                         @86       0x000e
   ub4 ktbitbas                             @88       0xb369e3b2
struct ktbbhitl[2], 24 bytes                @92
   struct ktbitxid, 8 bytes                 @92
      ub2 kxidusn                           @92       0x0000
      ub2 kxidslt                           @94       0x0000
      ub4 kxidsqn                           @96       0x00000000
   struct ktbituba, 8 bytes                 @100
      ub4 kubadba                           @100      0x00000000
      ub2 kubaseq                           @104      0x0000
      ub1 kubarec                           @106      0x00
   ub2 ktbitflg                             @108      0x0000 (NONE)
   union _ktbitun, 2 bytes                  @110
      sb2 _ktbitfsc                         @110      0
      ub2 _ktbitwrp                         @110      0x0000
   ub4 ktbitbas                             @112      0x00000000

--sb2 _ktbitfsc                         @86       14
--也就是修改offset=86 0.

BBED> modify /x 00 offset 86
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 131                                                                    Offsets:   86 to   89                                                                 Dba:0x02000083
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 0000b2e3

 <80 bytes per line>

BBED> p ktbbhitl
struct ktbbhitl[0], 24 bytes                @44
   struct ktbitxid, 8 bytes                 @44
      ub2 kxidusn                           @44       0xffff
      ub2 kxidslt                           @46       0x0000
      ub4 kxidsqn                           @48       0x00000000
   struct ktbituba, 8 bytes                 @52
      ub4 kubadba                           @52       0x00000000
      ub2 kubaseq                           @56       0x0000
      ub1 kubarec                           @58       0x00
   ub2 ktbitflg                             @60       0x8000 (KTBFCOM)
   union _ktbitun, 2 bytes                  @62
      sb2 _ktbitfsc                         @62       0
      ub2 _ktbitwrp                         @62       0x0000
   ub4 ktbitbas                             @64       0xb369e382
struct ktbbhitl[1], 24 bytes                @68
   struct ktbitxid, 8 bytes                 @68
      ub2 kxidusn                           @68       0x0008
      ub2 kxidslt                           @70       0x0006
      ub4 kxidsqn                           @72       0x00002303
   struct ktbituba, 8 bytes                 @76
      ub4 kubadba                           @76       0x00c03b6d
      ub2 kubaseq                           @80       0x116e
      ub1 kubarec                           @82       0x07
   ub2 ktbitflg                             @84       0x2001 (KTBFUPB)
   union _ktbitun, 2 bytes                  @86
      sb2 _ktbitfsc                         @86       0
      ub2 _ktbitwrp                         @86       0x0000
   ub4 ktbitbas                             @88       0xb369e3b2
struct ktbbhitl[2], 24 bytes                @92
   struct ktbitxid, 8 bytes                 @92
      ub2 kxidusn                           @92       0x0000
      ub2 kxidslt                           @94       0x0000
      ub4 kxidsqn                           @96       0x00000000
   struct ktbituba, 8 bytes                 @100
      ub4 kubadba                           @100      0x00000000
      ub2 kubaseq                           @104      0x0000
      ub1 kubarec                           @106      0x00
   ub2 ktbitflg                             @108      0x0000 (NONE)
   union _ktbitun, 2 bytes                  @110
      sb2 _ktbitfsc                         @110      0
      ub2 _ktbitwrp                         @110      0x0000
   ub4 ktbitbas                             @112      0x00000000


--再計算檢查和.
BBED> sum
Check value for File 8, Block 131:
current = 0x0804, required = 0x080a

BBED> sum apply
Check value for File 8, Block 131:
current = 0x080a, required = 0x080a

BBED> ver
Verification  verify
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/app/oracle11g/oradata/test/test01.dbf
BLOCK = 131

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
Message 531 not found;  product=RDBMS; facility=BBED

$ dbv file=test01.dbf

DBVERIFY: Release 11.2.0.1.0 - Production on Tue Oct 9 08:55:23 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle11g/oradata/test/test01.dbf

DBVERIFY - Verification complete

Total Pages Examined         : 8192
Total Pages Processed (Data) : 1566
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 161
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 6465
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 3010061234 (0.3010061234)
--dbv檢查也正常.

--以後修改塊,要注意使用verify檢檢視看.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-745944/,如需轉載,請註明出處,否則將追究法律責任。

相關文章