通过句柄文件恢复linux下误删除的数据文件

数据库在open的时候数据文件被删除(从系统级别删除)
因为在linux系统中,之前打开过该文件的进程仍然持有相应的文件句柄,所指向的文件仍然可以读写,
文件描述符可以从/proc目录中得到
如果关闭数据库,则该句柄会消失
[@more@]
通过简单的实验演示一下
SYS SQL> select status from v$instance;
STATUS
------------
OPEN
SYS SQL> select name from v$datafile;
NAME
-------------------------------------------------------
/opt/app/oracle/oradata/ora10g/system01.dbf
/opt/app/oracle/oradata/ora10g/undotbs01.dbf
/opt/app/oracle/oradata/ora10g/sysaux01.dbf
/opt/app/oracle/oradata/ora10g/users01.dbf

删除users表空间的数据文件
SYS SQL> ! rm -rf /opt/app/oracle/oradata/ora10g/users01.dbf

在users表空间建表的时候,报错
SYS SQL> create table t3 tablespace users as select * from scott.emp;
create table t3 tablespace users as select * from scott.emp *
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/opt/app/oracle/oradata/ora10g/users01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SYS SQL> select status from v$instance;
STATUS
------------
OPEN

查看dbw0写进程的进程号
[oracle@report bdump]$ ps -ef | grep dbw0 |grep -v grep
oracle 3393 1 0 17:32 ? 00:00:05 ora_dbw0_ora10g

proc目录下查看句柄号,可以看到users表空间的数据文件后面标示有deleted的字样 句柄文件名为21
[root@report ora10g]# cd /proc/3393/fd/
[root@report fd]# ll
lr-x------ 1 oracle dba 64 Dec 26 23:20 0 -> /dev/null
lr-x------ 1 oracle dba 64 Dec 26 23:20 1 -> /dev/null
lr-x------ 1 oracle dba 64 Dec 26 23:20 10 -> /dev/zero
lr-x------ 1 oracle dba 64 Dec 26 23:20 11 -> /dev/zero
lr-x------ 1 oracle dba 64 Dec 26 23:20 12 -> /opt/app/oracle/product/10.2.0/rdbms/mesg/oraus.msb
lrwx------ 1 oracle dba 64 Dec 26 23:20 13 -> /opt/app/oracle/product/10.2.0/dbs/hc_ora10g.dat
lrwx------ 1 oracle dba 64 Dec 26 23:20 14 -> /opt/app/oracle/product/10.2.0/dbs/lkORA10G
lrwx------ 1 oracle dba 64 Dec 26 23:20 15 -> /opt/app/oracle/oradata/ora10g/control01.ctl
lrwx------ 1 oracle dba 64 Dec 26 23:20 16 -> /opt/app/oracle/oradata/ora10g/control02.ctl
lrwx------ 1 oracle dba 64 Dec 26 23:20 17 -> /opt/app/oracle/oradata/ora10g/control03.ctl
lrwx------ 1 oracle dba 64 Dec 26 23:20 18 -> /opt/app/oracle/oradata/ora10g/system01.dbf
lrwx------ 1 oracle dba 64 Dec 26 23:20 19 -> /opt/app/oracle/oradata/ora10g/undotbs01.dbf
lr-x------ 1 oracle dba 64 Dec 26 23:20 2 -> /dev/null
lrwx------ 1 oracle dba 64 Dec 26 23:20 20 -> /opt/app/oracle/oradata/ora10g/sysaux01.dbf
lrwx------ 1 oracle dba 64 Dec 26 23:20 21 -> /opt/app/oracle/oradata/ora10g/users01.dbf (deleted)
lrwx------ 1 oracle dba 64 Dec 26 23:20 22 -> /opt/app/oracle/oradata/ora10g/temp01.dbf
lr-x------ 1 oracle dba 64 Dec 26 23:20 23 -> /opt/app/oracle/product/10.2.0/rdbms/mesg/oraus.msb
lr-x------ 1 oracle dba 64 Dec 26 23:20 3 -> /dev/null
lr-x------ 1 oracle dba 64 Dec 26 23:20 4 -> /dev/null
l-wx------ 1 oracle dba 64 Dec 26 23:20 5 -> /opt/app/oracle/admin/ora10g/udump/ora10g_ora_3384.trc
l-wx------ 1 oracle dba 64 Dec 26 23:20 6 -> /opt/app/oracle/admin/ora10g/bdump/alert_ora10g.log
l-wx------ 1 oracle dba 64 Dec 26 23:20 8 -> /opt/app/oracle/admin/ora10g/bdump/alert_ora10g.log
lrwx------ 1 oracle dba 64 Dec 26 23:20 9 -> /opt/app/oracle/product/10.2.0/dbs/hc_ora10g.dat

直接cp该句柄文件名到数据文件原位置
[root@report fd]# cp 21 /opt/app/oracle/oradata/ora10g/users01.dbf

SYS SQL> alter database datafile 4 offline;
Database altered.
SYS SQL> recover datafile 4;
Media recovery complete.
SYS SQL> alter database datafile 4 online;
Database altered.

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

转载于:http://blog.itpub.net/7490392/viewspace-1059516/

你可能感兴趣的:(通过句柄文件恢复linux下误删除的数据文件)