ORACLE 常見故障恢復(fù)
故障現(xiàn)象
丟失某個數(shù)據(jù)庫文件,造成了數(shù)據(jù)庫無法啟動,同時數(shù)據(jù)庫處于非歸檔模式,也沒有冷備份,啟動時的錯誤信息如下:
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: 'D:ORACLEORADATATESTUSERS01.DBF'
l解決方法
將數(shù)據(jù)庫啟動到mount狀態(tài)下:
SQLplus “/ as sysdba”
startup mount
從數(shù)據(jù)庫中刪除該數(shù)據(jù)文件
alter database datafile ‘xx’ offline drop;
打開數(shù)據(jù)庫
alter database open;
備注:
該方法可正常打開數(shù)據(jù)庫,但該datafile中的數(shù)據(jù)將丟失
如果誤刪除了system表空間的datafile,則該方法不奏效
如果該表空間還包含其它數(shù)據(jù)文件,用EXP把數(shù)據(jù)備份出來,然后刪除表空間,重建表空間,將數(shù)據(jù)導(dǎo)入。如果不包含其它數(shù)據(jù)文件,則直接刪除表空間就可以了。
二.歸檔模式數(shù)據(jù)庫丟失某數(shù)據(jù)文件,無備份,但有該數(shù)據(jù)文件創(chuàng)建以來的歸檔日志
l故障現(xiàn)象
歸檔模式的數(shù)據(jù)庫,丟失了某個數(shù)據(jù)庫文件,造成了數(shù)據(jù)庫無法啟動,同時沒有數(shù)據(jù)庫的全備份,但有該數(shù)據(jù)文件創(chuàng)建以來的歸檔日志,數(shù)據(jù)庫無法啟動:
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: 'D:ORACLEORADATATESTUSERS01.DBF
l解決方法
啟動數(shù)據(jù)庫到mount狀態(tài)
startup mount
手工創(chuàng)建丟失的數(shù)據(jù)文件
alter database create datafile ‘oldfname’ as ‘newfname’size xxx reuse;
利用歸檔日志對數(shù)據(jù)文件進(jìn)行恢復(fù)
recover datafile ‘newfname’;或者
recover datafile n;
打開數(shù)據(jù)庫
alter database open;
備注:
該方法可正常打開數(shù)據(jù)庫,而且不會丟失數(shù)據(jù)
該方法有兩個前提
丟失的數(shù)據(jù)文件不能是系統(tǒng)文件
不能丟失或損壞控制文件
三.非current和active的redo log損壞
l故障現(xiàn)象
誤刪除了redo log,或者redo log被損壞,數(shù)據(jù)庫能mount,不能open:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/oracle10/oradata/ora10g/redo03.log'
l解決方法
查詢v$log視圖,確認(rèn)損壞的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
如果該日志已經(jīng)歸檔,用下面的命令清除日志內(nèi)容
Alter database clear logfile group 3;
如果該日志沒有歸檔,用下面的命令清除日志內(nèi)容
Alter database clear unarchived logfile group 3;
打開數(shù)據(jù)庫
Alter database open;
盡快做一個數(shù)據(jù)庫全備份
四.current或active的redo log損壞
l故障現(xiàn)象
誤刪除了redo log,或者redo log被損壞,數(shù)據(jù)庫不能打開:
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視圖,確認(rèn)損壞的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:當(dāng)前日志文件還存在,只是邏輯損壞,并且當(dāng)前日志沒有未決事務(wù)需要實(shí)例恢復(fù)
alter database clear unarchived logfile group 2; --不會報錯
recover database until cancel;
alter database open resetlogs;
一般情況下,該方法不奏效,如果clear報錯,則用其它方法.
情況2:當(dāng)前日志完全損壞,且有未決事務(wù),數(shù)據(jù)庫有備份
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;
盡快做一個數(shù)據(jù)庫全備份
情況3:當(dāng)前日志完全損壞,且有未決事務(wù),數(shù)據(jù)庫無備份
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
盡快做一個數(shù)據(jù)庫全備份
五.臨時表空間的數(shù)據(jù)文件損壞
l故障現(xiàn)象
臨時表空間的數(shù)據(jù)文件發(fā)生損壞,系統(tǒng)出現(xiàn)故障,如何恢復(fù)
l解決方法
在10g及以上版本數(shù)據(jù)庫,啟動數(shù)據(jù)庫時,如果發(fā)現(xiàn)臨時數(shù)據(jù)文件損壞,會自動創(chuàng)建,如果在數(shù)據(jù)庫運(yùn)行過程中,可以手工重建:
create temporary tablespace temp1 tempfile ‘xx’ size xx’;
alter database default temporary tablespace temp1;--系統(tǒng)默認(rèn)臨時表空間的重建需要執(zhí)行這一步,否則不需要
drop tablespace temp;
alter tablespace temp1 rename to temp;
在10g以前版本數(shù)據(jù)庫,可以在數(shù)據(jù)庫打開后或運(yùn)行過程中,手工重建就可以了
alter database datafile ‘xxx’ offline drop;--如果數(shù)據(jù)庫打不開,就執(zhí)行這個步驟
create temporary tablespace temp1 tempfile ‘xx’ size xx’;
alter database default temporary tablespace temp1;--系統(tǒng)默認(rèn)臨時表空間的重建需要執(zhí)行這一步 ,否則不需要,9i以前版本也不需要。
drop tablespace temp;
alter tablespace temp1 rename to temp;
六.UNDO數(shù)據(jù)文件損壞,數(shù)據(jù)庫無法啟動
l故障現(xiàn)象
Undo數(shù)據(jù)文件發(fā)生了丟失或損壞,數(shù)據(jù)庫啟動報錯:
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
ORA-01110: data file 2: '/oracle10/oradata/ora10g/undotbs01.dbf'
l解決方法
如果數(shù)據(jù)庫有備份,則利用備份進(jìn)行恢復(fù)
如果數(shù)據(jù)庫沒有備份,則利用重建undo表空間的方式進(jìn)行恢復(fù)
startup mount
alter database datafile n offline drop;(刪除損壞的undo文件)
alter database open;
create undo tablespace xxx …; (創(chuàng)建一個新的undo表空間)
alter system set undo_tablespace=xxx;(指向新的undo表空間)
drop tablespace yyy including contents;(刪除原來的undo表空間)
七.控制文件損壞
l故障現(xiàn)象
控制文件發(fā)生了損壞,數(shù)據(jù)庫已經(jīng)無法啟動,報錯信息如下:
ORA-00202: controlfile: 'D:Oracleoradatachencontrol01.ctl'
ORA-27041: unable to open file
OSD-04002: unable to open file
l解決方法
情況一:控制文件有鏡像,且鏡像控制文件沒有被損壞
關(guān)閉數(shù)據(jù)庫
將沒有損壞的控制文件覆蓋掉損壞的控制文件,或者修改參數(shù)文件的control_files參數(shù),去掉損壞的控制文件
重新啟動數(shù)據(jù)庫
情況二:控制文件無鏡像,或者鏡像的所有控制文件都損壞了
恢復(fù)控制文件
如果控制文件有備份,從備份中恢復(fù)控制文件
restore controlfile from ‘
如果控制文件有snapshot,將snapshot控制文件替換掉原損壞控制文件
如果做過alter database backup controlfile to trace的控制文件腳本備份,可以用trace文件中的重建腳本來創(chuàng)建控制文件,
如果沒有備份,也沒有trace備份,只能手工編寫腳本創(chuàng)建控制文件,前提是你對數(shù)據(jù)庫文件結(jié)構(gòu)非常清楚
恢復(fù)和打開數(shù)據(jù)庫
如果是用create controlfile …noresetlogs 方式重建的控制文件
recover database;
alter database open;
alter tablespace temp add tempfile ‘xx’ size xx reuse ; --對所有臨時表空間做此操作
如果是用create controlfile …resetlogs方式重建的控制文件,或者通過備份或快照恢復(fù)的控制文件
recover database using backup controlfile;
alter database open resetlogs;
下一篇:oracle 異機(jī)恢復(fù)小記