沒有備份、只有歸檔日志,如何恢復數據文件
2024-07-21 02:35:41
供稿:網友
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;
假如是非歸檔模式,也可以運用以上方法,
前提是:輸入記錄所占空間的大小不超過所有聯機日志文件的大小
即:用聯機日志文件來恢復