12c新特性:Far Sync

12c版本dataguard中引入了一个新特性:far sync备库,它作为级联备库主要作为redo log仓库给终端库使用。它不包含任何数据文件,在far sync备库上只有日志传输服务是启用的。

far sync备库的好处主要在于它可以处于最大可用模式下作为主库的一个本地归档日志库,而其后的物理或者逻辑备库可以放在较远的其他地方。当之前的主备库距离较远时,可以先通过同步的方式将日志快速传到far sync备库,而后从far sync备库将日志通过异步的方式传到物理备库,这样既兼顾了效率同时也保证了安全。

Far Sync工作原理

原理其实很简单,farsync端接收到从主库同步过来的数据,然后将其异步推送给最多29个远端目的地。

far sync并不是一个标准的数据库,因为它只包含一些必要的文件,比如控制文件、spfile和standby redo日志。这个库必须要放在离主库较近的地方,这样才能确保较低的延时。为了高可用性,一般建议不要放在同一个物理位置。

如果主库出现故障,则跟以往一样实施failover,而far sync实例的存在保证了在failover过程中数据的安全性和完整性。

测试环境

Host Role
HostA Primary
HostB Far Sync
HostC Standby

这里已经有一个正在运行的主备库,为了简化,这里就只在HostB上新建一个far sync实例。

创建Far Sync实例

从主库上创建所需的控制文件和pfile

1
2
3
alter database create far sync instance controlfile as '/u01/app/oracle/control01.ctl';

create pfile='/u01/app/oracle/initora12c.ora' from spfile;

将文件传到HostB

1
scp control01.ctl initora12c.ora racnode1:/u01/app/oracle/

编辑pfile,修改control_files参数的路径

1
*.control_files='/u01/app/oracle/oradata/ORA12C/controlfile/control01.ctl'

创建相关目录,并将文件移到到合适位置

1
2
3
4
5
6
7
mkdir -p /u01/app/oracle/fast_recovery_area/ora12c/ORA12C
mkdir -p /u01/app/oracle/admin/ora12c/adump
mkdir -p /u01/arch/ora12c
mkdir -p /u01/app/oracle/oradata/ORA12C/{controlfile,onlinelog}

mv control01.ctl oradata/ORA12C/controlfile/
mv initora12c.ora product/12.2.0/dbhome_1/dbs/

通过spfile启动farsync实例,然后修改成mount状态,创建standby redo log

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
SQL> create spfile from pfile;

File created.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1946157056 bytes
Fixed Size 8794264 bytes
Variable Size 587206504 bytes
Database Buffers 1342177280 bytes
Redo Buffers 7979008 bytes
Database mounted.

set linesize 300
col member for a100
select GROUP#,MEMBER,TYPE from v$logfile;

GROUP# MEMBER TYPE
---------- ---------------------------------------------------------------------------------------------------- -------
3 /u01/app/oracle/oradata/ORA12C/onlinelog/o1_mf_3_gcm27r5h_.log ONLINE
4 /u01/app/oracle/oradata/ORA12C/onlinelog/o1_mf_4_gcwxsqn3_.log STANDBY
2 /u01/app/oracle/oradata/ORA12C/onlinelog/o1_mf_2_gcm27r55_.log ONLINE
5 /u01/app/oracle/oradata/ORA12C/onlinelog/o1_mf_5_gcwxswdf_.log STANDBY
1 /u01/app/oracle/oradata/ORA12C/onlinelog/o1_mf_1_gcm27r4t_.log ONLINE
6 /u01/app/oracle/oradata/ORA12C/onlinelog/o1_mf_6_gcwxt172_.log STANDBY
7 /u01/app/oracle/oradata/ORA12C/onlinelog/o1_mf_7_gcwxt5w8_.log STANDBY

Dataguard 配置

三个库的tnsnames.ora都要修改成一样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
ORA12C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = testyum)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ora12c)
)
)

ora12c_dg =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = stbyum)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ora12c)
)
)

ora12c_fs =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = racnode1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ora12c)
)
)

修改far sync实例的db_unique_name,启用dg broker

1
2
3
4
5
6
alter system set db_unique_name='ORA12C_FS' scope=spfile;

alter system set dg_broker_start=true;

-- 重启实例
startup mount

连到主库的dgmgrl,增加far sync实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
DGMGRL> connect sys/oracle
Connected to "ora12c"
Connected as SYSDG.
DGMGRL> add FAR_SYNC ora12c_fs as connect identifier is ora12c_fs;
far sync instance "ora12c_fs" added

DGMGRL> show configuration verbose;

Configuration - ora12ccfg

Protection Mode: MaxPerformance
Members:
ora12c - Primary database
ora12c_dg - Physical standby database
ora12c_fs - Far sync instance (disabled)

Properties:
FastStartFailoverThreshold = '30'
OperationTimeout = '30'
TraceLevel = 'USER'
FastStartFailoverLagLimit = '30'
CommunicationTimeout = '180'
ObserverReconnect = '0'
FastStartFailoverAutoReinstate = 'TRUE'
FastStartFailoverPmyShutdown = 'TRUE'
BystandersFollowRoleChange = 'ALL'
ObserverOverride = 'FALSE'
ExternalDestination1 = ''
ExternalDestination2 = ''
PrimaryLostWriteAction = 'CONTINUE'
ConfigurationWideServiceName = 'ora12c_CFG'

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

目前far sync还未激活,需要设置redo路由再激活

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
edit database ora12c set property redoroutes='(local:ora12c_fs sync)';

edit far_sync ora12c_fs set property redoroutes='(ora12c:ora12c_dg)';

edit configuration set protection mode as MaxAvailability;

enable far_sync ora12c_fs;

DGMGRL> show configuration verbose;

Configuration - ora12ccfg

Protection Mode: MaxAvailability
Members:
ora12c - Primary database
ora12c_fs - Far sync instance
ora12c_dg - Physical standby database

Properties:
FastStartFailoverThreshold = '30'
OperationTimeout = '30'
TraceLevel = 'USER'
FastStartFailoverLagLimit = '30'
CommunicationTimeout = '180'
ObserverReconnect = '0'
FastStartFailoverAutoReinstate = 'TRUE'
FastStartFailoverPmyShutdown = 'TRUE'
BystandersFollowRoleChange = 'ALL'
ObserverOverride = 'FALSE'
ExternalDestination1 = ''
ExternalDestination2 = ''
PrimaryLostWriteAction = 'CONTINUE'
ConfigurationWideServiceName = 'ora12c_CFG'

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

这里设置了从主库到far sync是通过sync的方式,而far sync的redo路由设置成从primary获取的redo都会发送到物理备库。

比较三个库生成的log_archive_dest_n参数

DATABASE log_archive_dest_1 log_archive_dest_2
Pri LOCATION=/u01/arch/ora12c VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ora12c service=”ora12c_fs”, SYNC AFFIRM delay=0 optional compression=disable max_failure=0 max_connections=1 reopen=300 db_unique_name=”ora12c_fs” net_timeout=30, valid_for=(online_logfile,all_roles)
Far Sync location=”USE_DB_RECOVERY_FILE_DEST”, valid_for=(STANDBY_LOGFILE,STANDBY_ROLE) service=”ora12c_dg”, ASYNC NOAFFIRM delay=0 optional compression=disable max_failure=0 max_connections=1 reopen=300 db_unique_name=”ora12c_dg” net_timeout=30, valid_for=(standby_logfile,all_roles)
Stb LOCATION=/u01/arch/ora12c VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ora12c_dg

可以看到Pri的日志是只会传送到far sync实例,所以做个测试看是否数据能正常同步

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- primary
sys@ORA12C> create table test as select * from dba_tables where 1=2;

Table created.

sys@ORA12C> drop table test purge;

Table dropped.

-- standby
sys@ORA12C> select * from test;

no rows selected

sys@ORA12C> /
select * from test
*
ERROR at line 1:
ORA-00942: table or view does not exist

配置全部结束,far sync主要是针对较远距离的传输场景,兼顾了数据的安全性也减轻了主库的压力,而far sync本身也比较轻量,不会造成瓶颈。


12c新特性:Far Sync
https://www.xbdba.com/2019/05/10/12c-newfeature-far-sync/
作者
xbdba
发布于
2019年5月10日
许可协议