System File1 File Header(資料庫System檔案1檔案頭)損壞情況的恢復

紅葉DBA發表於2013-01-15
鄭重宣告:本文所述內容純屬個人研究,對於任何由此帶來的資料庫故障,本人概不負責!

【SYSTEM 1號檔案頭損壞的恢復】

【工欲善其,必先利其器】
在進行本次故障重現與恢復工作之前,我們需要首先準備好實驗工具,本次實驗過程中全程使用sqlplus、bbed以及作業系統命令實現。
在這些所有工具中,我們需要自行編譯bbed,該工具並非Oracle自帶工具。
在Oracle 10g中,我們可以自行編譯BBED工具,而Oracle 11g版本可以使用在10g中編譯完成的BBED工具來進行本次實驗:
1、編譯BBED:
[oracle@db10205 ~]$ cd $ORACLE_HOME/rdbms/lib/
[oracle@db10205 lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
Linking BBED utility (bbed)
rm -f /oracle/product/10.2.0/db_1/rdbms/lib/bbed
gcc -o /oracle/product/10.2.0/db_1/rdbms/lib/bbed -L/oracle/product/10.2.0/db_1/rdbms/lib/ -L/oracle/product/10.b

[oracle@db10205 lib]$ mv bbed $ORACLE_HOME/bin
[oracle@db10205 lib]$ which bbed
/oracle/product/10.2.0/db_1/bin/bbed

[oracle@db10205 lib]$ bbed help=y
PASSWORD - Required parameter
FILENAME - Database file name
BLOCKSIZE - Database block size
LISTFILE - List file name
MODE - [browse/edit]
SPOOL - Spool to logfile [no/yes]
CMDFILE - BBED command file name
LOGFILE - BBED log file name
PARFILE - Parameter file name
BIFILE - BBED before-image file name
REVERT - Rollback changes from BIFILE [no/yes]
SILENT - Hide banner [no/yes]
HELP - Show all valid parameters [no/yes]


【一、模擬環境說明】
1、現有資料檔案
[oracle@db10205 datafile]$ ls -l
total 1001868
-rw-r----- 1 oracle oinstall 167780352 Dec 27 17:09 o1_mf_sysaux_8fno7csh_.dbf
-rw-r----- 1 oracle oinstall 314580992 Dec 27 17:09 o1_mf_system_8fno677y_.dbf       --正常的SYSTEM表空間1號檔案
-rw-r----- 1 oracle oinstall 314580992 Dec 27 17:14 o1_mf_system_8fno677y_.dbf.bak   --正常的SYSTEM表空間1號檔案的備份檔案
-rw-r----- 1 oracle oinstall  20979712 Dec 27 16:33 o1_mf_temp_8fno7lss_.tmp
-rw-r----- 1 oracle oinstall 209723392 Dec 27 17:09 o1_mf_undotbs1_8fno70q5_.dbf
-rw-r----- 1 oracle oinstall   5251072 Dec 27 17:09 o1_mf_users_8fno8gxr_.dbf

2、BBED檔案列表
[oracle@db10205 bbed]$ cat filelist.txt 
1 /oracle/oradata/DB/datafile/o1_mf_system_8fno677y_.dbf     
2 /oracle/oradata/DB/datafile/o1_mf_sysaux_8fno7csh_.dbf

3、構造SYSTEM檔案頭損壞的案例
模擬環境中,使用bbed工具來破壞檔案頭。對此我們可以使用複製一個任意其他塊複寫File Header,來達到破壞的目的
BBED> help copy
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]

BBED> copy file 1 block 111 to file 1 block 1
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y
 File: /oracle/oradata/DB/datafile/o1_mf_system_8fno677y_.dbf (1)
 Block: 1                Offsets:    0 to  511           Dba:0x00400001
------------------------------------------------------------------------
 00a20000 6f000000 00000000 00000105 6fa70000 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 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 1, Block 1:
current = 0xa76f, required = 0xa76f

4、損壞後嘗試啟動資料庫
17:21:02 IDLE > startup
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  2095568 bytes
Variable Size             109053488 bytes
Database Buffers          150994944 bytes
Redo Buffers                6291456 bytes
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/oracle/oradata/DB/datafile/o1_mf_system_8fno677y_.dbf'
ORA-01210: data file header is media corrupt

5、BBED顯示塊型別錯誤
BBED> set file 1 block 1
        FILE#           1
        BLOCK#          1

BBED> map /v
 File: /oracle/oradata/DB/datafile/o1_mf_system_8fno677y_.dbf (1)
 Block: 1                                     Dba:0x00400001
------------------------------------------------------------
BBED-00400: invalid blocktype (00)

本段總結:
在本段實驗中,我們使用File 1 Block 111複寫File 1 Block 1,
這樣的話,在File 1中,檔案頭(File Header)就已經被損壞了,而若DBA不知道檔案頭損壞的事實的話,那麼在啟動時就會出現ORA-01122錯誤。


恢復思路:
我們知道資料檔案頭(File Header)有其獨有的資料結構,對於File Header結構,我們可以修改其中的資料,但是對於其資料結構,我們很難手動構造,故此:在恢復過程中,我們使用從SYSAUX檔案,也就是File 3中拷貝過來的File Header,並修改其中的的部分資料,使其滿足File 1的檔案頭內容要求。

【二、構造頭塊結構】
複製File 3(SYSAUX)的File Header,用於構造File 1的File Header。
BBED> copy file 2 block 1 to file 1 block 1
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y
 File: /oracle/oradata/DB/datafile/o1_mf_system_8fno677y_.dbf (1)
 Block: 1                Offsets:    0 to  511           Dba:0x00400001
------------------------------------------------------------------------
 0ba20000 0100c000 00000000 00000104 47420000 00000000 0005200a b043645d 
 44420000 00000000 f1000000 00500000 00200000 03000300 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 12150000 00000000 6d5cdd2f 305cdd2f 01000000 00000000 00000000 
 00000000 00000000 00000000 28000000 9315df2f 27000000 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 02000000 06005359 53415558 00000000 00000000 
 00000000 00000000 00000000 00000000 03000000 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 75300500 00004506 e717df2f 01004506 12000000 14ab0000 10000000 

 <32 bytes per line>

BBED> sum apply
Check value for File 1, Block 1:
current = 0x4247, required = 0x4247

我們可以檢視複製過來的File Header結構
BBED> map /v
 File: /oracle/oradata/DB/datafile/o1_mf_system_8fno677y_.dbf (1)
 Block: 1                                     Dba:0x00400001
------------------------------------------------------------
 Data File Header

 struct kcvfh, 676 bytes                    @0       
    struct kcvfhbfh, 20 bytes               @0       
    struct kcvfhhdr, 76 bytes               @20      
    ub4 kcvfhrdb                            @96      
    struct kcvfhcrs, 8 bytes                @100     
    ub4 kcvfhcrt                            @108     
    ub4 kcvfhrlc                            @112     
    struct kcvfhrls, 8 bytes                @116     
    ub4 kcvfhbti                            @124     
    struct kcvfhbsc, 8 bytes                @128     
    ub2 kcvfhbth                            @136     
    ub2 kcvfhsta                            @138     
    struct kcvfhckp, 36 bytes               @484     
    ub4 kcvfhcpc                            @140     
    ub4 kcvfhrts                            @144     
    ub4 kcvfhccc                            @148     
    struct kcvfhbcp, 36 bytes               @152     
    ub4 kcvfhbhz                            @312     
    struct kcvfhxcd, 16 bytes               @316     
    word kcvfhtsn                           @332     
    ub2 kcvfhtln                            @336     
    text kcvfhtnm[30]                       @338     
    ub4 kcvfhrfn                            @368     
    struct kcvfhrfs, 8 bytes                @372     
    ub4 kcvfhrft                            @380     
    struct kcvfhafs, 8 bytes                @384     
    ub4 kcvfhbbc                            @392     
    ub4 kcvfhncb                            @396     
    ub4 kcvfhmcb                            @400     
    ub4 kcvfhlcb                            @404     
    ub4 kcvfhbcs                            @408     
    ub2 kcvfhofb                            @412     
    ub2 kcvfhnfb                            @414     
    ub4 kcvfhprc                            @416     
    struct kcvfhprs, 8 bytes                @420     
    struct kcvfhprfs, 8 bytes               @428     
    ub4 kcvfhtrt                            @444     

 ub4 tailchk                                @8188    
 
BBED> print kcvfh
struct kcvfh, 676 bytes                     @0       
   struct kcvfhbfh, 20 bytes                @0       
      ub1 type_kcbh                         @0        0x0b
      ub1 frmt_kcbh                         @1        0xa2
      ub1 spare1_kcbh                       @2        0x00
      ub1 spare2_kcbh                       @3        0x00
      ub4 rdba_kcbh                         @4        0x00c00001
      ub4 bas_kcbh                          @8        0x00000000
      ub2 wrp_kcbh                          @12       0x0000
      ub1 seq_kcbh                          @14       0x01
      ub1 flg_kcbh                          @15       0x04 (KCBHFCKV)
      ub2 chkval_kcbh                       @16       0x4247
      ub2 spare3_kcbh                       @18       0x0000
   struct kcvfhhdr, 76 bytes                @20      
      ub4 kccfhswv                          @20       0x00000000
      ub4 kccfhcvn                          @24       0x0a200500
      ub4 kccfhdbi                          @28       0x5d6443b0
      text kccfhdbn[0]                      @32      D
      text kccfhdbn[1]                      @33      B
      text kccfhdbn[2]                      @34       
      text kccfhdbn[3]                      @35       
      text kccfhdbn[4]                      @36       
      text kccfhdbn[5]                      @37       
      text kccfhdbn[6]                      @38       
      text kccfhdbn[7]                      @39       
      ub4 kccfhcsq                          @40       0x000000f1
      ub4 kccfhfsz                          @44       0x00005000
      s_blkz kccfhbsz                       @48       0x00
      ub2 kccfhfno                          @52       0x0003
      ub2 kccfhtyp                          @54       0x0003
      ub4 kccfhacid                         @56       0x00000000
      ub4 kccfhcks                          @60       0x00000000
      text kccfhtag[0]                      @64       
      text kccfhtag[1]                      @65       
      text kccfhtag[2]                      @66       
      text kccfhtag[3]                      @67       
      text kccfhtag[4]                      @68       
      text kccfhtag[5]                      @69       
      text kccfhtag[6]                      @70       
      text kccfhtag[7]                      @71       
      text kccfhtag[8]                      @72       
      text kccfhtag[9]                      @73       
      text kccfhtag[10]                     @74       
      text kccfhtag[11]                     @75       
      text kccfhtag[12]                     @76       
      text kccfhtag[13]                     @77       
      text kccfhtag[14]                     @78       
      text kccfhtag[15]                     @79       
      text kccfhtag[16]                     @80       
      text kccfhtag[17]                     @81       
      text kccfhtag[18]                     @82       
      text kccfhtag[19]                     @83       
      text kccfhtag[20]                     @84       
      text kccfhtag[21]                     @85       
      text kccfhtag[22]                     @86       
      text kccfhtag[23]                     @87       
      text kccfhtag[24]                     @88       
      text kccfhtag[25]                     @89       
      text kccfhtag[26]                     @90       
      text kccfhtag[27]                     @91       
      text kccfhtag[28]                     @92       
      text kccfhtag[29]                     @93       
      text kccfhtag[30]                     @94       
      text kccfhtag[31]                     @95       
   ub4 kcvfhrdb                             @96       0x00000000
   struct kcvfhcrs, 8 bytes                 @100     
      ub4 kscnbas                           @100      0x00001512
      ub2 kscnwrp                           @104      0x0000
   ub4 kcvfhcrt                             @108      0x2fdd5c6d
   ub4 kcvfhrlc                             @112      0x2fdd5c30
   struct kcvfhrls, 8 bytes                 @116     
      ub4 kscnbas                           @116      0x00000001
      ub2 kscnwrp                           @120      0x0000
   ub4 kcvfhbti                             @124      0x00000000
   struct kcvfhbsc, 8 bytes                 @128     
      ub4 kscnbas                           @128      0x00000000
      ub2 kscnwrp                           @132      0x0000
   ub2 kcvfhbth                             @136      0x0000
   ub2 kcvfhsta                             @138      0x0000 (NONE)
   struct kcvfhckp, 36 bytes                @484     
      struct kcvcpscn, 8 bytes              @484     
         ub4 kscnbas                        @484      0x00053075
         ub2 kscnwrp                        @488      0x0000
      ub4 kcvcptim                          @492      0x2fdf17e7
      ub2 kcvcpthr                          @496      0x0001
      union u, 12 bytes                     @500     
         struct kcvcprba, 12 bytes          @500     
            ub4 kcrbaseq                    @500      0x00000012
            ub4 kcrbabno                    @504      0x0000ab14
            ub2 kcrbabof                    @508      0x0010
      ub1 kcvcpetb[0]                       @512      0x02
      ub1 kcvcpetb[1]                       @513      0x00
      ub1 kcvcpetb[2]                       @514      0x00
      ub1 kcvcpetb[3]                       @515      0x00
      ub1 kcvcpetb[4]                       @516      0x00
      ub1 kcvcpetb[5]                       @517      0x00
      ub1 kcvcpetb[6]                       @518      0x00
      ub1 kcvcpetb[7]                       @519      0x00
   ub4 kcvfhcpc                             @140      0x00000028
   ub4 kcvfhrts                             @144      0x2fdf1593
   ub4 kcvfhccc                             @148      0x00000027
   struct kcvfhbcp, 36 bytes                @152     
      struct kcvcpscn, 8 bytes              @152     
         ub4 kscnbas                        @152      0x00000000
         ub2 kscnwrp                        @156      0x0000
      ub4 kcvcptim                          @160      0x00000000
      ub2 kcvcpthr                          @164      0x0000
      union u, 12 bytes                     @168     
         struct kcvcprba, 12 bytes          @168     
            ub4 kcrbaseq                    @168      0x00000000
            ub4 kcrbabno                    @172      0x00000000
            ub2 kcrbabof                    @176      0x0000
      ub1 kcvcpetb[0]                       @180      0x00
      ub1 kcvcpetb[1]                       @181      0x00
      ub1 kcvcpetb[2]                       @182      0x00
      ub1 kcvcpetb[3]                       @183      0x00
      ub1 kcvcpetb[4]                       @184      0x00
      ub1 kcvcpetb[5]                       @185      0x00
      ub1 kcvcpetb[6]                       @186      0x00
      ub1 kcvcpetb[7]                       @187      0x00
   ub4 kcvfhbhz                             @312      0x00000000
   struct kcvfhxcd, 16 bytes                @316     
      ub4 space_kcvmxcd[0]                  @316      0x00000000
      ub4 space_kcvmxcd[1]                  @320      0x00000000
      ub4 space_kcvmxcd[2]                  @324      0x00000000
      ub4 space_kcvmxcd[3]                  @328      0x00000000
   word kcvfhtsn                            @332      2
   ub2 kcvfhtln                             @336      0x0006
   text kcvfhtnm[0]                         @338     S
   text kcvfhtnm[1]                         @339     Y
   text kcvfhtnm[2]                         @340     S
   text kcvfhtnm[3]                         @341     A
   text kcvfhtnm[4]                         @342     U
   text kcvfhtnm[5]                         @343     X
   text kcvfhtnm[6]                         @344      
   text kcvfhtnm[7]                         @345      
   text kcvfhtnm[8]                         @346      
   text kcvfhtnm[9]                         @347      
   text kcvfhtnm[10]                        @348      
   text kcvfhtnm[11]                        @349      
   text kcvfhtnm[12]                        @350      
   text kcvfhtnm[13]                        @351      
   text kcvfhtnm[14]                        @352      
   text kcvfhtnm[15]                        @353      
   text kcvfhtnm[16]                        @354      
   text kcvfhtnm[17]                        @355      
   text kcvfhtnm[18]                        @356      
   text kcvfhtnm[19]                        @357      
   text kcvfhtnm[20]                        @358      
   text kcvfhtnm[21]                        @359      
   text kcvfhtnm[22]                        @360      
   text kcvfhtnm[23]                        @361      
   text kcvfhtnm[24]                        @362      
   text kcvfhtnm[25]                        @363      
   text kcvfhtnm[26]                        @364      
   text kcvfhtnm[27]                        @365      
   text kcvfhtnm[28]                        @366      
   text kcvfhtnm[29]                        @367      
   ub4 kcvfhrfn                             @368      0x00000003
   struct kcvfhrfs, 8 bytes                 @372     
      ub4 kscnbas                           @372      0x00000000
      ub2 kscnwrp                           @376      0x0000
   ub4 kcvfhrft                             @380      0x00000000
   struct kcvfhafs, 8 bytes                 @384     
      ub4 kscnbas                           @384      0x00000000
      ub2 kscnwrp                           @388      0x0000
   ub4 kcvfhbbc                             @392      0x00000000
   ub4 kcvfhncb                             @396      0x00000000
   ub4 kcvfhmcb                             @400      0x00000000
   ub4 kcvfhlcb                             @404      0x00000000
   ub4 kcvfhbcs                             @408      0x00000000
   ub2 kcvfhofb                             @412      0x0000
   ub2 kcvfhnfb                             @414      0x0000
   ub4 kcvfhprc                             @416      0x00000000
   struct kcvfhprs, 8 bytes                 @420     
      ub4 kscnbas                           @420      0x00000000
      ub2 kscnwrp                           @424      0x0000
   struct kcvfhprfs, 8 bytes                @428     
      ub4 kscnbas                           @428      0x00000000
      ub2 kscnwrp                           @432      0x0000
   ub4 kcvfhtrt                             @444      0x00000000


本段總結:
在本段實驗中,我們從File 3(SYSAUX)中拷貝了File Header,用於覆蓋File 1的File Header,而從複寫後的File 1 Block 1中,我們可以看到SYSAUX的字樣,這也正是File 3的表空間名稱,這也是後續需要修改的內容之一。

以下部分將詳細描述需要修改的內容,以及修改的過程及命令:

【三、修復頭塊資料】
1、Relative Data Block Address(相對檔案塊地址)
   [ ub4 rdba_kcbh                      @4        0x00c00001 ]
此部分表示相對檔案塊地址,即本塊(File 1 Block 1)的地址。共32位,前10位為檔案號,後22位為塊號。
原資料:00c00001,而本次模擬環境是Linux,是小位元組序平臺,我們需要做位元組調換,調換後的資料為0100c000,而這部分內容也可以在dump過程中顯示出來,轉化為二進位制就是0000 0000 11 00 0000 0000 0000 0000 0001,前10位為檔案號,即3,後22號為塊號,即1。
新資料:通過反向推理,File 1 Block 1,即為0000 0000 01 00 0000 0000 0000 0000 0001,轉化為16進製為00400001,調換位元組序之後為01004000。
   BBED Command :
     set file 1 block 1 offset 4
     dump
     modify /x 01004000
     sum apply
 
2、File Size(檔案大小)
   [ ub4 kccfhfsz                      @44       0x00005000 ]
此部分修改檔案大小,此部分可以從v$datafile.blocks查詢出來,下面提出令一種方法,從系統檔案大小推算出Oracle檔案大小
原資料:5000,轉化為10進位制即為20480,這也是File 3的Block Number,而當前資料庫Block Size為8192,故此可以計算出Oracle檔案大小為20480*8192=167772160,而在作業系統中,可以看到sysaux檔案的大小為167780352,167780352-167772160=8192,剛還相差一個Block,也就是說,在Oracle計算檔案大小的時候,是不包括File Header的,這也就是為什麼Oracle的File Size比系統中的File Size少一個Block Size的原因。
新資料,同樣通過反向推理,我們從系統中的File 1檔案的大小推匯出其資料庫檔案大小,進一步推匯出其調換位元組序之後的16進位制資料位9600。
   BBED Command :
     set file 1 block 1 offset 44
     dump
     modify /x 00960000
     sum apply

3、File Number(絕對檔案號)
   [ ub2 kccfhfno                          @52       0x0003 ]
0003表示3號檔案,即SYSAUX檔案號為3,而SYSTEM檔案號為1,故此改為0001
   BBED Command :
     set file 1 block 1 offset 52
     dump
     modify /x 0100
     sum apply   

4、Root Data Block(Root塊地址)
   [ ub4 kcvfhrdb                      @96       0x00000000 ]
Root塊地址也就是Oracle資料庫中bootstrap$物件的地址,在10g環境中,BootStrap$物件位於1號檔案377塊上,這是一個固定的位置。
00000000 全0表示0號檔案0號塊,也就說該檔案上不存在BootStrap$物件
File 1 Block 377參照第一步中的地址結構,我們可以得到其調換位元組序之後的16進位制資料位79014000。
   BBED Command :
     set file 1 block 1 offset 96
     dump
     modify /x 79014000
     sum apply   

5、File Create SCN(檔案建立SCN)
   [ struct kcvfhcrs, 8 bytes          @100                 ]
   [    ub4 kscnbas                    @100      0x00001512 ]
   [    ub2 kscnwrp                    @104      0x0000     ]
從v$datafile檔案中獲取,其查詢SQL如下:
COL NAME FOR A66
SELECT FILE#,NAME,CREATION_CHANGE# 
FROM V$DATAFILE;
其中1512轉換成10進製為5394,即為SYSAUX File3的Create SCN。而SYSTEM File1的Create SCN為11,即B,前面補0,即0000 000B,轉換位元組序,即0B00 0000。
   BBED Command :
     set file 1 block 1 offset 100
     dump
     modify /x 0b00
     sum apply  
 
6、File Create Time(檔案建立時間)
   [ ub4 kcvfhcrt                      @108      0x2fdd5c6d ]
從v$datafile檔案中獲取,其查詢SQL如下:
COL NAME FOR A66
SELECT FILE#,NAME,TO_CHAR(CREATION_TIME,'YYYY-MM-DD HH24:MI:SS') CREATION_TIME_D,
       (TO_CHAR(CREATION_TIME,'YYYY')-1988)*12*31*24*3600
       +(TO_CHAR(CREATION_TIME,'MM')-1)*31*24*3600
       +(TO_CHAR(CREATION_TIME,'DD')-1)*24*3600
       +TO_CHAR(CREATION_TIME,'HH24')*3600
       +TO_CHAR(CREATION_TIME,'MI')*60
       +TO_CHAR(CREATION_TIME,'SS') CREATION_TIME_N,
       TS#,STATUS
  FROM V$DATAFILE;
2fdd5c6d 轉換為10進製為 803036269,也即SYSAUX File3的Create Time的數值表示。SYSTEM File1的Create Time為803036246,轉化為16進製為2FDD5C56,轉換位元組序之後為565CDD2F。
   BBED Command :
     set file 1 block 1 offset 108
     dump
     modify /x 565cdd2f
     sum apply  

7、File Header Status(檔案頭狀態標誌)
   [ ub2 kcvfhsta                   @138      0x0000 (NONE) ]
此處狀態0000,表明資料庫處於正常關閉狀態,對於File1檔案來說,該狀態的值為8192,轉為16進製為2000,轉換位元組序為0020
   BBED Command :
     set file 1 block 1 offset 138
     dump
     modify /x 0020
     sum apply   

8、Tablespace Number(表空間號)
   [ word kcvfhtsn                              @332      2 ]
查詢得出SYSAUX的表空間號為2,而SYSTEM表空間號為0,故此修改為0
   BBED Command :
     set file 1 block 1 offset 332
     dump
     modify /x 00
     sum apply 

9、Tablespace Name(表空間名稱)
   [ xt kcvfhtnm[0]                         @338     S ]
   [ xt kcvfhtnm[1]                         @339     Y ]
   [ xt kcvfhtnm[2]                         @340     S ]
   [ xt kcvfhtnm[3]                         @341     A ]
   [ xt kcvfhtnm[4]                         @342     U ]
   [ xt kcvfhtnm[5]                         @343     X ]
此處需要修改AUX三個字元,修改為TEM,從314偏移位置開始的3個位元組為415558,從ASCII碼錶檢視,得出AUX,希望修改目標為TEM,其ASCII碼錶值為54454D
   BBED Command :
     set file 1 block 1 offset 341
     dump
     modify /x 54454d
     sum apply 
或者還有更為簡單的修改方式,直接修改如下:
   BBED Command :
     set file 1 block 1 offset 341
     dump
     modify /c TEM
     sum apply 

10、Relative File Number(相對檔案號)
    [ ub4 kcvfhrfn                     @368      0x00000003 ]
3號檔案為SYSAUX File3,修改為SYSTEM FIle1,即1號檔案
    BBED Command :
      set file 1 block 1 offset 368
      dump
      modify /x 01
      sum apply 

本段總結:
本段實驗過程中,我們分10個步驟一步一步的修改完了虛假檔案頭中的虛假資料,這些資料也是資料庫啟動過程中的驗證資料,通過這10步的修改,資料庫一般就可以回歸正常狀態。

目前File1的File Header已經基本恢復正常了,但是由於我們無法獲取正確的File 1的on disk rba,故此在啟動過程中可能需要恢復資料庫或者檔案,以下我們會描述修改完成之後,如何啟動資料庫。
 
【四、啟動資料庫】

全部修改完畢之後,嘗試啟動資料庫:
18:35:36 IDLE > alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery if it was restored from backup, or END BACKUP if it was not
ORA-01110: data file 1: '/oracle/oradata/DB/datafile/o1_mf_system_8fno677y_.dbf'

報錯ORA-01113: file 1 needs media recovery,報該錯誤,基本就已經迴歸正途了,由於我們已經無法得知SYSTEM File1正真的恢復起點,故此可直接recover後open資料庫

18:35:42 IDLE > recover datafile 1;
Media recovery complete.
18:35:59 IDLE > alter database open;

Database altered.

自此:資料庫正常啟動,且後臺告警日誌未出現任何類似ORA-600、7445等內部錯誤,恢復完成!

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

相關文章