以下操作代码的流程是配的,但是相应的文件名,啥的 必须改动。
故障现象
数据文件被误删除
具体情况
接到反馈说,数据文件data20120512.dbf被误删除,需要恢复
数据库提示
ERROR at line 1:
ORA-01116: error in opening database file 16ORA-01110: data file 16:‘/u01/app/oracle/product/11.2.0/oradata/ebridge/data20120512.dbfORA-27041: unable to open fileLinux Error: 2: No such file or directoryAdditional information: 3数据库还没有被关闭
解决过程
恢复的原理是,在Linux操作系统中,如果文件从操作系统级别被rm掉,之前打开该文件的进程仍然持有相应的文件句柄,所指向的文件仍然可以读写,并且该文件的文件描述符可以从/proc目录中获得。但是要注意的是,此时如果关闭数据库,则此句柄会消失.
检查dbwr的进程PID
[root@jingyong ~]# ps -ef|grep dbw0|grep -v greporacle 2236 1 0 06:40 ? 00:00:01 ora_dbw0_jingyongdbwr会打开所有数据文件的句柄。在proc目录中可以查到,目录名是进程PID,fd表示文件描述符
[root@jingyong ~]# cd /proc/2236/fd[root@jingyong fd]# ls -l
total 0lr-x—— 1 oracle oinstall 64 May 31 08:15 0 -> /dev/nulll-wx—— 1 oracle oinstall 64 May 31 08:15 1 -> /dev/nulll-wx—— 1 oracle oinstall 64 May 31 08:15 10 -> /u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_2213.trcl-wx—— 1 oracle oinstall 64 May 31 08:15 11 -> /u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_2213.trmlr-x—— 1 oracle oinstall 64 May 31 08:15 12 -> /u01/app/oracle/product/11.2.0/db/rdbms/mesg/oraus.msblr-x—— 1 oracle oinstall 64 May 31 08:15 13 -> /dev/zerolr-x—— 1 oracle oinstall 64 May 31 08:15 14 -> /proc/2236/fdlr-x—— 1 oracle oinstall 64 May 31 08:15 15 -> /dev/zerolrwx—— 1 oracle oinstall 64 May 31 08:15 16 -> /u01/app/oracle/product/11.2.0/db/dbs/hc_jingyong.datlrwx—— 1 oracle oinstall 64 May 31 08:15 17 -> /u01/app/oracle/product/11.2.0/db/dbs/lkJINGYONGlrwx—— 1 oracle oinstall 64 May 31 08:15 18 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/control01.ctllrwx—— 1 oracle oinstall 64 May 31 08:15 19 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/control02.ctll-wx—— 1 oracle oinstall 64 May 31 08:15 2 -> /dev/nulllrwx—— 1 oracle oinstall 64 May 31 08:15 20 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbflrwx—— 1 oracle oinstall 64 May 31 08:15 21 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbflrwx—— 1 oracle oinstall 64 May 31 08:15 22 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbflrwx—— 1 oracle oinstall 64 May 31 08:15 23 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf (deleted)lrwx—— 1 oracle oinstall 64 May 31 08:15 24 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/example01.dbflrwx—— 1 oracle oinstall 64 May 31 08:15 25 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbflrwx—— 1 oracle oinstall 64 May 31 08:15 26 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/temp01.dbflr-x—— 1 oracle oinstall 64 May 31 08:15 27 -> /u01/app/oracle/product/11.2.0/db/rdbms/mesg/oraus.msbl-wx—— 1 oracle oinstall 64 May 31 08:15 3 -> /u01/app/oracle/product/11.2.0/db/rdbms/log/jingyong_ora_2213.trclr-x—— 1 oracle oinstall 64 May 31 08:15 4 -> /dev/nulllr-x—— 1 oracle oinstall 64 May 31 08:15 5 -> /dev/nulllr-x—— 1 oracle oinstall 64 May 31 08:15 6 -> /dev/nulllrwx—— 1 oracle oinstall 64 May 31 08:15 7 -> /u01/app/oracle/product/11.2.0/db/dbs/hc_jingyong.dat注意其中”/u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf (deleted)”字样,表示该文件已经被删除,
直接cp该句柄文件名回原位置注意(这一步先略过,执行下一步,如果下一步报错如 : cp: cannot create symbolic link `/u01/app/oracle/dradata/orcl/demo01.dbf': No such file or directory,再放过来执行这一步) ———————— : [root@jingyong ]# mkdir -p /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf
[root@jingyong fd]# cp -R 23 /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf
进行数据文件恢复
[oracle@jingyong ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Fri May 31 08:24:35 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> alter database datafile 4 offline;
Database altered.
SQL> recover datafile 4;
Media recovery complete.SQL> alter database datafile 4 online;Database altered.