沒有備份只有歸檔日志如何恢復數據文件
2024-07-21 02:36:21
供稿:網友
系統環境:
1、操作系統:windows 2000 Server,機器內存128M
2、數據庫: Oracle 8i R2 (8.1.6) for NT 企業版
3、安裝路徑:C:/ORACLE
模擬現象:
可通過重建數據文件來恢復,前提是歸檔日志文件保存完整
先將數據庫設置為歸檔模式
SQL*Plus
conn system/manager
--創建實驗表空間
create tablespace test datafile
'c:/test.ora' size 5M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED
default storage (initial 128K next 1M pctincrease 0)
/
--創建實驗用戶
drop user test cascade;
create user test identified by test default tablespace test;
grant connect,resource to test;
conn test/test
create table a(a number);
insert into a values(1);
insert into a select * from a; --反復插入,達到100萬條
commit;
--關閉數據庫
SVRMGR> connect internal
SVRMGR> alter system switch logfile; --強制歸檔
SVRMGR> alter system switch logfile;
SVRMGR> alter system switch logfile;
SVRMGR> shutdown
--操作系統下刪除test.ora文件
--重新啟動數據庫
SVRMGR> connect internal
SVRMGR> startup
這時,可以mount上,但無法打開,因為數據文件test.ora不存在,
顯示錯誤如下:
ORA-01157: ????/?????? 8 - ??? DBWR ????
ORA-01110: ???? 8: 'C:/TEST.ORA'
SVRMGR> connect internal
SVRMGR> startup mount
SVRMGR> alter database create datafile 'c:/test.ora';
SVRMGR> set autorecovery on
SVRMGR> recover datafile 'c:/test.ora';
SVRMGR> alter database open;
conn test/test
select count(*) from a; --數據又恢復到100萬條
--刪除實驗表空間
conn system/manager
alter tablespace test offline;
drop tablespace test INCLUDING CONTENTS;
drop user test;
--假如是非歸檔模式,也可以運用以上方法,
--前提是:輸入記錄所占空間的大小不超過所有聯機日志文件的大小
--即:用聯機日志文件來恢復