主库上操作
1.开启RAC的 force logging
SQL> alter database force logging;
SQL>
2.修改RAC初始化参数文件
SQL> alter system set log_archive_config='DG_CONFIG=(eisoo,eisoos)';
SQL> alter system set log_archive_dest_2='SERVICE=eisoos ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=eisoos' scope=spfile;
SQL> alter system set log_archive_dest_state_1=ENABLE;
SQL> alter system set log_archive_dest_state_2=ENABLE;
SQL> alter system set fal_server=eisoos;
SQL> alter system set db_file_name_convert='eisoos','eisoo' scope=spfile;
SQL> alter system set db_file_name_convert='/data/oradata/eisoos','+DATA/EISOO/DATAFILE' scope=spfile; //如果备库没有使用asm
SQL> alter system set log_file_name_convert='eisoos','eisoo' scope=spfile;
SQL> alter system set log_file_name_convert='/data/oradata/eisoos','+DATA/EISOO/ONLINELOG' scope=spfile;//如果备库没有使用asm
SQL> alter system set standby_file_management='AUTO';
SQL> alter system set log_archive_max_processes=30;
3.开启归档模式
srvctl stop database -d eisoo
srvctl start database -d eisoo-i eisoo -o mount
SQL>alter database archivelog;
SQL>alter database open;
4.创建standby logfile;
SQL> select thread#,group#,bytes/1024/1024 from v$log;
THREAD# GROUP# BYTES/1024/1024
---------- ---------- ---------------
1 1 50
1 2 50
2 3 50
2 4 50
SQL> alter database add standby logfile thread 1 group 10 size 50M;
SQL> alter database add standby logfile thread 1 group 11 size 50M;
SQL> alter database add standby logfile thread 1 group 12 size 50M;
SQL> alter database add standby logfile thread 2 group 13 size 50M;
SQL> alter database add standby logfile thread 2 group 14 size 50M;
SQL> alter database add standby logfile thread 2 group 15 size 50M;
SQL> select thread#,group#,bytes/1024/1024 from v$standby_log;
Recovery Manager: Release 12.1.0.2.0 - Production on Mon Sep 26 16:50:42 2016
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: EISOO (DBID=3774196505)
connected to auxiliary database: EISOO (not mounted)
RMAN> duplicate target database for standby from active database;
Starting Duplicate Db at 2016/09/26 16:52:12
6.开启实时同步
SQL> alter database recover managed standby database using current logfile disconnect from session;
验证:
1)
SQL> select dest_name,error from v$archive_dest;//通过查看archive_log_dest_2列是否有error报错,如果有报错,则需要先根据报错内容解决问题
2)
查询主库最大归档序号和备库最大归档序号
select max(sequence#) from v$archived_log;
然后在主库切换日志:alter system switch logfile;
再次查询备库最大归档序号,一致即归档同步成功。
主库:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
133
SQL> alter system switch logfile;
System altered.
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
134
SQL>
备库:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
134
SQL>
3)
主库验证
SQL>select SEQUENCE#, FIRST_TIME, NEXT_TIME, APPLIED, ARCHIVED from V$ARCHIVED_LOG;
备库验证
SQL>select SEQUENCE#, FIRST_TIME, NEXT_TIME, APPLIED, ARCHIVED from V$ARCHIVED_LOG;
备注:观察主备库日志是否同步,如一致则表示日志CDP同步正常。
主备切换
1.检查DG是否同步是否正常
主库:
SQL> select switchover_status,database_role from gv$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
TO STANDBY PRIMARY
TO STANDBY PRIMARY
备库:
SQL> select switchover_status,database_role from gv$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
NOT ALLOWED PHYSICAL STANDBY