【备份恢复】无备份在线恢复非关键数据文件

当误删除表空间数据文件(特指非关键数据文件,而不是关键数据文件),则可以在不备份就可以修复数据文件,但有个前提,即不能关库,假如已经关库了,则没有备份,只能offline再删除表空间;

 

实验如下:

1:创建测试表空间

SYS@ORA11GR2>create tablespace ts_test datafile '/u01/app/oracle/oradata/ORA11GR2/test.dbf' size 20m autoextend on;

 

Tablespace created

 

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

SYS@ORA11GR2>create table t1 tablespace ts_test as select 1 id from dual;

 

Table created.

 

3:删除数据文件

[oracle@wang ~]$ cd /u01/app/oracle/oradata/ORA11GR2/

[oracle@wang ORA11GR2]$ ls

control01.ctl  redo01.log  sysaux01.dbf  test.dbf

control02.ctl  redo02.log  system01.dbf  undotbs01.dbf

example01.dbf  redo03.log  temp01.dbf    users01.dbf

[oracle@wang ORA11GR2]$

[oracle@wang ORA11GR2]$ ls test.dbf

test.dbf

[oracle@wang ORA11GR2]$ rm test.dbf

[oracle@wang ORA11GR2]$

 

4:再创建表,验证,数据文件已丢失

SYS@ORA11GR2>create table t2 tablespace ts_test as select 1 id from dual;

 

Table created.

 

SYS@ORA11GR2>exit

 

[oracle@wang ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 12 23:26:22 2016

 

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

SYS@ORA11GR2>drop table t2 purge;

drop table t2 purge

           *

ERROR at line 1:

ORA-01116: error in opening database file 6

ORA-01110: data file 6: '/u01/app/oracle/oradata/ORA11GR2/test.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

 

5:切记,此时,不能关闭数据库

 

6:查看DBWR进程pid

[oracle@wang ~]$ ps -ef | grep dbw|grep -v grep

oracle     899     1  0 10:59 ?        00:00:11 ora_dbw0_ORA11GR2

oracle   29549     1  0 Oct11 ?        00:00:03 ora_dbw0_SF

 

7:找到句柄 请参阅此链接http://www.cnblogs.com/cute/archive/2011/04/20/2022280.html

[oracle@wang ~]$ ll -rt /proc/899/fd

total 0

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 6 -> /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 5 -> /dev/null

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 4 -> /dev/null

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 3 -> /dev/null

l-wx------ 1 oracle oinstall 64 Oct 12 23:29 2 -> /dev/null

l-wx------ 1 oracle oinstall 64 Oct 12 23:29 1 -> /dev/null

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 0 -> /dev/null

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 9 -> /u01/app/oracle/product/11.2.0/dbhome_1/dbs/hc_ORA11GR2.dat

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 8 -> /dev/zero

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 7 -> /proc/899/fd

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 264 -> /u01/app/oracle/oradata/ORA11GR2/test.dbf (deleted)

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 263 -> /u01/app/oracle/oradata/ORA11GR2/temp01.dbf

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 262 -> /u01/app/oracle/oradata/ORA11GR2/example01.dbf

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 261 -> /u01/app/oracle/oradata/ORA11GR2/users01.dbf

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 260 -> /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 259 -> /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 258 -> /u01/app/oracle/oradata/ORA11GR2/system01.dbf

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 257 -> /u01/app/oracle/oradata/ORA11GR2/control02.ctl

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 256 -> /u01/app/oracle/oradata/ORA11GR2/control01.ctl

lr-x------ 1 oracle oinstall 64 Oct 12 23:29 11 -> /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

lrwx------ 1 oracle oinstall 64 Oct 12 23:29 10 -> /u01/app/oracle/product/11.2.0/dbhome_1/dbs/lkORA11GR2

[oracle@wang ~]$

 

8:将找到的句柄拷贝回来

[oracle@wang ~]$ cp /proc//899/fd/264 /u01/app/oracle/oradata/ORA11GR2/test.dbf

 

9:查看数据文件的状态

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/oradata/ORA11GR2/test.dbf

 

6 rows selected.

 

10:将6号数据文件offline

SYS@ORA11GR2>alter database datafile 6 offline;

 

Database altered.

——再次查看数据文件状态:

SYS@ORA11GR2>select file#,status,name from v$datafile;

 

     FILE# STATUSNAME

--------------------------------------------------------------------------------

         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/oradata/ORA11GR2/test.dbf

 

6 rows selected.

 

11:恢复数据文件

SYS@ORA11GR2>recover datafile 6;

Media recovery complete.

SYS@ORA11GR2>

 

12:将6号数据文件online

SYS@ORA11GR2>alter database datafile 6 online;

 

Database altered.

 

13.验证:(文件已经修复回来了)

SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/test.dbf

 

/u01/app/oracle/oradata/ORA11GR2/test.dbf

 

 

请使用浏览器的分享功能分享到微信等