ORACLE 常見故障恢復

murkey發表於2013-12-18
一.非歸檔模式的,丟失資料檔案

l故障現象
?丟失某個資料庫檔案,造成了資料庫無法啟動,同時資料庫處於非歸檔模式,也沒有冷,啟動時的錯誤資訊如下:
ORA-01157: cannot identify/lock  file 3 - see DBWR trace file
ORA-01110: data file 3: 'D:\ORACLE\ORADATA\TEST\USERS01.DBF'
l解決方法
?將資料庫啟動到mount狀態下:
?sqlplus “/ as sysdba”
?startup mount
?從資料庫中刪除該資料檔案
?alter  datafile ‘xx’ offline drop;
?開啟資料庫
?alter database open;
?備註:
?該方法可正常開啟資料庫,但該datafile中的資料將丟失
?如果誤刪除了system表空間的datafile,則該方法不奏效
?如果該表空間還包含其它資料檔案,用EXP把資料備份出來,然後刪除表空間,重建表空間,將資料匯入。如果不包含其它資料檔案,則直接刪除表空間就可以了。

二.歸檔模式資料庫丟失某資料檔案,無備份,但有該資料檔案建立以來的歸檔日誌

l故障現象
?歸檔模式的資料庫,丟失了某個資料庫檔案,造成了資料庫無法啟動,同時沒有資料庫的全備份,但有該資料檔案建立以來的歸檔日誌,資料庫無法啟動:
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: 'D:\ORACLE\ORADATA\TEST\USERS01.DBF
l解決方法
?啟動資料庫到mount狀態
?startup mount
?手工建立丟失的資料檔案
?alter database create datafile ‘oldfname’ as  ‘newfname’size xxx reuse;
?利用歸檔日誌對資料檔案進行
?recover datafile ‘newfname’;或者
?recover datafile  n;
?開啟資料庫
?alter database open;
?備註:
?該方法可正常開啟資料庫,而且不會丟失資料
?該方法有兩個前提
?丟失的資料檔案不能是系統檔案
?不能丟失或損壞控制檔案

三.非currentactiveredo log損壞

l故障現象
?誤刪除了redo log,或者redo log被損壞,資料庫能mount,不能open:
ORA-00313: open failed  members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/oracle10/oradata/ora10g/redo03.log'
l解決方法
?查詢v$log檢視,確認損壞的redo log group是非current和active
?SQL>select group#,thread#,sequence#, archived,status from v$log;
GROUP#  THREAD#  SEQUENCE#  ARCHIVED STATUS 
------       -------          ----------            --------           --------
1                1                103                  YES      INACTIVE
2                1                104                  NO       CURRENT
3                1                102                  YES      INACTIVE
?如果該日誌已經歸檔,用下面的命令清除日誌內容
?Alter database clear logfile group 3;
?如果該日誌沒有歸檔,用下面的命令清除日誌內容
?Alter database clear unarchived logfile group 3;
?開啟資料庫
?Alter database open;
?儘快做一個資料庫全備份

四.currentactiveredo log損壞

l故障現象
?誤刪除了redo log,或者redo log被損壞,資料庫不能開啟:
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/oracle10/oradata/ora10g/redo02.log'
l解決方法
?查詢v$log檢視,確認損壞的redo log group是current或active
?SQL>select group#,thread#,sequence#, archived,status from v$log;
GROUP#  THREAD#  SEQUENCE#  ARCHIVED STATUS 
------       -------          ----------            --------           --------
1                1                    2                      YES      INACTIVE
2                1                    4                      NO       CURRENT
3                1                    3                      YES      INACTIVE
?情況1:當前日誌檔案還存在,只是邏輯損壞,並且當前日誌沒有未決事務需要例項恢復
?alter database clear unarchived logfile group 2;  --不會報錯
?recover database until cancel;
?alter database open resetlogs;
?一般情況下,該方法不奏效,如果clear報錯,則用其它方法.
?情況2:當前日誌完全損壞,且有未決事務,資料庫有備份
?alter database clear unarchived logfile group 2;  --會報錯
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of thread 1
?restore database;
?recover database until cancel; --選擇auto
?recover database until cancel;
?alter datbase open resetlogs;
?儘快做一個資料庫全備份
?情況3:當前日誌完全損壞,且有未決事務,資料庫無備份
?shutdown immediate;
?_allow_resetlogs_corruption=true;
?startup mount pfile=‘xxx’;
?recover database until cancel;
?alter datbase open resetlogs;
?shutdown immediate
?_allow_resetlogs_corruption=true;
?Startup
?儘快做一個資料庫全備份

五.臨時表空間的資料檔案損壞

l故障現象
?臨時表空間的資料檔案發生損壞,系統出現故障,如何恢復
l解決方法
?在及以上版本資料庫,啟動資料庫時,如果發現臨時資料檔案損壞,會自動建立,如果在資料庫執行過程中,可以手工重建:
?create temporary tablespace temp1 tempfile ‘xx’ size xx’;
?alter database default temporary tablespace temp1;--系統預設臨時表空間的重建需要執行這一步,否則不需要
?drop tablespace temp;
?alter tablespace temp1 rename to temp;
?在10g以前版本資料庫,可以在資料庫開啟後或執行過程中,手工重建就可以了
?alter database datafile ‘xxx’ offline drop;--如果資料庫打不開,就執行這個步驟
?create temporary tablespace temp1 tempfile ‘xx’ size xx’;
?alter database default temporary tablespace temp1;--系統預設臨時表空間的重建需要執行這一步 ,否則不需要,9i以前版本也不需要。
?drop tablespace temp;
?alter tablespace temp1 rename to temp;

六.UNDO資料檔案損壞,資料庫無法啟動

l故障現象
?Undo資料檔案發生了丟失或損壞,資料庫啟動報錯:
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
ORA-01110: data file 2: '/oracle10/oradata/ora10g/undotbs01.dbf'
l解決方法
?如果資料庫有備份,則利用備份進行恢復
?如果資料庫沒有備份,則利用重建undo表空間的方式進行恢復
?startup mount
?alter database datafile n offline drop;(刪除損壞的undo檔案)
?alter database open;
?create undo tablespace xxx …; (建立一個新的undo表空間)
?alter system set undo_tablespace=xxx;(指向新的undo表空間)
?drop tablespace yyy including contents;(刪除原來的undo表空間)

七.控制檔案損壞

l故障現象
?控制檔案發生了損壞,資料庫已經無法啟動,報錯資訊如下:
ORA-00202: controlfile: 'D:\Oracle\oradata\chen\control01.ctl'
ORA-27041: unable to open file
OSD-04002: unable to open file
l解決方法
?情況一:控制檔案有映象,且映象控制檔案沒有被損壞
?關閉資料庫
?將沒有損壞的控制檔案覆蓋掉損壞的控制檔案,或者修改引數檔案的control_files引數,去掉損壞的控制檔案
?重新啟動資料庫

?情況二:控制檔案無映象,或者映象的所有控制檔案都損壞了
?恢復控制檔案
?如果控制檔案有備份,從備份中恢復控制檔案
restore controlfile from ‘’
?如果控制檔案有snapshot,將snapshot控制檔案替換掉原損壞控制檔案
?如果做過alter database backup controlfile to trace的控制檔案指令碼備份,可以用trace檔案中的重建指令碼來建立控制檔案,
?如果沒有備份,也沒有trace備份,只能手工編寫指令碼建立控制檔案,前提是你對資料庫檔案結構非常清楚
?恢復和開啟資料庫
?如果是用create controlfile …noresetlogs 方式重建的控制檔案
?recover database;
?alter database open;
?alter tablespace temp add tempfile ‘xx’ size xx reuse ; --對所有臨時表空間做此操
?如果是用create controlfile …resetlogs方式重建的控制檔案,或者透過備份或快照恢復的控制檔案
?recover database using backup controlfile;
?alter database open resetlogs;
?alter tablespace temp add tempfile ‘xx’ size xx reuse ; --對所有臨時表空間做此操

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

相關文章