RMAN> run { allocate channel prmy1 type disk; allocate channel prmy2 type disk; allocate channel prmy3 type disk; allocate channel prmy4 type disk; allocate channel prmy5 type disk; allocate channel prmy6 type disk; allocate auxiliary channel aux1 type disk; allocate auxiliary channel aux2 type disk; allocate auxiliary channel aux3 type disk; allocate auxiliary channel aux4 type disk; allocate auxiliary channel aux5 type disk; allocate auxiliary channel aux6 type disk; duplicate target database for standby from active database dorecover nofilenamecheck; }
等待 RMAN duplicate 复制完成即可。
打开备库只读
1 2
SQL>alter database open read only; SQL>alter pluggable database allopen;
-- 主库 SQL>set line2222 pages1000 col status for a10 col type for a10 col error for a20 col gap_status for a20 col synchronization_status for a30 col recovery_mode for a60 select inst_id,status,DEST_ID,TYPE,ERROR,GAP_STATUS,SYNCHRONIZED,SYNCHRONIZATION_STATUS,RECOVERY_MODE from GV$ARCHIVE_DEST_STATUS where STatus <>'INACTIVE'and type ='PHYSICAL';
备库:
1 2 3 4 5
SQL>set line222 pages1000 select process,thread#,group#,sequence#,status from v$managed_standby;
SQL> col memberfor a100 select t2.thread#,t1.group#,t1.member,t2.STATUS,t2.ARCHIVED,t2.bytes/1024/1024from v$logfile t1,v$standby_log t2 where t1.group#=t2.group# orderby1,2;
-- 查询数据 SELECT*FROM testuser.employees; SELECTCOUNT(*) FROM testuser.employees;
主备 SwitchOver 切换
切换前检查
查看主备库同步进程状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-- 主库 SQL>set line2222 col status for a10 col type for a10 col error for a20 col gap_status for a20 col synchronization_status for a30 col recovery_mode for a60 select inst_id,status,DEST_ID,TYPE,database_mode,ERROR,GAP_STATUS,SYNCHRONIZED,SYNCHRONIZATION_STATUS,RECOVERY_MODE from GV$ARCHIVE_DEST_STATUS where STatus <>'INACTIVE'and type ='PHYSICAL';
SQL>set line2222 col name for a10 col database_role for a20 col switchover_status for a20 col PROTECTION_MODE for a25 select inst_id,name,database_role,protection_mode,switchover_status from gv$database;
备库:
1 2 3 4 5 6 7 8 9 10 11 12
SQL>SELECT (SELECTMAX(sequence#) FROM v$archived_log WHERE applied='YES') last_applied_seq, (SELECTMAX(sequence#) FROM v$archived_log) last_received_seq, (SELECTMAX(sequence#) FROM v$archived_log) - (SELECTMAX(sequence#) FROM v$archived_log WHERE applied='YES') gap FROM dual;
SQL>set line222 col database_role for a20 col switchover_status for a20 col PROTECTION_MODE for a25 select inst_id,name,database_role,protection_mode,switchover_status from gv$database;
主切换到备
主库切换为备库 (期间观察主库 alert 日志):
1
SQL>alter database committo switchover to physical standby with session shutdown;
备切换到主
备库下检查是否可以切换为主库:
1 2 3 4 5
SQL>set line222 col database_role for a20 col switchover_status for a20 col PROTECTION_MODE for a25 select name,database_role,protection_mode,switchover_status from gv$database;
-- 主库 SQL>set line2222 col status for a10 col type for a10 col error for a20 col gap_status for a20 col synchronization_status for a30 col recovery_mode for a60 select inst_id,status,DEST_ID,TYPE,database_mode,ERROR,GAP_STATUS,SYNCHRONIZED,SYNCHRONIZATION_STATUS,RECOVERY_MODE from GV$ARCHIVE_DEST_STATUS where STatus <>'INACTIVE'and type ='PHYSICAL';