前面我们对DATAGUARD做了一些介绍并搭建了一个测试环境,还提到了DATAGUARD有3种保护模式,但是如何来设置这3种模式并没有提到。在这里我们将对3种模式进行介绍以及他们的配置过程。

一、三种保护模式的相关配置比较


     最大保护    最大可用    最大性能
REDO写进程    LGWR    LGWR    LGWR或者ARCH
网络传输模式    SYNC    SYNC    LGWR进程时SYNC or ASYNC;ARCH进程时ASYNC
磁盘写操作    AFFIRM    AFFIRM    AFFIRM or NOAFFIRM
是否需要standby redolog    YES    YES    可没有但推荐有

ARCH——把完整的REDO文件拷贝到standby数据服务器上。
LGWR——ASYNC异步
redo written by LGWR to local disk
LGWR将redo写到本地LOG文件
LNSn进程读取redo,传到standby服务器上。
——SYNC同步
redo written to standby by LGWR
LGWR将redo信息直接写到standby 数据库服务器上

下面以我们前面搭建的测试环境为例,来说明一下何如来配置这3种保护模式。我们先来看看搭建环境时配置的参数:


LOG_ARCHIVE_DEST_2='SERVICE=OCM3 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=OCM3'

LGWR ASYNC ——应用在线redo方式进行数据同步,网络传输模式ASYNC(异步),从参数可以判断我们建立的DG环境使用的是最大性能模式。
从v$database视图,可以进一步的判断。


SYS@OCM3>select name,protection_mode,protection_level from v$database;
 
NAME      PROTECTION_MODE      PROTECTION_LEVEL
--------- -------------------- --------------------
PROD      MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

二、将最大性能模式转变为最大可用模式
1、备份主备节点spfile文件

primary


SYS@OCM3>create pfile='/home/oracle/pfile_20140327.ora' from spfile;
 
File created.

standby

SYS@PROD>create pfile='/home/oracle/pfile_20140327.ora' from spfile;
 
File created.

2、取消日志传输

SYS@PROD>alter database recover managed standby database cancel;
 
Database altered.

3、修改相关参数
primary


SYS@OCM3>alter system set log_archive_dest_2='SERVICE=PROD LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD' scope=both;
 
System altered.

standby

SYS@PROD>alter system set log_archive_dest_2='SERVICE=OCM3 LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=OCM3' scope=both;
 
System altered.

4、将库修改为最大可用模式
primary


SYS@OCM3>alter database set standby database to maximize availability;
 
Database altered.

standby

SYS@PROD>alter database set standby database to maximize availability;
 
Database altered.

5、启动日志传输

SYS@PROD>alter database recover managed standby database disconnect from session;
 
Database altered.

6、检查保护模式
primary


SYS@OCM3>select name,protection_mode,protection_level from v$database;
 
NAME                                     PROTECTION_MODE      PROTECTION_LEVEL
---------------------------------------- -------------------- --------------------
PROD                                     MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY

standby

SYS@PROD>select name,protection_mode,protection_level from v$database;
 
NAME      PROTECTION_MODE      PROTECTION_LEVEL
--------- -------------------- --------------------
PROD      MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY

7、测试
在primary做两次日志切换


SYS@OCM3>alter system switch logfile;
 
System altered.
 
SYS@OCM3>alter system switch logfile;
 
System altered.

检查standby 的alert log 日志

-- Connected User is Valid
RFS[5]: Assigned to RFS process 29718
RFS[5]: Identified database type as 'physical standby'
Primary database is in MAXIMUM AVAILABILITY mode
Changing standby controlfile to RESYNCHRONIZATION level
Primary database is in MAXIMUM AVAILABILITY mode
Changing standby controlfile to MAXIMUM AVAILABILITY level
RFS[5]: Successfully opened standby log 5: '/u01/app/oracle/oradata/PROD/disk1/standbylog5a.log'
Thu Mar 27 14:58:33 2014
Media Recovery Log /u01/app/oracle/archlog/1_24_836758036.arc
Thu Mar 27 14:58:47 2014
Media Recovery Waiting for thread 1 sequence 25 (in transit)
Thu Mar 27 15:47:25 2014
Primary database is in MAXIMUM AVAILABILITY mode
Standby controlfile consistent with primary
RFS[5]: Successfully opened standby log 4: '/u01/app/oracle/oradata/PROD/disk1/standbylog4a.log'
Thu Mar 27 15:47:28 2014
Media Recovery Log /u01/app/oracle/archlog/1_25_836758036.arc
Media Recovery Waiting for thread 1 sequence 26 (in transit)
Thu Mar 27 15:47:53 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[6]: Assigned to RFS process 30348
RFS[6]: Identified database type as 'physical standby'
Thu Mar 27 15:49:20 2014
Primary database is in MAXIMUM AVAILABILITY mode
Standby controlfile consistent with primary
RFS[5]: Successfully opened standby log 4: '/u01/app/oracle/oradata/PROD/disk1/standbylog4a.log'
Thu Mar 27 15:49:22 2014
Media Recovery Log /u01/app/oracle/archlog/1_26_836758036.arc
Media Recovery Waiting for thread 1 sequence 27 (in transit)


检查视图
SYS@PROD>select sequence#,applied from v$archived_log;
 
 SEQUENCE# APP
---------- ---
         2 NO
         4 NO
        11 YES
        11 YES
        12 YES
        12 YES
        13 YES
        13 YES
        14 YES
        14 YES
        15 YES
 
 SEQUENCE# APP
---------- ---
        15 YES
        16 YES
        16 YES
        17 YES
        17 YES
        18 YES
        18 NO
        19 YES
        19 NO
        20 YES
        20 NO
 
 SEQUENCE# APP
---------- ---
        21 YES
        22 YES
        23 YES
        24 YES
        25 YES
        26 YES
 
28 rows selected.

发现日志传输是成功的,到这里模式从最大性能切换到最大可用完成。