场景描述:在数据库尚在运行的情况下,数据文件被误删除,此时根据数据库正在运行的进程进行恢复,因为在数据库还在运行当中执行rm删除数据文件,并不是真正的删除。
注意:数据文件删除后不要关闭数据库。
恢复演示
1.删除数据文件
rm -rf /opt/oracle/oradata/ORCLCDB/users01.dbf
2.查看数据库dbw进程pid
[oracle@instance-ej1hspdt ~]$ ps -ef | grep dbw
oracle 13859 13538 0 02:51 pts/0 00:00:00 grep --color=auto dbw
oracle 22831 1 0 Sep05 ? 00:01:48 ora_dbw0_ORCLCDB
3.根据进程pid在/proc/pid/fd目录找寻删除的数据文件
1.注意系统屏幕显示红色并且后面标注(deleted)字样的为删除的文件
[oracle@instance-ej1hspdt ~]$ cd /proc/22831/fd/
[oracle@instance-ej1hspdt fd]$ ls -ltr
total 0
lr-x------ 1 oracle oinstall 64 Sep 11 02:52 8 -> /opt/oracle/product/18c/dbhome_1/rdbms/mesg/oraus.msb
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 7 -> /opt/oracle/product/18c/dbhome_1/dbs/lkORCLCDB
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 6 -> /opt/oracle/product/18c/dbhome_1/dbs/hc_ORCLCDB.dat
lr-x------ 1 oracle oinstall 64 Sep 11 02:52 5 -> /proc/22831/fd
lr-x------ 1 oracle oinstall 64 Sep 11 02:52 4 -> /opt/oracle/product/18c/dbhome_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Sep 11 02:52 3 -> /dev/null
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 274 -> /opt/oracle/oradata/ORCLCDB/pdbseed/temp012019-08-09_11-51-17-153-AM.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 273 -> /opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 272 -> /opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 271 -> /opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 270 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_temp3_goyqsl8r_.tmp
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 269 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_temp2_goyqsl41_.tmp
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 268 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_temp1_goyo6hlk_.tmp
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 267 -> /opt/oracle/oradata/ORCLCDB/temp01.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 266 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_fixf_gphjvk84_.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 265 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_shadow_gpcsfzpt_.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 264 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_undotbs0_gp1qljq8_.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 263 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_undotbs0_gp1qjjvg_.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 262 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_undotbs0_gp1m3g1f_.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 261 -> /opt/oracle/oradata/ORCLCDB/ORCLCDB/datafile/o1_mf_whs01_gopv7wd5_.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 260 -> /opt/oracle/oradata/ORCLCDB/users01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 259 -> /opt/oracle/oradata/ORCLCDB/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 258 -> /opt/oracle/oradata/ORCLCDB/system01.dbf
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 257 -> /opt/oracle/oradata/ORCLCDB/control02.ctl
lrwx------ 1 oracle oinstall 64 Sep 11 02:52 256 -> /opt/oracle/oradata/ORCLCDB/control01.ctl
l-wx------ 1 oracle oinstall 64 Sep 11 02:52 2 -> /dev/null
l-wx------ 1 oracle oinstall 64 Sep 11 02:52 1 -> /dev/null
lr-x------ 1 oracle oinstall 64 Sep 11 02:52 0 -> /dev/null
4.进行cp 恢复,之后最好进行一致性关闭shudown immediate;
[oracle@instance-ej1hspdt fd]$ cp 260 /opt/oracle/oradata/ORCLCDB/users01.dbf