1. 程式人生 > >斷電導致資料庫不一致

斷電導致資料庫不一致

斷電導致資料庫檔案不一致,可能是controlfile,也可能是system資料檔案報錯,無備份,非歸檔

1、首先檢視alter.log ,檢視報錯資訊,如果是redo不一致可以嘗試加,_ALLOW_RESETLOGS_CORRUPTION = TRUE 隱含引數試試

2、看到控制檔案不一致時,首先是將control02.ctl 拷貝為 control01.ctl,使兩份控制檔案一致,啟動還是報錯,報system資料檔案問題

SQL> show parameter _ALLOW_RESETLOGS_CORRUPTION

SQL> recover database;

ORA-00283: recovery session canceled due to errors

ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

SQL> recover database using  BACKUP CONTROLFILE;

ORA-00279: change 2433115 generated at 01/17/2008 04:00:40 needed for thread 1

ORA-00289: suggestion :

/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc

ORA-00280: change 2433115 for thread 1 is in sequence #42

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

auto

ORA-00308: cannot open archived log

'/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

ORA-00308: cannot open archived log

'/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

SQL> recover database using  BACKUP CONTROLFILE;

ORA-00279: change 2433115 generated at 01/17/2008 04:00:40 needed for thread 1

ORA-00289: suggestion :

/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc

ORA-00280: change 2433115 for thread 1 is in sequence #42

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

cancel

Media recovery cancelled.

SQL> alter database open;

alter database open

ERROR at line 1:

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

SQL> alter database open resetlogs;

alter database open resetlogs

*

ERROR at line 1:

ORA-01113: file 1 needs media recovery

ORA-01110: data file 1: '/opt/oracle/oradata/oradb/bak/system01.dbf'

顯示錶空間需要修復

SQL> recover datafile 1;

ORA-00283: recovery session canceled due to errors

ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

SQL> recover database using  BACKUP CONTROLFILE until cancel;

ORA-00279: change 2433115 generated at 01/17/2008 04:00:40 needed for thread 1

ORA-00289: suggestion :

/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc

ORA-00280: change 2433115 for thread 1 is in sequence #42

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

cancel

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below

ORA-01194: file 1 needs more recovery to be consistent

ORA-01110: data file 1: '/opt/oracle/oradata/oradb/bak/system01.dbf'

ORA-01112: media recovery not started

SQL> alter database open resetlogs;

alter database open resetlogs

*

ERROR at line 1:

ORA-01194: file 1 needs more recovery to be consistent

ORA-01110: data file 1: '/opt/oracle/oradata/oradb/bak/system01.dbf'

仍然需要恢復表空間

SQL> recover datafile 1;

ORA-00283: recovery session canceled due to errors

ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

加入隱含引數!,關閉重啟

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

sqlplus / as sysdba


SQL> startup mount

SQL> recover database;

ORA-00283: recovery session canceled due to errors

ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

SQL> recover database using backup controlfile until cancel;

ORA-00279: change 2433115 generated at 01/17/2008 04:00:40 needed for thread 1

ORA-00289: suggestion :

/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc

ORA-00280: change 2433115 for thread 1 is in sequence #42

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

auto

ORA-00308: cannot open archived log

'/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

ORA-00308: cannot open archived log

'/opt/oracle/flash_recovery_area/ORADB/archivelog/2008_01_18/o1_mf_1_42_%u_.arc'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below

ORA-01194: file 1 needs more recovery to be consistent

ORA-01110: data file 1: '/opt/oracle/oradata/oradb/bak/system01.dbf'

SQL> alter database open;

alter database open

*

ERROR at line 1:

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

SQL> alter database open RESETLOGS;

此時,系統好像hang住了一樣,很長一段時間沒有反映,過了一會,報錯如下!

alter database open RESETLOGS

*

ERROR at line 1:

ORA-01092: ORACLE instance terminated. Disconnection forced

此時檢視alter日誌資訊:又出現2662錯誤,

Errors in file /opt/oracle/admin/oradb/udump/oradb_ora_10369.trc:

ORA-00600: internal error code, arguments: [2662], [0], [2433141], [0], [2443300], [12595947], [], []

Fri Jan 18 15:58:21 2008

Errors in file /opt/oracle/admin/oradb/udump/oradb_ora_10369.trc:

ORA-00600: internal error code, arguments: [2662], [0], [2433141], [0], [2443300], [12595947], [], []

Fri Jan 18 15:58:21 2008

Error 600 happened during db open, shutting down database

USER: terminating instance due to error 600

Instance terminated by USER, pid = 10369

ORA-1092 signalled during: alter database open RESETLOGS...

再次重啟登入

SQL> startup

ORACLE instance started.

Total System Global Area  616562688 bytes

Fixed Size                  1220868 bytes

Variable Size             167775996 bytes

Database Buffers          440401920 bytes

Redo Buffers                7163904 bytes

Database mounted.

ORA-01113: file 1 needs media recovery

ORA-01110: data file 1: '/opt/oracle/oradata/oradb/bak/system01.dbf'

SQL> recover database;
Media recovery complete.
SQL> alter database open;

alter database open

*

ERROR at line 1:

ORA-00603: ORACLE server session terminated by fatal error

檢查日誌如下:爽呀,又出現了ORA-00600 中的4194錯誤,

Database Characterset is UTF8

Fri Jan 18 16:00:14 2008

Errors in file /opt/oracle/admin/oradb/udump/oradb_ora_10443.trc:

ORA-00600: internal error code, arguments: [4194], [38], [34], [], [], [], [], []

Fri Jan 18 16:00:14 2008

Errors in file /opt/oracle/admin/oradb/bdump/oradb_smon_10429.trc:

ORA-00600: internal error code, arguments: [4194], [59], [57], [], [], [], [], []

4149錯誤一般根undo有關係,因為當前redo損壞,undo資料也大都不一致了

設定隱含引數:undo改變成手工管理的,然後重啟資料庫。

SQL> startup mount
SQL> show parameter undo

SQL> alter system set undo_management='manual' scope=spfile;

SQL> shutdown immediate

SQL> quit


SQL> startup mount

SQL> alter database open

成功開庫

因為設定了undo手動管理,update資料庫時會出現問題,重新建立自動管理undo表空間,並指定新的undo表空間

總結:

系統掉電一般引起redo損壞,最糟糕的就是引起當前redo損壞,針對當前redo損壞,又沒有備份,資料庫處於非歸檔模式時,只能通過加入隱含引數方式恢復!

一般步驟如下:

1:首先加入_ALLOW_RESETLOGS_CORRUPTION = TRUE隱含引數,最後resetlogs開啟資料庫,如果無法開啟,進入第二步。

2:檢視日誌資訊,根據具體報錯資訊,確認方法,本例是出現ORA-00600: internal error code, arguments: [2662], [0], [2433141], [0], [2443300], [12595947], [], []

ORA-600 [2662] "Block SCN is ahead of Current SCN",說明當前資料庫的資料塊的SCN早於當前的SCN,主要是和儲存在UGA變數中的dependent SCN進行比較,如果當前的SCN小於它,資料庫就會產生這個ORA-600 [2662]的錯誤了.於是想到使用ADJUST_SCN事件來調整當前的SCN,使其大於dependent SCN. 此時我們可以通過Oracle的內部事件來調整SCN:

解決這個問題一般方法是: 調整SCN有兩種常用方法: 1.通過immediate trace name方式(在資料庫Open狀態下,即通過用_allow_resetlogs_corruption=TRUE隱含引數開啟資料庫之後報錯600) alter session set events 'IMMEDIATE trace name ADJUST_SCN level x'; 2.通過10015事件(在資料庫無法開啟,mount狀態下) alter session set events '10015 trace name adjust_scn level x'; 注:level 1為增進SCN 10億 (1 billion) (1024*1024*1024),通常Level 1已經足夠。也可以根據實際情況適當調整。

本文通過此種方法設定無效,scn沒有得到提升!

3:一般情況下redo損壞的時候,undo資料也大都不一致,因此通過scn調整完畢,resetlogs資料庫後還會出現ORA-00600: internal error code, arguments: [4194]錯誤,這個錯誤可以通過設定undo解決:

設定隱含引數:_corrupted_rollback_segments 將undo改變成手工管理的,然後重啟資料庫,

本例只是將undo改變成手工管理,問題解決。