ITPub博客

首页 > 数据库 > Oracle > 恢复rm -f物理删除数据文件

恢复rm -f物理删除数据文件

原创 Oracle 作者:parknkjun 时间:2016-01-30 17:57:07 0 删除 编辑
1、在数据库open的时候,直接删除users表空间中的数据库文件;
SYS@jzh>select name from v$dbfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/jzh/users01.dbf
/u01/app/oracle/oradata/jzh/undotbs01.dbf
/u01/app/oracle/oradata/jzh/sysaux01.dbf
/u01/app/oracle/oradata/jzh/system01.dbf
/u01/app/oracle/oradata/jzh/example01.dbf

SYS@jzh>host rm /u01/app/oracle/oradata/jzh/users01.dbf
[oracle@jzh5 ~]$ cd /u01/app/oracle/oradata/jzh/
[oracle@jzh5 jzh]$ ll
total 1879452
-rw-r----- 1 oracle oinstall   9748480 Jan 30 09:38 control01.ctl
-rw-r----- 1 oracle oinstall 328343552 Jan 30 09:35 example01.dbf
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:38 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo03.log
-rw-r----- 1 oracle oinstall 576724992 Jan 30 09:35 sysaux01.dbf
-rw-r----- 1 oracle oinstall 744497152 Jan 30 09:35 system01.dbf
-rw-r----- 1 oracle oinstall  30416896 Dec  8 03:50 temp01.dbf
-rw-r----- 1 oracle oinstall 104865792 Jan 30 09:35 undotbs01.dbf
users0.dbf已经被删除了
2、在表空间users中创建测试表
SYS@jzh>create table jzh (id int,name varchar2(10)) tablespace USERS;
create table jzh (id int,name varchar2(10)) tablespace USERS
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/u01/app/oracle/oradata/jzh/users01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
------报错了
3、检查dbwr进程的PID
[oracle@jzh5 jzh]$ ps -ef | grep dbw0 | grep -v grep
oracle    3182     1  0 09:35 ?        00:00:00 ora_dbw0_jzh
4、dbwr进程会打开所有数据文件的句柄,在proc目录中可以查到,目录名是进程PID,fd表示文件描述符
[oracle@jzh5 3182]$ cd /proc/3182/fd
[oracle@jzh5 fd]$ ll
total 0
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 Jan 30 09:47 1 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 10 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 11 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 12 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_jzh.dat
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 13 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 14 -> /proc/3182/fd
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 15 -> /dev/zero
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 16 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_jzh.dat
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 17 -> /u01/app/oracle/product/11.2.0/db_1/dbs/lkJZH
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 18 -> /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/oraus.msb
l-wx------ 1 oracle oinstall 64 Jan 30 09:47 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 256 -> /u01/app/oracle/oradata/jzh/control01.ctl
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 257 -> /u01/app/oracle/fast_recovery_area/jzh/control02.ctl
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 258 -> /u01/app/oracle/oradata/jzh/system01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 259 -> /u01/app/oracle/oradata/jzh/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 260 -> /u01/app/oracle/oradata/jzh/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 261 -> /u01/app/oracle/oradata/jzh/users01.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 262 -> /u01/app/oracle/oradata/jzh/example01.dbf
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 263 -> /u01/app/oracle/oradata/jzh/temp01.dbf
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 4 -> /dev/null
lrwx------ 1 oracle oinstall 64 Jan 30 09:47 5 -> /u01/app/oracle/product/11.2.0/db_1/dbs/hc_jzh.dat
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 6 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 7 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 8 -> /dev/null
lr-x------ 1 oracle oinstall 64 Jan 30 09:47 9 -> /dev/null
以上标红文件被标记为deleted
5、直接cp该句柄文件名回原位置
[oracle@jzh5 fd]$ cp 261 /u01/app/oracle/oradata/jzh/users01.dbf
6、进行数据文件recover
SYS@jzh>alter database datafile 4 offline;            
Database altered.
SYS@jzh>recover datafile 4;
Media recovery complete.
SYS@jzh>alter database datafile 4 online;
Database altered.
[oracle@jzh5 fd]$ cd /u01/app/oracle/oradata/jzh
[oracle@jzh5 jzh]$ ll
total 1884592
-rw-r----- 1 oracle oinstall   9748480 Jan 30 09:53 control01.ctl
-rw-r----- 1 oracle oinstall 328343552 Jan 30 09:35 example01.dbf
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:52 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Jan 30 09:35 redo03.log
-rw-r----- 1 oracle oinstall 576724992 Jan 30 09:52 sysaux01.dbf
-rw-r----- 1 oracle oinstall 744497152 Jan 30 09:52 system01.dbf
-rw-r----- 1 oracle oinstall  30416896 Dec  8 03:50 temp01.dbf
-rw-r----- 1 oracle oinstall 104865792 Jan 30 09:52 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Jan 30 09:52 users01.dbf
users01.dbf文件回来了!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10271187/viewspace-1984550/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
DBA攻城狮

注册时间:2008-02-11

  • 博文量
    115
  • 访问量
    539858