Oracle數(shù)據(jù)庫RMAN恢復(fù)之?dāng)?shù)據(jù)文件的恢復(fù)詳解
Oracle數(shù)據(jù)庫REAN恢復(fù)之數(shù)據(jù)文件的恢復(fù)是本文我們主要要介紹的內(nèi)容,我們知道,除了system表空間的數(shù)據(jù)文件(mount)之外,其它數(shù)據(jù)文件可以在open(mount也可以)狀態(tài)下恢復(fù)。open狀態(tài)下恢復(fù)數(shù)據(jù)文件可以減少數(shù)據(jù)庫停用的時(shí)間,所以應(yīng)該在open狀態(tài)下恢復(fù)這些數(shù)據(jù)文件。
示例一:數(shù)據(jù)文件被誤刪除
數(shù)據(jù)庫關(guān)閉狀態(tài)下刪除非系統(tǒng)表空間數(shù)據(jù)文件。
啟動(dòng)數(shù)據(jù)庫到mount狀態(tài)。
脫機(jī)丟失的數(shù)據(jù)文件,alter database datafile n offline。
打開數(shù)據(jù)庫,alter database open。
轉(zhuǎn)儲(chǔ)數(shù)據(jù)文件,restore datafile n。
使用recover datafile n 應(yīng)用歸檔日志。
聯(lián)機(jī)數(shù)據(jù)文件,alter database datafile n online。
--數(shù)據(jù)庫關(guān)閉狀態(tài)下刪除非系統(tǒng)表空間數(shù)據(jù)文件。
- [oracle@localhost ~]$ rm $ORACLE_BASE/product/10.2.0/oradatabak/example01.dbf;
- SQL> select file#,error from v$recover_file;
- FILE# ERROR
- ---------- -----------------------------------------------------------------
- 5 FILE NOT FOUND
- SQL> select file#,name from v$datafile where file#=5;
- FILE# NAME
- ---------- --------------------------------------------------------------------------------
- 5 /oracle/10g/oracle/product/10.2.0/oradatabak/example01.dbf
- --恢復(fù)數(shù)據(jù)文件
- RMAN> run {
- startup force mount;
- sql 'alter database datafile 5 offline';
- sql 'alter database open';
- restore datafile 5;
- recover datafile 5;
- sql 'alter database datafile 5 online';
- 8> }
示例二:數(shù)據(jù)文件所在磁盤出現(xiàn)損壞
數(shù)據(jù)庫關(guān)閉狀態(tài)下刪除非系統(tǒng)表空間數(shù)據(jù)文件。
啟動(dòng)數(shù)據(jù)庫到mount狀態(tài)。
脫機(jī)丟失的數(shù)據(jù)文件,alter database datafile n offline。
打開數(shù)據(jù)庫,alter database open。
在restore database之前,執(zhí)行set newname為數(shù)據(jù)文件指定新的位置。
在restore database之后,執(zhí)行switch datafile改變控制文件中數(shù)據(jù)文件位置和名稱。
之后通過執(zhí)行recover database應(yīng)用歸檔日志。
聯(lián)機(jī)數(shù)據(jù)文件,alter database datafile n online。
--數(shù)據(jù)庫關(guān)閉狀態(tài)下刪除非系統(tǒng)表空間數(shù)據(jù)文件。
- [oracle@localhost ~]$ rm $ORACLE_BASE/product/10.2.0/oradatabak/example01.dbf;
- SQL> select file#,error from v$recover_file;
- FILE# ERROR
- ---------- -----------------------------------------------------------------
- 5 FILE NOT FOUND
- SQL> select file#,name from v$datafile where file#=5;
- FILE# NAME
- ---------- --------------------------------------------------------------------------------
- 5 /oracle/10g/oracle/product/10.2.0/oradatabak/example01.dbf
- --恢復(fù)數(shù)據(jù)文件
- [oracle@localhost ~]$ rman target sys/oracle@oralife nocatalog
- RMAN> run {
- 2> startup force mount;
- 3> sql 'alter database datafile 5 offline';
- 4> sql 'alter database open';
- 5> set newname for datafile 5 to '$ORACLE_BASE/product/10.2.0/oradata/oralife/example01.dbf';
- 6> restore datafile 5;
- 7> switch datafile 5;
- 8> recover datafile 5;
- 9> sql 'alter database datafile 5 online';
- 10> }
- SQL> select file#,name from v$datafile where file#=5;
- FILE# NAME
- ---------- --------------------------------------------------------------------------------
- 5 /oracle/10g/oracle/product/10.2.0/oradata/oralife/example01.dbf
- SQL> select file#,error from v$recover_file;
- no rows selected
關(guān)于Oracle數(shù)據(jù)庫RMAN恢復(fù)之?dāng)?shù)據(jù)文件的恢復(fù)的相關(guān)知識(shí)就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!
【編輯推薦】






