来自大神 David http://blog.csdn.net/tianlesoftware/article/details/44082283
1 问题描述
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
2 创建测试数据
SQL> create tablespace test1 datafile '/oradata/ogg02/test1.dbf' size 100m;
Tablespace created.
Tablespace created.
User created.
Grant succeeded.
Table created.
Table created.
SQL> create table t3 as select * from all_users;
Table created.
3 归档模式处理
3.1 模拟故障
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oradata/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
[oracle@dg1 u01]$ rm -rf /oradata/ogg02/test1.dbf
*
ERROR at line 1:
ORA-01116: error in opening database file 7
ORA-01110: data file 7: '/oradata/ogg02/test1.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
至少从目前看,一切都是正常。 这里正常也是因为我们的操作系统是Linux,当数据文件从操作系统级别被rm掉,但之前打开该文件的进程仍然持有相应的文件句柄,所以指向的文件仍然可以读写,并且该文件的文件描述符可以从/proc目录中获得,也可以利用这个句柄恢复文件。如果在这个时候,重启了数据库或者操作系统,那么句柄就会消失,也就只能通过扫描磁盘进行文件恢复。
3.2 恢复
检查dbwr的进程PID:
[oracle@dg1 trace]$ ps -ef|grep dbw0
oracle 21884 1 0 19:05 ? 00:00:00 ora_dbw0_ogg02
[oracle@dg1 trace]$ cd /proc/21884/fd
这里的 265 就是我们删掉的数据文件。
//直接cp该句柄文件名回原位置:
[oracle@dg1 fd]$ cp 265 /oradata/ogg02/test1.dbf
因为数据库一直是open的,那么SCN也会不断的变化,我们cp出来的数据文件和数据库当前的信息不一致,所以我们需要进行recover:
SQL> alter database datafile'/oradata/ogg02/test1.dbf' offline;
Database altered.
SQL> recover datafile'/oradata/ogg02/test1.dbf'
ORA-01110: data file 7: '/oradata/ogg02/test1.dbf'
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
ORA-01110: data file 7: '/oradata/ogg02/test1.dbf'
1.查看这个数据文件有没有权限
Media recovery complete.
Database altered.
恢复正常。
//重启数据库:
ORACLE instance shut down.