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