rman实验之归档模式无备份,正常关机丢失数据文件的恢复
并不是所有数据文件丢失都能够直接被恢复,如system;也不是所有数据文件丢失都需要恢复,如temp表空间。
下面模拟一张业务表。
1 创建演示环境
sys@ORCL> archive log list;Database log mode Archive ModeAutomatic archival EnabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 16Next log sequence to archive 18Current log sequence 18sys@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/thinkConnected.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> startupORACLE instance started.Total System Global Area 419430400 bytesFixed Size 1219760 bytesVariable Size 125829968 bytesDatabase Buffers 289406976 bytesRedo Buffers 2973696 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 8 - see DBWR trace fileORA-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/thinkConnected.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 2012Copyright (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-12using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: sid=155 devtype=DISKcreating datafile fno=8 name=/u01/app/oracle/oradata/ORCL/datafile/think.dbfrestore not done; all files readonly, offline, or already restoredFinished restore at 07-AUG-12RMAN> recover datafile 8;Starting recover at 07-AUG-12using channel ORA_DISK_1starting media recoverymedia recovery complete, elapsed time: 00:00:03Finished recover at 07-AUG-12RMAN> alter database open;database openedsys@ORCL> conn think/thinkConnected.think@ORCL> select * from tt;NAME--------------------think
小结:丢失的数据文件,能够恢复的关键是,从其创建时刻起所有的重做日志文件都还在,因此我们才可以在重建该数据文件后,通过recover命令应用所有重做日志的方式,重建该数据文件的内容。