准备工作 按照下面的输入,如果全部恢复,应该可以看到insert into test1 values(13),因为insert into test1 values(14)没提交。
SQL> conn lunar/lunar
SQL> insert into test1 values(13);
SQL> insert into test1 values(14);
Shutdown immediate,然后模拟数据文件丢失
单开一个session,执行shutdown immediate(保证insert into test1 values(14);没有被隐式提交)
E:\>sqlplus internal
SQL>shutdown immediate
ORACLE 例程已经关闭。
模拟数据文件丢失,然后用热备覆盖这个文件
mount数据库
E:\>sqlplus internal
SQL>shutdown immediate
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
SQL> startup mount
使损坏的数据文件脱机
SQL>alter database datafile 'D:\BACKUPDB\USERS01.DBF' offline;
Database altered.
恢复数据文件
SQL> recover datafile 'D:\BACKUPDB\USERS01.DBF';
ORA-00279: change 424116 generated at 10/20/2002 20:42:04 needed for thread 1
ORA-00289: suggestion : D:\BACKUPDB\ARCHIVE\BACKUPT001S00001.ARC
ORA-00280: change 424116 for thread 1 is in sequence #1
Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 424125 generated at 10/20/2002 20:44:14 needed for thread 1
ORA-00289: suggestion : D:\BACKUPDB\ARCHIVE\BACKUPT001S00002.ARC
ORA-00280: change 424125 for thread 1 is in sequence #2
ORA-00278: log file 'D:\BACKUPDB\ARCHIVE\BACKUPT001S00001.ARC' no longer needed
for this recovery
⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
Log applied.
Media recovery complete.
使恢复的数据文件联机
SQL>alter database datafile 'D:\BACKUPDB\USERS01.DBF' online;
打开数据库
SQL>alter database open;
Database altered.
这时需要重新启动数据库,并完全恢复数据库
SQL> conn lunar/lunar
SQL> select count(*) from test;
select count(*) from test
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> conn internal
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
重新启动数据库,
SQL> startup
ORACLE instance started.
用recover database再次恢复数据库
SQL> conn internal
SQL> recover database;
ORA-00283: recovery session canceled due to errors
ORA-01124: cannot recover data file 1 - file is in use or recovery
ORA-01110: data file 1: 'D:\BACKUPDB\SYSTEM01.DBF'
重新使恢复的表空间联机
SQL> alter database datafile 'D:\BACKUPDB\USERS01.DBF' online;
SQL> conn lunar/lunar
SQL> select * from test1; ok.
验证恢复结果:完全恢复
说明:
1. 用热备覆盖这个文件
2. mount数据库
3. 使损坏的数据文件脱机
4. 恢复数据文件
5. 使恢复的数据文件联机
6. 打开数据库
7. 这时需要重新启动数据库,并完全恢复数据库
8. 重新启动数据库,
9. 用recover database再次恢复数据库
10. 重新使恢复的表空间联机