1,获取最新的控制文件
在主库执行以下命令,如果报错,换一个文件名
alter database create standby controlfile as '/home/oracle/control01.ctl';
scp /home/oracle/control01.ctl 备库ip:/home/oracle/
2,复制到备库对应位置后进行恢复
sqlplus / as sysdba
SQL> shutdown immediate
SQL> startup nomount
SQL> exit
rman target /
RMAN> restore controlfile from '/home/oracle/control01.ctl'; ----这里的control01.ctl和上面生成的文件名对应
RMAN> sql 'alter database mount standby database';
在后台恢复
vi restore.sh
rman target / <<EOF
run {
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=主库的主机名)';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=主库的主机名)';
restore database ;
recover database delete archivelog;
release channel ch00;
release channel ch01;
}
exit;
EOF
nohup sh restore.sh &
3,创建standby logfile
需要在主库上查询
select bytes as logsize from v$log;
select member from v$logfile;
在备库上创建
(standby logfile需要比redologfile多一组,每组只能创建一个成员,group编号不能重复,group编号要比主库上最大group#大于20)
大小根据主库查询到的结果设置,路径根据本地实际路径,数量为主库日志组数+1
ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 21 ('/xxx/xxxrdo_u01/xxx/stdredo21.log') size <logsize> reuse;
ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 22 ('/xxx/xxxrdo_u01/xxx/stdredo22.log') size <logsize> reuse;
ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 23 ('/xxx/xxxrdo_u01/xxx/stdredo23.log') size <logsize> reuse;
ALTER DATABASE ADD STANDBY LOGFILE group 21 ('/wuhcxidst0/wuhcxidst0rdo_u01/wuhcxidst0/stdredo01.log') SIZE 314572800;
ALTER DATABASE ADD STANDBY LOGFILE group 22 ('/wuhcxidst0/wuhcxidst0rdo_u01/wuhcxidst0/stdredo02.log') SIZE 314572800;
ALTER DATABASE ADD STANDBY LOGFILE group 23 ('/wuhcxidst0/wuhcxidst0rdo_u01/wuhcxidst0/stdredo03.log') SIZE 314572800;
4,在DG备库上启动同步
alter database recover managed standby database disconnect from session;
select process,status,sequence# from v$managed_standby;
---- 正常情况下会存在一个mrp0进程,需要追平日志
####如何判断日志是否追平####
主库查询当前最新日志序号
select SEQUENCE# from v$log where STATUS='CURRENT';
备库查看当前所需日志号(WAIT_FOR_LOG)
select STATUS,SEQUENCE# from v$managed_standby where PROCESS='MRP0';
####以上2个查询结果一致,则已经追平####
----继续执行以下命令
alter database recover managed standby database cancel;
alter database open read only ;
alter database recover managed standby database using current logfile disconnect from session;
网友评论