客服微信
本文为云贝教育 刘峰 原创,请尊重知识产权,转发请注明出处,不接受任何抄袭、演绎和未经注明出处的转载。
前言
万一手滑把数据库的DBF文件误删除,千万不要关库!以下过程模拟如何通过文件句柄恢复被删除的数据文件
1、删除数据文件
[oracle@database oracle]$ cd /opt/oracle/oradata/ORCLCDB [oracle@database ORCLCDB]$ rm users01.dbf
2、尝试在该表空间上创建表,发现报错
SYS@ORCLCDB> create table t1(id int) tablespace users; create table t1(id int) tablespace users * ERROR at line 1: ORA-01116: error in opening database file 7 ORA-01110: data file 7: '/opt/oracle/oradata/ORCLCDB/users01.dbf' ORA-27041: unable to open file Linux-x86_64 Error: 2: No such file or directory Additional information: 3
3、找到dbw的进程ID
[oracle@database ORCLCDB]$ ps -ef|grep dbw oracle 29459 1 0 03:31 ? 00:00:05 ora_dbw0_ORCLCDB oracle 34599 33456 0 10:50 pts/2 00:00:00 grep --color=auto dbw
4、通过进程号找到文件句柄
[oracle@database ORCLCDB]$ cd /proc/29459/fd [oracle@database fd]$ ll total 0 lr-x------ 1 oracle oinstall 64 Jul 15 10:51 0 -> /dev/null l-wx------ 1 oracle oinstall 64 Jul 15 10:51 1 -> /dev/null l-wx------ 1 oracle oinstall 64 Jul 15 10:51 2 -> /dev/null lrwx------ 1 oracle oinstall 64 Jul 15 10:51 256 -> /opt/oracle/oradata/ORCLCDB/control01.ctl lrwx------ 1 oracle oinstall 64 Jul 15 10:51 257 -> /opt/oracle/oradata/ORCLCDB/control02.ctl lrwx------ 1 oracle oinstall 64 Jul 15 10:51 258 -> /opt/oracle/oradata/ORCLCDB/control03.ctl lrwx------ 1 oracle oinstall 64 Jul 15 10:51 259 -> /opt/oracle/oradata/ORCLCDB/system01.dbf lrwx------ 1 oracle oinstall 64 Jul 15 10:51 260 -> /opt/oracle/oradata/ORCLCDB/sysaux01.dbf lrwx------ 1 oracle oinstall 64 Jul 15 10:51 261 -> /opt/oracle/oradata/ORCLCDB/undotbs01.dbf lrwx------ 1 oracle oinstall 64 Jul 15 10:51 262 -> '/opt/oracle/oradata/ORCLCDB/users01.dbf (deleted)' lrwx------ 1 oracle oinstall 64 Jul 15 10:51 263 -> /opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf 。。。。
5、将句柄文件复制为被删除的DBF文件
[oracle@database fd]$ cp /proc/29459/fd/262 /opt/oracle/oradata/ORCLCDB/users01.dbf
6、针对该DBF文件做介质恢复
SYS@ORCLCDB> alter database datafile 7 offline; Database altered. SYS@ORCLCDB> recover datafile 7; Media recovery complete. SYS@ORCLCDB> alter database datafile 7 online; Database altered.
7、再次尝试在该表空间上创建表成功
SYS@ORCLCDB> create table t1(id int) tablespace users; Table created.