非关键性文件的丢失都不需要关闭数据库。
关键性文件:undo,system
alter database datafile <> offline;
restore datafile <>;
recover datafile <>;
关键性文件:undo,system
alter database datafile <> offline;
restore datafile <>;
recover datafile <>;
alter database datafile <> online;
--实验
SYS@PROD2> ho rm /u01/app/oracle/oradata/PROD2/example01.dbf
SYS@PROD2> select count(*) from hr.employees;
select count(*) from hr.employees
*
ERROR at line 1:
ORA-01116: error in opening database file 5
ORA-01110: data file 5: '/u01/app/oracle/oradata/PROD2/example01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
[oracle@ocm1 ~]$ vi rman_ex.sql --编写成一个脚本方便执行
[oracle@ocm1 ~]$ cat rman_ex.sql
run {
sql 'alter database datafile 5 offline';
restore datafile 5;
recover datafile 5;
sql 'alter database datafile 5 online';
}
[oracle@ocm1 ~]$ rman target / cmdfile=/home/oracle/rman_ex.sql --执行恢复
Recovery Manager: Release 11.2.0.3.0 - Production on Fri Dec 16 21:07:37 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD2 (DBID=1564287740)
RMAN> run {
2> sql 'alter database datafile 5 offline';
3> restore datafile 5;
4> recover datafile 5;
5> sql 'alter database datafile 5 online';
6> }
7>
using target database control file instead of recovery catalog
sql statement: alter database datafile 5 offline
Starting restore at 16-DEC-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD2/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD2/backupset/2016_12_16/o1_mf_nnndf_TAG20161216T202530_d57q9tn3_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD2/backupset/2016_12_16/o1_mf_nnndf_TAG20161216T202530_d57q9tn3_.bkp tag=TAG20161216T202530
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:26
Finished restore at 16-DEC-16
Starting recover at 16-DEC-16
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 9 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_9_d57qf3tn_.arc
archived log for thread 1 with sequence 10 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_10_d57qq6rm_.arc
archived log for thread 1 with sequence 11 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_11_d57r5c75_.arc
archived log for thread 1 with sequence 12 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_12_d57ro1fg_.arc
archived log for thread 1 with sequence 13 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_13_d57rqf15_.arc
archived log for thread 1 with sequence 14 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_14_d57rs04p_.arc
archived log for thread 1 with sequence 15 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_15_d57rs1l3_.arc
archived log for thread 1 with sequence 16 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_16_d57rs2ln_.arc
archived log for thread 1 with sequence 17 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_17_d57rs3g5_.arc
archived log for thread 1 with sequence 18 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_18_d57rs432_.arc
archived log for thread 1 with sequence 19 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_19_d57rs4pm_.arc
archived log for thread 1 with sequence 20 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_20_d57rs5c0_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_9_d57qf3tn_.arc thread=1 sequence=9
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_10_d57qq6rm_.arc thread=1 sequence=10
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_11_d57r5c75_.arc thread=1 sequence=11
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_12_d57ro1fg_.arc thread=1 sequence=12
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_13_d57rqf15_.arc thread=1 sequence=13
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_14_d57rs04p_.arc thread=1 sequence=14
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_15_d57rs1l3_.arc thread=1 sequence=15
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_16_d57rs2ln_.arc thread=1 sequence=16
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_17_d57rs3g5_.arc thread=1 sequence=17
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_16/o1_mf_1_18_d57rs432_.arc thread=1 sequence=18
media recovery complete, elapsed time: 00:00:00
Finished recover at 16-DEC-16
sql statement: alter database datafile 5 online
Recovery Manager complete.
SYS@PROD2> select count(*) from hr.employees; --恢复成功
COUNT(*)
----------
107