Oracle RMAN恢复带有OFFLINE数据文件的数据库

本文详细介绍了如何使用Oracle Recovery Manager (RMAN) 恢复包含离线数据文件的数据库。内容涵盖了解决此类问题的关键步骤和策略,帮助数据库管理员在遇到数据文件脱机情况时,能够有效地恢复数据库到正常运行状态。
1、创建测试表空间及测试数据文件
SQL> create tablespace test datafile '/u01/app/oracle/oradata/qlotcdb/test.dbf' size 1M;
SQL> create user test identified by test default tablespace test;
User created.

SQL> alter system switch logfile;
System altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/qlotcdb/system01.dbf
/u01/app/oracle/oradata/qlotcdb/sysaux01.dbf
/u01/app/oracle/oradata/qlotcdb/undotbs01.dbf
/u01/app/oracle/oradata/qlotcdb/users01.dbf
/u01/app/oracle/oradata/qlotcdb/test.dbf

2、将测试数据文件OFFLINE
SQL> alter database datafile '/u01/app/oracle/oradata/qlotcdb/test.dbf' offline;
Database altered.

3、删除全部归档日志
[oracle@db ~]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs/arch
[oracle@db arch]$ ls
1_12_911428282.dbf  1_14_911428282.dbf  1_16_911428282.dbf  1_18_911428282.dbf  1_49_917365262.dbf
1_13_911428282.dbf  1_15_911428282.dbf  1_17_911428282.dbf  1_48_917365262.dbf  redo.log
[oracle@db arch]$ rm -rf *

4、尝试ONLINE测试数据文件失败
SQL> alter database datafile 5 online;
alter database datafile 5 online
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/u01/app/oracle/oradata/qlotcdb/test.dbf'

5、recover OFFLINE数据文件失败
SQL> recover datafile 5;
ORA-00279: change 2036178 generated at 09/18/2016 16:51:38 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0/db_1/dbs/arch/1_48_917365262.dbf
ORA-00280: change 2036178 for thread 1 is in sequence #48

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/product/11.2.0/db_1/dbs/arch/1_48_917365262.dbf
ORA-00308: cannot open archived log
'/u01/app/oracle/product/11.2.0/db_1/dbs/arch/1_48_917365262.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00308: cannot open archived log
'/u01/app/oracle/product/11.2.0/db_1/dbs/arch/1_48_917365262.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

6、RMAN全备数据库进行异机恢复
RMAN> backup database format  '/home/oracle/db_%d_%s_%p_%t_%T';
Starting backup at 18-SEP-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/qlotcdb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/qlotcdb/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/qlotcdb/users01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/qlotcdb/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/qlotcdb/test.dbf
channel ORA_DISK_1: starting piece 1 at 18-SEP-16
channel ORA_DISK_1: finished piece 1 at 18-SEP-16
piece handle=/home/oracle/db_qlotcdb_5_1_922899986_20160918 tag=TAG20160918T170626 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 18-SEP-16
channel ORA_DISK_1: finished piece 1 at 18-SEP-16
piece handle=/home/oracle/db_qlotcdb_6_1_922900041_20160918 tag=TAG20160918T170626 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 18-SEP-16

RMAN> list backup of database;
List of Backup Sets
==================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    1.40G      DISK        00:00:16     18-SEP-16      
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20160918T170253
        Piece Name: /home/oracle/1.ddd
  List of Datafiles in backup set 2
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 2037314    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/system01.dbf
  2       Full 2037314    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/sysaux01.dbf
  3       Full 2037314    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/undotbs01.dbf
  4       Full 2037314    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/users01.dbf
  5       Full 2036178    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/test.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    1.40G      DISK        00:00:15     18-SEP-16      
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20160918T170444
        Piece Name: /home/oracle/1_U%
  List of Datafiles in backup set 3
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 2037360    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/system01.dbf
  2       Full 2037360    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/sysaux01.dbf
  3       Full 2037360    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/undotbs01.dbf
  4       Full 2037360    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/users01.dbf
  5       Full 2036178    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/test.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    1.40G      DISK        00:00:51     18-SEP-16      
        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20160918T170626
        Piece Name: /home/oracle/db_qlotcdb_5_1_922899986_20160918
  List of Datafiles in backup set 4
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 2037401    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/system01.dbf
  2       Full 2037401    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/sysaux01.dbf
  3       Full 2037401    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/undotbs01.dbf
  4       Full 2037401    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/users01.dbf
  5       Full 2036178    18-SEP-16 /u01/app/oracle/oradata/qlotcdb/test.dbf
  

7、异机恢复参数文件及控制文件(略)


8、异机restore database
RMAN> shutdown immediate
database closed
database dismounted
Oracle instance shut down

RMAN> startup mount
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area     413372416 bytes
Fixed Size                     2253784 bytes
Variable Size                327158824 bytes
Database Buffers              79691776 bytes
Redo Buffers                   4268032 bytes

RMAN> restore database;
Starting restore at 18-SEP-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 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 00001 to /u01/app/oracle/oradata/qlotcdb/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/qlotcdb/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/qlotcdb/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/qlotcdb/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/qlotcdb/test.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/db_qlotcdb_5_1_922899986_20160918
channel ORA_DISK_1: piece handle=/home/oracle/db_qlotcdb_5_1_922899986_20160918 tag=TAG20160918T170626
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:26
Finished restore at 18-SEP-16

9、restore database后无法直接OPEN,提示数据文件需要介质恢复
RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/18/2016 17:09:51
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/qlotcdb/system01.dbf'

10、recover亦失败
RMAN> recover database;
Starting recover at 18-SEP-16
using channel ORA_DISK_1
starting media recovery
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/18/2016 17:09:57
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 50 and starting SCN of 2036521 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 49 and starting SCN of 2036497 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 48 and starting SCN of 2035586 found to restore

11、此时数据库无法OPEN
RMAN> alter database open;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/18/2016 17:17:28
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/qlotcdb/system01.dbf'

RMAN> alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/18/2016 17:17:51
ORA-01152: file 1 was not restored from a sufficiently old backup 
ORA-01110: data file 1: '/u01/app/oracle/oradata/qlotcdb/system01.dbf'

12、重建控制文件,去除OFFLINE的数据文件
RMAN> shutdown immediate
database dismounted
Oracle instance shut down

SQL> STARTUP NOMOUNT
ORACLE instance started.
Total System Global Area  413372416 bytes
Fixed Size                  2253784 bytes
Variable Size             327158824 bytes
Database Buffers           79691776 bytes
Redo Buffers                4268032 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "qlotcdb" NORESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '/u01/app/oracle/oradata/qlotcdb/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/u01/app/oracle/oradata/qlotcdb/redo02.log'  SIZE 50M BLOCKSIZE 512,
 10    GROUP 3 '/u01/app/oracle/oradata/qlotcdb/redo03.log'  SIZE 50M BLOCKSIZE 512
 11  -- STANDBY LOGFILE
 12  DATAFILE
 13    '/u01/app/oracle/oradata/qlotcdb/system01.dbf',
 14    '/u01/app/oracle/oradata/qlotcdb/sysaux01.dbf',
 15    '/u01/app/oracle/oradata/qlotcdb/undotbs01.dbf',
 16    '/u01/app/oracle/oradata/qlotcdb/users01.dbf'
 17  CHARACTER SET ZHS16GBK
 18  ;
Control file created.

13、重建控制文件后,recover database,数据库成功OPEN
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/qlotcdb/system01.dbf'

SQL> recover database;        
Media recovery complete.

SQL> alter database open;
Database altered.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值