说明:数据库开规档,没备份,数据文件被删除的恢复
工具恢复文件
没重启恢复
条件:
1.数据库开启归档
2.创建数据文件之后的所有归档日志都在
3.数据文件或表空间没有备份,数据文件异常丢失
步骤:
1.创建测试用的表空间:
SQL> create tablespace bbb datafile '/oradata/node1/bbb.dbf' size 100M;
Tablespace created.
SQL> conn zw/zw
Connected.
SQL> create table test1 (
id number(10)
)tablespace bbb;
SQL> insert into test1 values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test1;
ID
----------
1
SQL> select name from v$datafile;
NAME
-----------------------------
/oradata/node1/system01.dbf
/oradata/node1/sysaux01.dbf
/oradata/node1/undotbs01.dbf
/oradata/node1/users01.dbf
/oradata/node1/bbb.dbf
2.删除数据文件,模拟异常丢失
[oracle@node1 node1]$ mv bbb.dbf bbb.dbf.bak
[oracle@node1 node1]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Jan 24 02:43:35 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
SQL>
SQL> alter tablespace bbb read only;
alter tablespace bbb read only
*
ERROR at line 1:
ORA-01116: error in opening database file 5
ORA-01110: data file 5: '/oradata/node1/bbb.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> shutdown immediate
ORA-01116: error in opening database file 5
ORA-01110: data file 5: '/oradata/node1/bbb.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> select status from v$instance;
STATUS
------------------------
OPEN
SQL> alter system switch logfile;
System altered.
SQL> /
SQL> shutdown abort;
ORACLE instance shut down.
3.把数据库启动到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 839282688 bytes
Fixed Size 2257880 bytes
Variable Size 494930984 bytes
Database Buffers 339738624 bytes
Redo Buffers 2355200 bytes
Database mounted.
SQL>
4.使用alter database create datafile '/' as '/' 的方式,重建这个丢失的数据文件:
SQL> alter database create datafile 5;
Database altered.
5.查看文件是否已经创建
[root@node1 oradata]# cd node1
[root@node1 node1]# ll
total 1953452
-rw-r----- 1 oracle dba 104865792 Jan 24 02:48 bbb.dbf
-rw-r----- 1 oracle dba 104865792 Jan 24 02:44 bbb.dbf.bak
-rw-r----- 1 oracle dba 9748480 Jan 24 02:49 control01.ctl
可以看到文件bbb.dbf已经创建
6.通过归档日志和redo log对数据文件进行恢复
SQL> recover datafile 5;
Media recovery complete.
SQL> alter database open;
Database altered.
SQL> conn zw/zw
Connected.
SQL> select * from test1;
ID
----------
1
可以看到数据已经成功恢复;