原文http://blog.csdn.net/tianlesoftware/article/details/5156507
前提条件
1. 归档模式下。
2. 数据文件在当前控制文件之后创建。 否则会报ORA-01178错误。
ORA-01178: file 5 created before last CREATE CONTROLFILE, cannot recreate
ORA-01110: data file 5: 'D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/USERS01.DBF'
因为只有控制文件中包含了丢失文件信息,才可以通过create datafile方式重新创建文件,通过控制文件中记录的文件信息、SCN、检查点等信息,应用归档日志进行恢复,完成完全恢复.
操作步骤:
1 以MOUNT方式启动:
STARTUP MOUNT
2. 使破坏的数据文件离线:
ALTER DATABASE DATAFILE '----' OFFLINE;
3 打开数据库:
ALTER DATABASE OPEN;
4 创建一个新的控制的数据文件,要求和原文件大小,路径,名称都相同.
SQL> alter database create datafile 'D:/DAVE/TEST.DBF' as 'D:/DAVE/TEST.DBF';
5 对新数据文件实施恢复:
RECOVER DATAFILE '----';
6 使数据文件在线:
ALTER DATAFILE '----' ONLINE;
查看数据文件状态
SQL> select file#,status,name from v$datafile;
切换归档模式
SQL> startup mount;
SQL> alter database archivelog;
SQL> shutdown immediate;
测试用例:
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/SYSTEM01.DBF
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/UNDOTBS01.DBF
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/SYSAUX01.DBF
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/USERS01.DBF
D:/DAVE/DAVE.DBF
SQL> create tablespace test datafile 'D:/DAVE/test.DBF' size 5m;
Tablespace created.
SQL> alter system switch logfile;
系统已更改。
SQL> create table t tablespace test as select * from dba_users;
表已创建。
SQL> alter system switch logfile;
系统已更改。
SQL> shutdown immediate;
D:/Dave>move test.dbf test.bak
SQL> startup
ORACLE instance started.
Total System Global Area 574619648 bytes
Fixed Size 1250236 bytes
Variable Size 197135428 bytes
Database Buffers 373293056 bytes
Redo Buffers 2940928 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: 'D:/DAVE/TEST.DBF'
SQL> select name from v$datafile;
NAME
----------------------------------------------------------
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/SYSTEM01.DBF
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/UNDOTBS01.DBF
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/SYSAUX01.DBF
D:/ORACLE/PRODUCT/10.2.0/ORADATA/ORCL/USERS01.DBF
D:/DAVE/DAVE.DBF
D:/DAVE/TEST.DBF
6 rows selected.
SQL> alter database create datafile 'D:/DAVE/TEST.DBF';
Database altered.
SQL> recover datafile 'D:/DAVE/TEST.DBF';
Media recovery complete.
SQL> alter database open;