Far Sync容灾部署及测试
前言
Far Sync都已经出现很多年了,虽然知道这个东西,但一直没有亲自测试过,最近有个项目可能要上这个玩意,于是先在测试环境练练手。
一、 环境信息
部署Far Sync ADG环境,需要提前准备好主、备库环境以及至少一套Far Sync用的环境(单机或RAC)。
1. Far Sync HA架构
此次文档使用Far Sync HA架构。
Far Sync HA架构,也即有两个Far Sync节点,避免Far Sync出现单点故障。
2. 测试环境说明
本次测试,环境信息如下所示:
DB_UNIQUE_NAME |
DB_NAME |
SID |
TNS alias |
IP |
|
主库 |
pocdb |
pocdb |
pocdb |
pocdb_tns |
192.168.56.141 |
备库 |
pocdbdg |
pocdb |
pocdb |
pocdbdg_tns |
192.168.56.144 |
FarSync1 |
pocdbfs1 |
pocdb |
pocdbfs1 |
pocdbfs1_tns |
192.168.56.142 |
FarSync2 |
pocdbfs2 |
pocdb |
pocdbfs2 |
pocdbfs2_tns |
192.168.56.143 |
二、 配置容灾
1. 配置ADG环境
具体配置过程省略。
ADG配置完成后,环境信息如下所示。
SQL> select * from v$dataguard_config;
DB_UNIQUE_NAME PARENT_DBUN DEST_ROLE CURRENT_SCN CON_ID
------------------ -------------- ----------------- ----------- ----------
pocdb NONE PRIMARY DATABASE 409942 0
pocdbdg pocdb PHYSICAL STANDBY 409944 0
SQL>
2. RMAN配置Far Sync1
1) 配置Far Sync1的服务名称
Far Sync1库所有节点需配置数据库服务名
# su - oracle
$ vi $ORACLE_HOME/network/admin/tnsnames.ora
pocdb_tns =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.141)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pocdb)
)
)
pocdbfs1_tns =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.142)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pocdbfs1)
)
)
pocdbfs2_tns =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.143)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pocdbfs2)
)
)
pocdbdg_tns =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.144)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pocdbdg)
)
)
2) 注册Far Sync1的静态监听
Far Sync1库所有节点需配置静态监听
添加静态注册监听,用于DG BROKER:名称:db_nuique_name_dgmgrl
# su - grid
$ vi $ORACLE_HOME/network/admin/listener.ora
#备库配置
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = pocdbfs1_DGMGRL)
(ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1)
(SID_NAME = pocdbfs1)
)
(SID_DESC =
(GLOBAL_DBNAME = pocdbfs1)
(ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1)
(SID_NAME = pocdbfs1)
)
)
# reload监听使参数生效
$ lsnrctl reload
$ lsnrctl status
3) 将主库的pfile文件拷贝至Far Sync1
--主库:
$ scp pfile.ora 192.168.56.142:/u01/app/oracle/product/19.0.0/dbhome_1/dbs
--备库:
$ mv pfile.ora initpocdbfs1.ora
4) 将主库的密码文件拷贝至Far Sync1
--主库:
$ scp orapwpocdb 192.168.56.142:/u01/app/oracle/product/19.0.0/dbhome_1/dbs
--备库:
$ mv orapwpocdb orapwpocdbfs1
5) 修改Far Sync1库的pfile文件
$ mv pfile.ora initpocdbfs1.ora
修改后的内容如下:
[oracle@db02 dbs]$ cat initpocdbfs1.ora
*.audit_file_dest='/u01/app/oracle/admin/pocdbfs1/adump'
*.audit_trail='db'
*.compatible='19.0.0'
*.control_files='/u01/app/oracle/oradata/pocdbfs1/control01.ctl','/u01/app/oracle/oradata/pocdbfs1/control02.ctl'
*.db_block_size=8192
*.db_file_name_convert='/u01/app/oracle/oradata/pocdb','/u01/app/oracle/oradata/pocdbfs1'
*.db_name='pocdb'
*.db_unique_name='pocdbfs1'
*.diagnostic_dest='/u01/app/oracle'
*.fal_server='pocdb_tns'
*.log_archive_config='dg_config=(pocdb,pocdbfs1,pocdbdg)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/pocdbfs1/archive'
*.log_archive_dest_2='SERVICE=pocdbdg_tns ASYNC VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=pocdbdg'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s_%r.arc'
*.log_file_name_convert='/u01/app/oracle/oradata/pocdb','/u01/app/oracle/oradata/pocdbfs1'
*.memory_target=1515m
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
6) 登陆Far Sync1库,添加相关目录
$ mkdir -p /u01/app/oracle/admin/pocdbfs1/adump
$ mkdir -p /u01/app/oracle/oradata/pocdbfs1/archive
7) 登陆Far Sync1库,nomont启动实例
$ sqlplus / as sysdba
SQL> startup nomount
SQL> create spfile from pfile;
8) 测试主、备、Far Sync1库的TNS连通性
sqlplus sys/welcome1@pocdb_tns as sysdba
sqlplus sys/welcome1@pocdbdg_tns as sysdba
sqlplus sys/welcome1@pocdbfs1_tns as sysdba
主库、备库以及Far Sync1库都需要测试成功。
9) 登陆主库,通过rman恢复Far Sync1
#在主库操作:
1).创建farsync1.rman脚本,内容如下所示:
run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby1 type disk;
allocate auxiliary channel stby2 type disk;
allocate auxiliary channel stby3 type disk;
allocate auxiliary channel stby4 type disk;
duplicate target database for FARSYNC from active database nofilenamecheck;
}
2).创建farsync1.sh脚本,后期放入后台执行。
rman target sys/welcome1@pocdb_tns auxiliary sys/welcome1@pocdbfs1_tns cmdfile farsync1.rman log rman.log
3).执行farsync1.sh脚本:
nohup ./farsync1.sh &
备注:rman 分别使用简易连接连接主库和far sync,也可以直接使用TNS配置名称连接。
10) 确认farsync1状态
SQL> select open_mode,protection_mode,protection_level,switchover#,database_role,switchover_status from v$database;
11) 修改主库参数
alter system set log_archive_config='DG_CONFIG=(pocdb,pocdbfs1,pocdbdg)' scope=both sid='*';
利用Group 和 Priority的配置,控制日志传输的优先级和方向
alter system set LOG_ARCHIVE_DEST_2='SERVICE=pocdbfs1_tns SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) GROUP=1 PRIORITY=1 DB_UNIQUE_NAME=pocdbfs1' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_3='SERVICE=pocdbdg_tns ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) GROUP=1 PRIORITY=8 DB_UNIQUE_NAME=pocdbdg' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_3=ENABLE scope=both sid='*';
alter system set fal_server='pocdbdg_tns' scope=both sid='*';
12) 修改备库参数
alter system set log_archive_config='DG_CONFIG=(pocdb,pocdbfs1,pocdbdg)' scope=both sid='*';
利用Group 和 Priority的配置,控制日志传输的优先级和方向
alter system set LOG_ARCHIVE_DEST_2='SERVICE=pocdb_tns ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) GROUP=2 PRIORITY=1 DB_UNIQUE_NAME=pocdb' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid='*';
alter system set fal_server='pocdb_tns,pocdbfs1_tns,pocdbfs2_tns' scope=both sid='*';
13) 修改Far Sync1库参数
alter system set log_archive_config='DG_CONFIG=(pocdb,pocdbfs1,pocdbdg)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/pocdbfs1/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pocdbfs1' scope=both sid='*';
alter system set log_archive_dest_2='SERVICE=pocdbdg_tns ASYNC VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=pocdbdg' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid='*';
alter system set fal_server='pocdb_tns' scope=both sid='*';
14) 确认配置完成
SQL> select * from v$dataguard_config;
DB_UNIQUE_NAME PARENT_DBUN DEST_ROLE CURRENT_SCN CON_ID
---------------- -------------- ----------------- ----------- ----------
pocdb NONE PRIMARY DATABASE 422700 0
pocdbfs1 pocdb FAR SYNC INSTANCE 422552 0
pocdbdg pocdbfs1 PHYSICAL STANDBY 422552 0
SQL>
SQL> select dest_name,status,type,destination,error from v$archive_dest_status where dest_id<=4;
DEST_NAME STATUS TYPE DESTINATION ERROR
--------------------- --------- ---------------- --------------------------------------- -----------
LOG_ARCHIVE_DEST_1 VALID LOCAL /u01/app/oracle/oradata/pocdb/archive
LOG_ARCHIVE_DEST_2 VALID FAR SYNC pocdbfs1_tns
LOG_ARCHIVE_DEST_3 ALTERNATE PHYSICAL pocdbdg_tns
LOG_ARCHIVE_DEST_4 INACTIVE LOCAL
3. 配置Far Sync2
配置Far Sync2的步骤与配置Far Sync1基本一致,也可以考虑使用手动方式来配置Far Sync2。如果使用手动方式配置Far Sync2,则必须先在主库生成Far Sync格式的控制文件,然后在Far Sync2实例中添加standby logfile。
配置完Far Sync2后,主要是需要修改整个DG环境中的相关参数。具体如下所示。
1) 修改主库参数
alter system set log_archive_config='DG_CONFIG=(pocdb,pocdbfs1,pocdbfs2,pocdbdg)' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=pocdbfs1_tns SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) GROUP=1 PRIORITY=1 DB_UNIQUE_NAME=pocdbfs1' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_3='SERVICE=pocdbfs2_tns SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) GROUP=1 PRIORITY=1 DB_UNIQUE_NAME=pocdbfs2' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_3=ENABLE scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_4='SERVICE=pocdbdg_tns ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) GROUP=1 PRIORITY=8 DB_UNIQUE_NAME=pocdbdg' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_4=ENABLE scope=both sid='*';
alter system set fal_server='pocdbdg_tns' scope=both sid='*';
2) 修改备库参数
alter system set log_archive_config='DG_CONFIG=(pocdb,pocdbfs1,pocdbfs2,pocdbdg)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/pocdb/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pocdbdg' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=pocdb_tns ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) GROUP=2 PRIORITY=1 DB_UNIQUE_NAME=pocdb' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid='*';
alter system set fal_server='pocdb_tns,pocdbfs1_tns,pocdbfs2_tns' scope=both sid='*';
14) 修改Far Sync1库参数
alter system set log_archive_config='DG_CONFIG=(pocdb,pocdbfs1,pocdbfs2,pocdbdg)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/pocdbfs1/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pocdbfs1' scope=both sid='*';
alter system set log_archive_dest_2='SERVICE=pocdbdg_tns ASYNC VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=pocdbdg' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid='*';
alter system set fal_server='pocdb_tns' scope=both sid='*';
15) 修改Far Sync2库参数
alter system set log_archive_config='DG_CONFIG=(pocdb,pocdbfs1,pocdbfs2,pocdbdg)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/pocdbfs2/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pocdbfs2' scope=both sid='*';
alter system set log_archive_dest_2='SERVICE=pocdbdg_tns ASYNC VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=pocdbdg' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid='*';
alter system set fal_server='pocdb_tns' scope=both sid='*';
16) 确认配置完成
SQL> select * from v$dataguard_config;
DB_UNIQUE_NAME PARENT_DBUN DEST_ROLE CURRENT_SCN CON_ID
------------------------------ ------------------------------ ----------------- ----------- ----------
POCDB NONE PRIMARY DATABASE 802346 0
pocdbfs1 POCDB FAR SYNC INSTANCE 802267 0
pocdbdg pocdbfs1 PHYSICAL STANDBY 802267 0
pocdbfs2 UNKNOWN UNKNOWN 0 0
SQL>
SQL> select dest_name,status,type,destination,error from v$archive_dest_status where dest_id<=4;
DEST_NAME STATUS TYPE DESTINATION ERROR
-------------------- --------- ---------- ---------------------------------------- -----------
LOG_ARCHIVE_DEST_1 VALID LOCAL /u01/app/oracle/oradata/pocdb/archive
LOG_ARCHIVE_DEST_2 ALTERNATE FAR SYNC pocdbfs1_tns ORA-03113:
LOG_ARCHIVE_DEST_3 VALID FAR SYNC pocdbfs2_tns
LOG_ARCHIVE_DEST_4 ALTERNATE UNKNOWN pocdbdg_tns
DGMGRL> show configuration
Configuration - config1
Protection Mode: MaxPerformance
Members:
pocdb - Primary database
pocdbdg - Physical standby database
pocdbfs1 - Far sync instance
pocdbfs2 - Far sync instance
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 28 seconds ago)
DGMGRL>
三、 Far Sync高可用测试
1. 当前状态
SQL> select dest_name,status,type,destination,error from v$archive_dest_status where dest_id<=4;
DEST_NAME STATUS TYPE DESTINATION ERROR
---------------------- --------- ----------- --------------------------------------- -------
LOG_ARCHIVE_DEST_1 VALID LOCAL /u01/app/oracle/oradata/pocdb/archive
LOG_ARCHIVE_DEST_2 ALTERNATE PHYSICAL pocdbdg_tns
LOG_ARCHIVE_DEST_3 VALID FAR SYNC pocdbfs1_tns
LOG_ARCHIVE_DEST_4 ALTERNATE FAR SYNC pocdbfs2_tns
SQL>
DGMGRL> show configuration
Configuration - config1
Protection Mode: MaxPerformance
Members:
pocdb - Primary database
pocdbfs1 - Far sync instance
pocdbdg - Physical standby database
Members Not Receiving Redo:
pocdbfs2 - Far sync instance (alternate of pocdbfs1)
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 11 seconds ago)
DGMGRL>
Far Sync1工作,Far Sync2备用。
2. 停止Far Sync1
SQL>
--停止Far Sync1实例:
SQL> shutdown abort
ORACLE instance shut down.
SQL>
--查看归档链路
DEST_NAME STATUS TYPE DESTINATION ERROR
-------------------- --------- ----------- --------------------------------------- ------------------------------------------------
LOG_ARCHIVE_DEST_1 VALID LOCAL /u01/app/oracle/oradata/pocdb/archive
LOG_ARCHIVE_DEST_2 ALTERNATE PHYSICAL pocdbdg_tns
LOG_ARCHIVE_DEST_3 ALTERNATE FAR SYNC pocdbfs1_tns ORA-03113: end-of-file on communication channel
LOG_ARCHIVE_DEST_4 VALID FAR SYNC pocdbfs2_tns
SQL>
DGMGRL> show configuration
Configuration - config1
Protection Mode: MaxPerformance
Members:
pocdb - Primary database
pocdbfs2 - Far sync instance (alternate of pocdbfs1)
pocdbdg - Physical standby database
Members Not Receiving Redo:
pocdbfs1 - Far sync instance
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 57 seconds ago)
DGMGRL>
Far Sync1已经处于备用,而Far Sync2开始工作。
3. 停止Far Sync2
SQL>
--停止Far Sync2实例:
SQL> shutdown abort
ORACLE instance shut down.
SQL>
--查看归档链路
DEST_NAME STATUS TYPE DESTINATION ERROR
--------------------- --------- ---------- --------------------------------------- ----------------------------------
LOG_ARCHIVE_DEST_1 VALID LOCAL /u01/app/oracle/oradata/pocdb/archive
LOG_ARCHIVE_DEST_2 ALTERNATE PHYSICAL pocdbdg_tns
LOG_ARCHIVE_DEST_3 VALID FAR SYNC pocdbfs1_tns
LOG_ARCHIVE_DEST_4 ALTERNATE FAR SYNC pocdbfs2_tns ORA-03135: connection lost contact
SQL>
DGMGRL> show configuration
Configuration - config1
Protection Mode: MaxPerformance
Members:
pocdb - Primary database
pocdbfs1 - Far sync instance
pocdbdg - Physical standby database
Members Not Receiving Redo:
pocdbfs2 - Far sync instance (alternate of pocdbfs1)
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 52 seconds ago)
DGMGRL>
Far Sync2已经处于备用,而Far Sync1开始工作。
四、 Far Sync最佳实践
部署Far Sync时,尽量满足如下最佳实践。
1). 主库与Far Sync库之间的网络延迟足够低。
2). 主库与Far Sync库之间的网络带宽足够大。
3). 开启redo传输压缩。
4). 主库与Far Sync库之间的网络实现冗余链路。
5). Far Sync库的standby log file必须放在IOPS非常大的存储设备上。