以下操作代码的流程是配的,但是相应的文件名,啥的 必须改动。
故障现象
数据文件被误删除
具体情况
接到反馈说,数据文件data20120512.dbf被误删除,需要恢复
数据库提示
ERROR at line 1:
ORA-01116: error in opening database file 16
ORA-01110: data file 16:
‘/u01/app/oracle/product/11.2.0/oradata/ebridge/data20120512.dbf
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
数据库还没有被关闭
解决过程
恢复的原理是,在Linux操作系统中,如果文件从操作系统级别被rm掉,之前打开该文件的进程仍然持有相应的文件句柄,所指向的文件仍然可以读写,并且该文件的文件描述符可以从/proc目录中获得。但是要注意的是,此时如果关闭数据库,则此句柄会消失.
检查dbwr的进程PID
[[email protected] ~]# ps -ef|grep dbw0|grep -v grep
oracle 2236 1 0 06:40 ? 00:00:01 ora_dbw0_jingyong
dbwr会打开所有数据文件的句柄。在proc目录中可以查到,目录名是进程PID,fd表示文件描述符
[[email protected] ~]# cd /proc/2236/fd
[[email protected] fd]# ls -l
total 0
lr-x—— 1 oracle oinstall 64 May 31 08:15 0 -> /dev/null
l-wx—— 1 oracle oinstall 64 May 31 08:15 1 -> /dev/null
l-wx—— 1 oracle oinstall 64 May 31 08:15 10 -> /u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_2213.trc
l-wx—— 1 oracle oinstall 64 May 31 08:15 11 -> /u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_2213.trm
lr-x—— 1 oracle oinstall 64 May 31 08:15 12 -> /u01/app/oracle/product/11.2.0/db/rdbms/mesg/oraus.msb
lr-x—— 1 oracle oinstall 64 May 31 08:15 13 -> /dev/zero
lr-x—— 1 oracle oinstall 64 May 31 08:15 14 -> /proc/2236/fd
lr-x—— 1 oracle oinstall 64 May 31 08:15 15 -> /dev/zero
lrwx—— 1 oracle oinstall 64 May 31 08:15 16 -> /u01/app/oracle/product/11.2.0/db/dbs/hc_jingyong.dat
lrwx—— 1 oracle oinstall 64 May 31 08:15 17 -> /u01/app/oracle/product/11.2.0/db/dbs/lkJINGYONG
lrwx—— 1 oracle oinstall 64 May 31 08:15 18 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/control01.ctl
lrwx—— 1 oracle oinstall 64 May 31 08:15 19 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/control02.ctl
l-wx—— 1 oracle oinstall 64 May 31 08:15 2 -> /dev/null
lrwx—— 1 oracle oinstall 64 May 31 08:15 20 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbf
lrwx—— 1 oracle oinstall 64 May 31 08:15 21 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbf
lrwx—— 1 oracle oinstall 64 May 31 08:15 22 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbf
lrwx—— 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.dbf
lrwx—— 1 oracle oinstall 64 May 31 08:15 25 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbf
lrwx—— 1 oracle oinstall 64 May 31 08:15 26 -> /u01/app/oracle/product/11.2.0/oradata/jingyong/temp01.dbf
lr-x—— 1 oracle oinstall 64 May 31 08:15 27 -> /u01/app/oracle/product/11.2.0/db/rdbms/mesg/oraus.msb
l-wx—— 1 oracle oinstall 64 May 31 08:15 3 -> /u01/app/oracle/product/11.2.0/db/rdbms/log/jingyong_ora_2213.trc
lr-x—— 1 oracle oinstall 64 May 31 08:15 4 -> /dev/null
lr-x—— 1 oracle oinstall 64 May 31 08:15 5 -> /dev/null
lr-x—— 1 oracle oinstall 64 May 31 08:15 6 -> /dev/null
lrwx—— 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,再放过来执行这一步) ———————— : [[email protected] ]# mkdir -p /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf
[[email protected] fd]# cp -R 23 /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf
进行数据文件恢复
[[email protected] ~]$ sqlplus / as sysdba
SQL*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 – Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database datafile 4 offline;
Database altered.
SQL> recover datafile 4;
Media recovery complete.
SQL> alter database datafile 4 online;
Database altered.