DG 11g duplicate primary数据库
2018-06-22DataGuard主库配置完毕后,需要将数据库复制到备库主机。
1、冷备份
关闭主库,或者启动到mount模式
rsync /u02/oracle oracle@db2:/u02
主库备份controlfile
SQL>alter database create standby controlfile as '/tmp/standby.ctl';
或者
rman> backup current controlfile for standby format '/tmp/2.ctl';
scp复制到备库
scp /tmp/standby.ctl oracle@db02:/tmp
在备库
cp /tmp/standby.ctl $ORACLE_BASE/oradata/$ORACLE_SID $ORACLE_BASE/fast_recovery_area/$ORACLE_SID
或者用rman 恢复
rman auxiliary /
RMAN>restore standby controlfile from '/tmp/standby2.ctl';
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u02/oracle/oradata/dydb/control01.ctl
output filename=/u02/oracle/oradata/dydb/control02.ctl
output filename=/u02/oracle/oradata/dydb/control03.ctl
注意需要启动std数据库到NOMOUNT状态,否则会报错:RMAN-06496: must use the TO clause when the database is mounted or open
2、如果遇到错误:RA-01665: control file is not a standby control file
select controlfile_type from v$database;
CONTROL
-------
STANDBY 正确
##########################
select controlfile_type from v$database;
CONTROL
-------
BACKUP 错误
3、rman克隆
11g 支持Active database duplicate,可以通过网络直接copy target到auxiliary库,不需要先用rman备库
startup nomount;
在备库登录
rman target sys/pass@pri auxiliary sys/pass@std
duplicate target database for standby from active database nofilenamecheck;
这条命令直接复制dbf/ctl,非常霸道,注意:Duplicate不会将primary上的temp表空间复制到standby库上,但是在将standby库启动到open时会自动创建,standby库上的redo log oracle也将会重新创建。
复制过程中rman已经将备库启动至mount状态。
select open_mode from v$database;
恢复数据
alter database recover managed standby database disconnect from session;
########################################
rman target /
RMAN> backup full database format='/rman/FOR_STANDBY_%u%p%s,RMN' include current controlfile for standby;
或者
RMAN>
run {
allocate channel d1 device type disk;
backup as compressed backupset
incremental level=0 format='/data1/rman/inc0_%d_%T_%s_%p'
tag='inc0' channel=d1 database;
sql "alter system archive log current";
backup as compressed backupset
format='/data1/rman/arch_%d_%T_%s_%p'
tag='arch' channel=d1 archivelog all delete input;
backup as compressed backupset
format='/data1/rman/ctl_%d_%T_%s_%p'
tag='ctl' channel=d1 current controlfile for standby reuse;
}
RMAN> sql'alter system archive log current';
scp inc0_looyudb_20180625_* 172.20.1.75:/data1/rman/
scp ctl_looyudb_20180625_4_1 172.20.1.75:/data1/rman/
scp arch_looyudb_20180625_3_1 172.20.1.75:/data1/rman/
4、备库启动
RMAN> connect auxiliary / 备用的
RMAN> duplicate target database for standby nofilenamecheck;
RMAN> duplicate target database for standby nofilenamecheck BACKUP LOCATION '/data1/rman';
a、在异机克隆时,如果auxiliary DB使用了与target DB相同的磁盘配置,目录结构以及文件名时,必须指定NOFILENAMECHECK。
NOFILENAMECHECK可以阻止检查target DB的数据文件及联机日志文件是否处于正常使用的状态。而auxiliary DB与target DB的磁盘配置,
目录结构以及文件名任一不同时,应避免使用NOFILENAMECHECK。
b、对于没有连接到target DB或catalog的情形,应使用BACKUP LOCATION ''指定备份文件所在的位置。
恢复standby数据库 (db02)
SQL> recover managed standby database disconnect from session;
Media recovery complete.
standby数据库启动到open read only状态
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database open read only;
Database altered.
SQL> recover managed standby database disconnect from session;
Media recovery complete.
5、ORA-10458: standby database requires recovery
物理备库open ORA-10458
刚创建的物理备库在打开时可能会报 ORA-10458: standby database requires recovery 这个错,此时只要打开备库的 日志恢复,让备库apply重做日志即可。
alter database recover managed standby database using current logfile disconnect;
alter database recover managed standby database cancel;
alter database open;
6、重启备库
shutdown immediate;
startup nomount
alter database mount standby database;
alter database open read only;
alter database recover managed standby database disconnect from session;初始化日志应用服务