catalog start with + switch database to copy的妙用
2017-08-31 17:28 AlfredZhao 阅读(1711) 评论(0) 编辑 收藏 举报
catalog start with + switch database to copy的妙用
环境:RHEL6.4 + Oracle 11.2.0.4 Primary RAC + Standby RAC
现象:从主库恢复控制文件之后,由于是OMF管理的方式,导致ASM上存储的数据文件名字和控制文件中的名字不一样。
我们来看看现象的具体情况:
ASM上的数据文件信息:
ASMCMD [+data/mynas/datafile] > ls -l
Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y DBADATA.276.952933931
DATAFILE UNPROT COARSE AUG 11 21:00:00 Y DBS_D_HANK.273.951774293
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y DBS_D_HANK.274.951774467
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y DBS_D_JINGYU.262.951608185
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y DBS_I_JINGYU.263.951608185
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y SYSAUX.257.951608183
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y SYSTEM.258.951608183
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y TEST.264.951608185
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y TEST2.260.951608185
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y UNDOTBS1.259.951608185
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y UNDOTBS2.261.951608185
DATAFILE UNPROT COARSE AUG 31 16:00:00 Y USERS.265.951608205
ASMCMD [+data/mynas/datafile] >
恢复的备库控制文件中的信息:
SQL> select name, database_role, open_mode from gv$database;
NAME DATABASE_ROLE OPEN_MODE
--------- ---------------- --------------------
JYZHAO PHYSICAL STANDBY MOUNTED
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA/mynas/datafile/system.256.919998779
+DATA/mynas/datafile/sysaux.257.919998781
+DATA/mynas/datafile/undotbs1.258.919998783
+DATA/mynas/datafile/users.259.919998789
+DATA/mynas/datafile/undotbs2.264.919999419
+DATA/mynas/datafile/dbs_d_jingyu.268.947072261
+DATA/mynas/datafile/dbs_i_jingyu.270.947072263
+DATA/mynas/datafile/test.271.947072293
+DATA/mynas/datafile/test2.272.947072883
+DATA/mynas/datafile/dbs_d_hank.273.951758265
+DATA/mynas/datafile/dbadata.275.952933837
11 rows selected.
可以看到,虽然路径是对的,但由于OMF特性,文件名字完全不一样。
有的同学看到这里,尤其是刚刚入门的初级DBA,可能会直接想简单粗暴的直接使用rename数据文件来解决问题。
当然,这我的这个场景里,也恰巧可以用rename来解决问题,但这只是因为我这里测试环境文件少,可以容易对应起来。
而且这种方式不但容易误操作,在数据文件多的情况,有可能根本无法轻松识别出对应关系。
那应该怎么做呢?
。。。
现在换个角度来考虑,这些控制文件记录的都是不存在的文件,只是数据库认为是这些文件,而我的ASM上才是真实的数据文件,那么,
我可以把ASM上的文件都认为是数据文件的copy备份,完全可以使用RMAN的catalog start with手工将这些copy“备份”加进来,数据库会认为这些文件就只是数据文件的copy备份,然后直接switch database to copy就可以成功切换。
参考命令:
RMAN> catalog start with '+data/mynas/datafile';
RMAN> switch database to copy;
实际操作过程和结果如下:
RMAN> list copy;
using target database control file instead of recovery catalog
specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
List of Archived Log Copies for database with db_unique_name MYNAS
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
2 1 983 A 31-AUG-17
Name: +FRA/mynas/archivelog/2017_08_31/thread_1_seq_983.743.953483617
4 1 984 A 31-AUG-17
Name: +FRA/mynas/archivelog/2017_08_31/thread_1_seq_984.731.953483625
1 2 826 A 31-AUG-17
Name: +FRA/mynas/archivelog/2017_08_31/thread_2_seq_826.737.953483619
3 2 827 A 31-AUG-17
Name: +FRA/mynas/archivelog/2017_08_31/thread_2_seq_827.736.953483623
RMAN> catalog start with '+data/mynas/datafile';
Starting implicit crosscheck backup at 31-AUG-17
allocated channel: ORA_DISK_1
Crosschecked 37 objects
Finished implicit crosscheck backup at 31-AUG-17
Starting implicit crosscheck copy at 31-AUG-17
using channel ORA_DISK_1
Finished implicit crosscheck copy at 31-AUG-17
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_821.628.953475515
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_974.622.953475665
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_757.609.953475667
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_755.607.953475667
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_756.598.953475667
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_758.462.953475671
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_759.464.953475671
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_760.457.953475673
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_761.456.953475677
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_763.434.953475677
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_762.422.953475677
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_764.401.953475679
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_606.384.953475815
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_607.381.953475815
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_605.374.953475815
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_608.364.953475817
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_609.357.953475817
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_610.438.953475817
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_611.421.953475819
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_612.412.953475819
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_613.393.953475819
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_614.592.953475821
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_822.580.953476813
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_975.562.953476817
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_823.551.953477803
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_976.512.953477807
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_977.500.953478181
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_978.488.953478659
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_824.476.953478659
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_979.317.953479329
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_980.298.953481127
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_981.473.953481743
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_2_seq_825.475.953481753
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_31/thread_1_seq_982.745.953482353
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_11/thread_1_seq_171.341.951768137
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_11/thread_2_seq_135.342.951768137
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_30/thread_2_seq_513.634.953368985
File Name: +fra/MYNAS/ARCHIVELOG/2017_08_30/thread_2_seq_514.638.953369045
searching for all files that match the pattern +data/mynas/datafile
List of Files Unknown to the Database
=====================================
File Name: +data/MYNAS/DATAFILE/SYSAUX.257.951608183
File Name: +data/MYNAS/DATAFILE/SYSTEM.258.951608183
File Name: