日期:2014-05-16  浏览次数:20437 次

rman实验之归档模式无备份,正常关机丢失数据文件的恢复

    并不是所有数据文件丢失都能够直接被恢复,如system;也不是所有数据文件丢失都需要恢复,如temp表空间。  

    下面模拟一张业务表。

    1 创建演示环境

sys@ORCL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     16
Next log sequence to archive   18
Current log sequence           18
sys@ORCL> create tablespace think datafile '/u01/app/oracle/oradata/ORCL/datafile/think.dbf' size 10m;

Tablespace created.

sys@ORCL> create user think identified by think default tablespace think quota unlimited on think;

User created.

sys@ORCL> grant connect,resource to think;

Grant succeeded.

sys@ORCL> conn think/think
Connected.
think@ORCL> create table tt (name varchar2(20));

Table created.

think@ORCL> insert into tt values('think');

1 row created.

think@ORCL> commit;

Commit complete.

think@ORCL> select * from tt;

NAME
--------------------
think


    2 模拟数据文件丢失

sys@ORCL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ORCL> host rm -rf /u01/app/oracle/oradata/ORCL/datafile/think.dbf
重新启动数据库
sys@ORCL> startup
ORACLE instance started.

Total System Global Area  419430400 bytes
Fixed Size                  1219760 bytes
Variable Size             125829968 bytes
Database Buffers          289406976 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 8 - see DBWR trace file
ORA-01110: data file 8: '/u01/app/oracle/oradata/ORCL/datafile/think.dbf'


****************************用户管理的恢复方式***********************

    3 执行修复和恢复

sys@ORCL> alter database create datafile '/u01/app/oracle/oradata/ORCL/datafile/think.dbf';

Database altered.

sys@ORCL> recover datafile 8;
Media recovery complete.


    4 查询数据

sys@ORCL> alter database open;

Database altered.

sys@ORCL> conn think/think
Connected.
think@ORCL> select * from tt;

NAME
--------------------
think


*****************************rman恢复**********************

 

[oracle@localhost ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Aug 7 00:03:44 2012

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

connected to target database: ORCL (DBID=1316499950, not open)

RMAN> restore datafile 8;

Starting restore at 07-AUG-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

creating datafile fno=8 name=/u01/app/oracle/oradata/ORCL/datafile/think.dbf
restore not done; all files readonly, offline, or already restored
Finished restore at 07-AUG-12

RMAN> recover datafile 8;

Starting recover at 07-AUG-12
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 07-AUG-12

RMAN> alter database open;

database opened
sys@ORCL> conn think/think
Connected.
think@ORCL> select * from tt;

NAME
--------------------
think


    小结:丢失的数据文件,能够恢复的关键是,从其创建时刻起所有的重做日志文件都还在,因此我们才可以在重建该数据文件后,通过recover命令应用所有重做日志的方式,重建该数据文件的内容。