1.创建测试表空间:

17:19:06 SYS@ORA11GR2>create tablespace t_test datafile
17:19:30   2  '/u01/app/oracle/oradata/ORA11GR2/test.dbf' size 20M;

Tablespace created.

2.在测试表空间上创建测试表:

17:19:58 SYS@ORA11GR2>create table t as select 1 id from dual;

Table created.

3.删除数据文件:

[oracle@host03 ~]$ rm /u01/app/oracle/oradata/ORA11GR2/test.dbf

4.此时不能关库。查看dbwr进程的pid:

[oracle@host03 ~]$ ps -ef |grep dbw
oracle    2773     1  0 15:34 ?        00:00:03 ora_dbw0_ORA11GR2
oracle    3712  3561  0 17:23 pts/2    00:00:00 grep dbw

找到句柄,那个blingbling的就是刚才误删的数据文件:

[oracle@host03 ~]$ ls -ltr /proc/2773/fd
total 0
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 5 -> /dev/null
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 4 -> /dev/null
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 3 -> /dev/null
l-wx------ 1 oracle oinstall 64 Dec 13 17:09 2 -> /dev/null
l-wx------ 1 oracle oinstall 64 Dec 13 17:09 1 -> /dev/null
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 0 -> /dev/null
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 9 -> /u01/app/oracle/product/11.2.0/dbhome_1/dbs/hc_ORA11GR2.dat
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 8 -> /dev/zero
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 7 -> /proc/2773/fd
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 6 -> /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 265 -> /u01/app/oracle/oradata/ORA11GR2/test.dbf (deleted)
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 264 -> /u01/app/oracle/oradata/ORA11GR2/temp01.dbf
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 263 -> /u01/app/oracle/test.dbf
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 262 -> /u01/app/oracle/oradata/ORA11GR2/example01.dbf
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 261 -> /u01/app/oracle/oradata/ORA11GR2/users01.dbf
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 260 -> /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 259 -> /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 258 -> /u01/app/oracle/oradata/ORA11GR2/system01.dbf
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 257 -> /u01/app/oracle/fast_recovery_area/ORA11GR2/control02.ctl
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 256 -> /u01/app/oracle/oradata/ORA11GR2/control01.ctl
lr-x------ 1 oracle oinstall 64 Dec 13 17:09 11 -> /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb
lrwx------ 1 oracle oinstall 64 Dec 13 17:09 10 -> /u01/app/oracle/product/11.2.0/dbhome_1/dbs/lkORA11GR2
lrwx------ 1 oracle oinstall 64 Dec 13 17:24 12 -> socket:[53856]

5.将文件cp回来:

[oracle@host03 ~]$ cp /proc//2773/fd/265 /u01/app/oracle/oradata/ORA11GR2/test.dbf

6. 查看数据文件的信息:

17:25:27 SYS@ORA11GR2>select file#,status,name from v$datafile;

     FILE# STATUS  NAME
---------- ------- --------------------------------------------------
         1 SYSTEM  /u01/app/oracle/oradata/ORA11GR2/system01.dbf
         2 ONLINE  /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
         3 ONLINE  /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
         4 ONLINE  /u01/app/oracle/oradata/ORA11GR2/users01.dbf
         5 ONLINE  /u01/app/oracle/oradata/ORA11GR2/example01.dbf
         6 ONLINE  /u01/app/oracle/test.dbf
         7 ONLINE  /u01/app/oracle/oradata/ORA11GR2/test.dbf

7 rows selected.

7.将数据文件offline并再次查看状态:

17:25:51 SYS@ORA11GR2>alter database datafile 6 offline;

Database altered.

再次查看状态
17:26:19 SYS@ORA11GR2>select file#,status,name from v$datafile;

     FILE# STATUS  NAME
---------- ------- --------------------------------------------------
         1 SYSTEM  /u01/app/oracle/oradata/ORA11GR2/system01.dbf
         2 ONLINE  /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
         3 ONLINE  /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
         4 ONLINE  /u01/app/oracle/oradata/ORA11GR2/users01.dbf
         5 ONLINE  /u01/app/oracle/oradata/ORA11GR2/example01.dbf
         6 RECOVER /u01/app/oracle/test.dbf
         7 ONLINE  /u01/app/oracle/oradata/ORA11GR2/test.dbf

7 rows selected.

8.需要recover:

17:26:25 SYS@ORA11GR2>recover datafile 6;
Media recovery complete.
将表空间online,这样误删的数据文件就找回来了
17:26:37 SYS@ORA11GR2>alter database datafile 6 online;

Database altered.

 

posted on 2016-12-16 15:32  Tomatoes  阅读(114)  评论(0编辑  收藏  举报