REDO日誌損壞,非歸檔模式資料檔案恢復

wzhalal發表於2013-08-14

今天一同事專案9I資料庫 執行在非歸檔模式下,應用前端提示ORA-1033: ORACLE 正在初始化或關閉過程中 。

OPEN過程中出現 ORA-16068: redo log file activation identifier mismatch

      ORA-00312: online log 1 thread 1: ‘/usr/app/oracle/oradata/db1/redo03.log’

     解決辦法 啟動資料庫到mount狀態

       sql>startup mount

SQL> select group#,sequence#,archived,status from v$log;

    GROUP#  SEQUENCE# ARC STATUS

---------- ---------- --- ----------------

         1        373 YES INACTIVE

         2        374 NO  CURRENT

         3        372 YES INACTIVE

SQL>alter database clear logfile group 3;
如果是該日誌組還沒有歸檔,則需要用
SQL>alter database clear unarchived logfile group 3;
然後alter database open  資料庫就可以連上了。
我這是在自己本機上隨便做的,但是如果在生產機上最好立刻做備份一下。
說明:
1)、如果損壞的是非當前的聯機日誌檔案,一般只需要clear就可以重建該日誌檔案,但是如果該資料庫處於歸檔狀態但該日誌還沒有歸檔,就需要強行clear。
2)、建議clear,特別是強行clear後作一次資料庫的全備份。
3)、此方法適用於歸檔與非歸檔資料庫。


其後開啟資料庫後出現 資料庫檔案損壞,不能ONLINE,可以利用此方法。

1.建立實驗表空間資料檔案



 1 SQL> conn /as sysdba

 2 

 3 Connected.

 4 

 5 SQL> create tablespace data01 datafile '/u01/app/oracle/oradata/oracle/data01.dbf'size 10m;

 6 

 7 Tablespace created.

 8 

 9 SQL> create table david_01 tablespace data01 as select * from dba_objects;

10 

11 Table created.


2.資料檔案offline



1 SQL> alter database datafile '/u01/app/oracle/oradata/oracle/data01.dbf' offline;

3 Database altered.

5 SQL> alter system switch logfile;

7 System altered.


 3.資料檔案online



 1 SQL> alter database datafile '/u01/app/oracle/oradata/oracle/data01.dbf' online;

 2 

 3 alter database datafile '/u01/app/oracle/oradata/oracle/data01.dbf' online

 4 

 5 *

 6 

 7 ERROR at line 1:

 8 

 9 ORA-01113: file 5 needs media recovery

10 

11 ORA-01110: data file 5: '/u01/app/oracle/oradata/oracle/data01.dbf'


 4.資料檔案進行介質恢復



 1 SQL> recover datafile 5;

 2 

 3 ORA-00279: change 1179122 generated at 04/03/2012 23:35:49 needed for thread 1

 4 

 5 ORA-00289: suggestion : /u01/app/oracle/flash_recovery_area/ORACLE/archivelog/2012_04_03/o1_mf_1_25_7qp6 nqxt_.arc

 6 

 7 ORA-00280: change 1179122 for thread 1 is in sequence #25

 8 

 9  

10 

11 Specify log: {=suggested | filename | AUTO | CANCEL}

12 

13 auto(自動搜尋歸檔日誌,本實驗無歸檔日誌)

14 

15 ORA-00308: cannot open archived log '/u01/app/oracle/flash_recovery_area/ORACLE/archivelog/2012_04_03/o1_mf_1_25_7qp 6nqxt_.arc'

16 

17 ORA-27037: unable to obtain file status

18 

19 Linux-x86_64 Error: 2: No such file or directory

20 

21 Additional information: 3

22 

23  

24 

25 ORA-00308: cannot open archived log '/u01/app/oracle/flash_recovery_area/ORACLE/archivelog/2012_04_03/o1_mf_1_25_7qp 6nqxt_.arc'

26 

27 ORA-27037: unable to obtain file status

28 

29 Linux-x86_64 Error: 2: No such file or directory

30 

31 Additional information: 3


5.加上until cancle引數再次嘗試恢復,恢復資料原則要程式不斷嘗試



 1 SYS SQL> recover datafile 5 until cancel;

 2 

 3 ORA-00274: illegal recovery option UNTIL

 4 

 5  

 6 

 7 SQL> alter database datafile 5 online;

 8 

 9 alter database datafile 5 online

10 

11 *

12 

13 ERROR at line 1:

14 

15 ORA-01113: file 5 needs media recovery

16 

17 ORA-01110: data file 5: '/u01/app/oracle/oradata/oracle/data01.dbf'


6.將庫載入到mount狀態,再次嘗試介質恢復



 1 SQL> shutdown immediate;

 2 

 3 Database closed.

 4 

 5 Database dismounted.

 6 

 7 ORACLE instance shut down.

 8 

 9 SQL> startup mount;

10 

11 ORACLE instance started.

12 

13 Total System Global Area  534462464 bytes

14 

15 Fixed Size                  2215064 bytes

16 

17 Variable Size             406848360 bytes

18 

19 Database Buffers          121634816 bytes

20 

21 Redo Buffers                3764224 bytes

22 

23 Database mounted.


 恢復成功



1 SQL> recover database until cancel;

3 Media recovery complete.


7.嘗試開啟資料庫



 1 SQL> alter database open;

 2 

 3 alter database open

 4 

 5 *

 6 

 7 ERROR at line 1:

 8 

 9 ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

10 

11  

12 

13 SQL> alter database open RESETLOGS;

14 

15 Database altered.


將資料檔案online



 1 SQL> alter database datafile 5 online;

 2 

 3 alter database datafile 5 online

 4 

 5 *

 6 

 7 ERROR at line 1:

 8 

 9 ORA-01190: control file or data file 5 is from before the last RESETLOGS

10 

11 ORA-01110: data file 5: '/u01/app/oracle/oradata/oracle/data01.dbf'


報錯資訊提示:控制檔案或檔案5不在同一個resetlogs版本,再次嘗試恢復



1 SQL> recover datafile 5;

3 ORA-00283: recovery session canceled due to errors

5 ORA-19909: datafile 5 belongs to an orphan incarnation

7 ORA-01110: data file 5: '/u01/app/oracle/oradata/oracle/data01.dbf'


還是失敗


8.修改引數,嘗試手動調整SCN,手動調整SCN以後必須用resetlogs模式開啟資料庫,所以需要設定引數"_allow_resetlogs_corruption"=true



 1 SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;

 2 

 3 System altered.

 4 

 5  

 6 

 7 SQL> shutdown immediate;

 8 

 9 Database closed.

10 

11 Database dismounted.

12 

13 ORACLE instance shut down.

14 

15 SQL> startup mount;

16 

17 ORACLE instance started.

18 

19 Total System Global Area  534462464 bytes

20 

21 Fixed Size                  2215064 bytes

22 

23 Variable Size             406848360 bytes

24 

25 Database Buffers          121634816 bytes

26 

27 Redo Buffers                3764224 bytes

28 

29 Database mounted.


 9.再次介質恢復



1 SQL> recover database until cancel;

3 Media recovery complete.


備註:因為用RESETLOGS來開啟資料庫,所以上面這一步很又做了一遍介質恢復(雖然不做這個操作也能開啟資料庫),但個人覺得是必須要的,然後再將資料檔案狀態聯機



1 SQL> alter database datafile 5 online;

3 Database altered.



1 SQL> alter database open RESETLOGS;

3 Database altered.


10.修改引數,將該引數修改回原來狀態



1 SQL> alter system reset "_allow_resetlogs_corruption" scope=spfile sid='*';

3 System altered.


 11.檢視資料檔案


SQL> select FILE_ID,FILE_NAME,TABLESPACE_NAME,ONLINE_STATUS from dba_data_files;




再檢視下恢復檢視



1 select * from v$recover_file


無任何內容顯示,到此本實驗結束


總結:本實驗討論在非歸檔情況下資料恢復,實驗中需注重oracle提示的錯誤資訊,針對提示資訊採取措施同時還需不斷嘗試開啟資料庫。

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

相關文章