一、大致步骤
通过RMAN备份创建standby数据库大致分为这几个步骤:
(1)设置主数据库为force loggin模式
(2)设置主数据库为archived log模式
(3)配置好主备库的参数文件
(4)两边的密码文件保持一致
(5)配置监听
(6)用参数文件启动standby到nomount状态
(7)通过rman对主库做完全备份
(8)通过rman为standby创建控制文件
(9)通过rman dumplicate命令创建备库
(10)创建完成后,自动将standby 数据库启动到mount状态,并且不会自动启动redo apply
二、实施创建操作
环境:primary数据库名DGWH,standby数据库名DGBJ,db_unique_name=DGWH
在我总结的10步中,前5步骤和使用常规的方式一样,参见我的blog:
http://5073392.blog.51cto.com/5063392/1299100
理论知识:
http://5073392.blog.51cto.com/5063392/1297346
有详细配置步骤,这里省略,从第6步开始。
注意这里我是直接创建好了spfile文件,当修改好了参数文件后可以用create spfile from pfile创建
(1)在备库上使用spfile启动到nomount状态。
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 318046208 bytes
Fixed Size 1299652 bytes
Variable Size 297798460 bytes
Database Buffers 12582912 bytes
Redo Buffers 6365184 bytes
SQL>
(2)将主库启动到mount状态下,然后用rman连接备份数据库
RMAN> backup database include current controlfile for standby plus archivelog; //注意 备份数据库的同时创建了standby控制文件,并且包含了归档日志。 也可以分开来做例如 backup database ;copy current controlfile for standby to '/tmp/st.ctl'
Starting backup at 22-SEP-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=154 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=463 RECID=917 STAMP=826842432
channel ORA_DISK_1: starting piece 1 at 22-SEP-13
channel ORA_DISK_1: finished piece 1 at 22-SEP-13
piece handle=/u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_annnn_TAG20130922T224340_93y0k0wl_.bkp tag=TAG20130922T224340 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 22-SEP-13
Starting backup at 22-SEP-13
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/DGWH/datafile/o1_mf_system_9361jnkf_.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/DGWH/datafile/o1_mf_sysaux_9361jnkx_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/DGWH/datafile/o1_mf_undotbs1_9361jnol_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/DGWH/datafile/o1_mf_users_9361jnpq_.dbf
channel ORA_DISK_1: starting piece 1 at 22-SEP-13
channel ORA_DISK_1: finished piece 1 at 22-SEP-13
piece handle=/u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_nnndf_TAG20130922T224346_93y0k69f_.bkp tag=TAG20130922T224346 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including standby control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 22-SEP-13
channel ORA_DISK_1: finished piece 1 at 22-SEP-13
piece handle=/u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_ncsnf_TAG20130922T224346_93y0n4ss_.bkp tag=TAG20130922T224346 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 //piece handle生成了3个备份片到/u01/app/oracle/flash_recovery_area/DGWH/backupset
Finished backup at 22-SEP-13
Starting backup at 22-SEP-13
using channel ORA_DISK_1
specification does not match any archived log in the recovery catalog
backup cancelled because all files were skipped
Finished backup at 22-SEP-13
(3) 复制备份集到备库
注意:我在这耽误了几个小时,总是报下列的错误,我理解为使用rman搭建不需要像常规方式那样copy数据文件,所以就没有手工复制备份集到备库,我在网上看了很多知名人写的blog都没提到这步,当出现下面错误的时候,我检查目录文件缺少存在,权限也没什么问题,开始以为备份的命令有问题,各种方法试了很多次还是不行,我就尝试是否要要将备份集copy到与主库备份集相同的目录下,终于成功了。。。。
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_ncsnf_TAG20130922T201417_93xqvgm9_.bkp
channel ORA_AUX_DISK_1: ORA-19870: error while restoring backup piece /u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_ncsnf_TAG20130922T201417_93xqvgm9_.bkp
ORA-19505: failed to identify file "/u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_ncsnf_TAG20130922T201417_93xqvgm9_.bkp"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
首先在备库上使用oracle账号创建/u01/app/oracle/flash_recovery_area/DGWH/backupset/目录,如果使用root需要修改目录权限。
[oracle@localhost flash_recovery_area] mkdir -p DGWH/backupset
在主库执行scp命令copy所有的备份片到备库,可以从第2步中得知生成了哪些备份片,也可以通过相关命令查看
[oracle@localhost] cd /u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22
[oracle@localhost 2013_09_22]$ scp * 192.168.31.3:/u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22
oracle@192.168.31.3's password:
o1_mf_annnn_TAG20130922T224340_93y0k0wl_.bkp 100% 480KB 479.5KB/s 00:00
o1_mf_ncsnf_TAG20130922T224346_93y0n4ss_.bkp 100% 13MB 12.6MB/s 00:00
o1_mf_nnndf_TAG20130922T224346_93y0k69f_.bkp 100% 1090MB 2.6MB/s 06:53
(4)使用rman连接到主库和备库
[oracle@localhost admin]$ rman target / auxiliary sys/oracle@DGBJ//同时连接到主备库
Recovery Manager: Release 11.1.0.6.0 - Production on Sun Sep 22 19:41:53 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: DGWH (DBID=773380365, not open) //显示出主库状态是not open,即mount
connected to auxiliary database: DGWH (not mounted)//显示出备库状态是为not mounted,即nomout
RMAN>
如果监听配置有问题会返回下列错误。
connected to target database: DGWH (DBID=773380365, not open)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04006: error from auxiliary database: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
RMAN> duplicate target database for standby;//使用duplicate命令还原
Starting Duplicate Db at 22-SEP-13
using channel ORA_AUX_DISK_1
contents of Memory Script:
{
restore clone standby controlfile;
sql clone 'alter database mount standby database';
}
executing Memory Script
Starting restore at 22-SEP-13
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_ncsnf_TAG20130922T224346_93y0n4ss_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_ncsnf_TAG20130922T224346_93y0n4ss_.bkp tag=TAG20130922T224346
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/DGBJ/controlfile/DGBJ01.ctl //在备库中指定备份 控制文件的路径,duplicate时会自动copy 2份到对应的路径下,因此必须要启动到nomount状态,读取到备库的参数文件
output file name=/u01/app/oracle/flash_recovery_area/DGBJ/controlfile/DGBJ02.ctl
Finished restore at 22-SEP-13
sql statement: alter database mount standby database
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_temp_9361onbf_.tmp";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_system_9361jnkf_.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_sysaux_9361jnkx_.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_undotbs1_9361jnol_.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_users_9361jnpq_.dbf";
restore
clone database
;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/DGBJ/datafile/o1_mf_temp_9361onbf_.tmp in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 22-SEP-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/DGBJ/datafile/o1_mf_system_9361jnkf_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/DGBJ/datafile/o1_mf_sysaux_9361jnkx_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/DGBJ/datafile/o1_mf_undotbs1_9361jnol_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/DGBJ/datafile/o1_mf_users_9361jnpq_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_nnndf_TAG20130922T224346_93y0k69f_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/DGWH/backupset/2013_09_22/o1_mf_nnndf_TAG20130922T224346_93y0k69f_.bkp tag=TAG20130922T224346
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:03:11
Finished restore at 22-SEP-13
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=9 STAMP=826325100 file name=/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_system_93g65fcl_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=10 STAMP=826325100 file name=/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_sysaux_93g65fht_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=11 STAMP=826325100 file name=/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_undotbs1_93g65fo3_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=826325100 file name=/u01/app/oracle/oradata/DGBJ/datafile/o1_mf_users_93g65fqj_.dbf
Finished Duplicate Db at 22-SEP-13
(5)搭建完成验证
主库创建测试表:
SQL> create table test1(id int);
Table created.
SQL> insert into test1 values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered
备库验证:
SQL> alter database open;
Database altered.
SQL> alter database recover managed standby databaSe disconnect from session;//执行redo apply
Database altered.
SQL> select * from test1;
ID
----------
1
如果发现无法同步,请检查密码文件是否一致。