Data Guard是Oracle高可用性HA的重要解决方案。针对不同的系统保护需求,DG提供了三种不同类型的保护模式(Protection Mode),分别为:最大保护(Maximum Protection)、最大可用(MaximumAvailability)和最大性能(Maximum performance)。在实际应用场景下,我们需要根据不同的业务场景和数据可用性需求,来设置DG环境的保护类型。
1、三种保护模式Protection Mode
三种保护模式是DG的核心概念。DG本质上是一种基于Redo Log的数据同步机制。Undo和Redo是Oracle早期奠定行业地位的核心技术。Undo负责记录事务操作的前镜像,而Redo负责记录事务操作的后镜像。在Oracle事务commit的动作中,写入日志文件是一个一定需要完成的动作。写入日志文件之后,即使立刻出现严重的实例终止事件,在重新启动实例的时候也会进行实例恢复动作,将事务落实。
在DG环境中,无论采用何种初始化方法,都是确保一个Primary和Standby的初始化数据一致,之后Primary一端接收的事务类型操作,均会以归档日志串列的方式传递到Standby端的standby redo log和归档日志列表中,最后重复应用这些日志,实现Primary和Standby端一致。
Primary和Standby是相互为备份的冗余结构,Standby跟随Primary的情况,反映了HA结构的可用性级别。理论上,最保险的策略是一个事务要保证在Primary和Standby上都提交了,才返回给用户说已经完成。这样是可以保证主备库完全一致的最保险做法。另一个极端情况,就是主库“自顾自”进行事务处理,独立将日志进行传输,也不用管日志是否传输到或者应用到。
针对不同的传输情况,DG区分为三种保护类型:
ü 最大可用模式Maximum Availability
在官方文档中,对这种模式的描述如下:
“This protection mode provides thehighest level of data protection that is possible without compromising theavailability of a primary database. Transactions do not commit until all redodata needed to recover those transactions has been written to the online redolog and to the standby redo log on at least one synchronized standby database.If the primary database cannot write its redo stream to at least onesynchronized standby database, it operates as if it were in maximum performancemode to preserve primary database availability until it is again able to writeits redo stream to a synchronized standby database.”
Maximum Availability模式下,事务只有在所有相关日志都被传输到至少一个Standby端日志的时候,才可以正式提交。但是,如果Primary在传输日志的过程中,发现所有standby端都不能进行传输,模式会退化到最大性能模式(Maximum Performance)工作方式。应该说,MaximumAvailability是一种自适应的保护模式,当出现问题的时候,DG会退而求其次,确保Primary主库事务进行。
ü 最大性能模式(Maximum Performance)
官方文档中介绍如下:“This protection mode providesthe highest level of data protection that is possible without affecting theperformance of a primary database. This is accomplished by allowingtransactions to commit as soon as all redo data generated by those transactionshas been written to the online log. Redo data is also written to one or morestandby databases, but this is done asynchronously with respect to transactioncommitment, so primary database performance is unaffected by delays in writingredo data to the standby database(s).
This protection mode offers slightly lessdata protection than maximum availability mode and has minimal impact onprimary database performance.
This is the default protection mode.”
最大性能模式是在不影响主库工作情况下,可以提供的最高数据保护级别。当事务进行提交的时候,主库不会去确认日志是否写入到备库中,更不会确认是否被apply。这种方式下,主库的工作性能是不会收到备库提交应用的影响的。当然,这种保护模式会有一定的事务数据丢失,但是绝对不会出现数据误提交的情况。
对DG而言,最大性能模式是默认的保护模式。当我们完成了DG安装之后,就自动进入了Maximum Performance模式。
ü 最大保护模式(Maximum Protection)
最大保护模式在官方中的描述为:
“This protection mode ensures that nodata loss will occur if the primary database fails. To provide this level ofprotection, the redo data needed to recover a transaction must be written toboth the online redo log and to the standby redo log on at least onesynchronized standby database before the transaction commits. To ensure thatdata loss cannot occur, the primary database will shut down, rather thancontinue processing transactions, if it cannot write its redo stream to atleast one synchronized standby database.
Transactions on the primary are consideredprotected as soon as Data Guard has written the redo data to persistent storagein a standby redo log file. Once that is done, acknowledgment is quickly madeback to the primary database so that it can proceed to the next transaction.This minimizes the impact of synchronous transport on primary databasethroughput and response time. To fully benefit from complete Data Guardvalidation at the standby database, be sure to operate in real-time apply modeso that redo changes are applied to the standby database as fast as they arereceived. Data Guard signals any corruptions that are detected so thatimmediate corrective action can be taken.”
最大保护模式是完全HA架构理想中的事务模式。如果Primary数据库进行一个事务,连带Standby数据库也要同步进行操作。如果由于网络、执行模式等原因,Standby不能够跟上主库的操作,那么主库会放弃事务,并且强制停库。
保护模式的三种和数据库之间传输日志的机制是密切相关的。主要体现是否同步传输Redo日志和对日志进行确认两个方面。我们配置三种日志模式,一定要以Log_Archive_Config参数配置为基础。
Maximum Availability | Maximum Performance | Maximum Protection |
AFFIRM | NOAFFIRM | AFFIRM |
SYNC | ASYNC | SYNC |
DB_UNIQUE_NAME | DB_UNIQUE_NAME | DB_UNIQUE_NAME |
下面通过一系列的测试,来分析三种保护模式的工作行为方式。
2、环境介绍
笔者使用环境为Oracle 11gR2,具体版本为11.2.0.4。主备库环境已经搭建完成,同步保护模式是采用默认方式。
主库信息:
SQL> select name, open_mode,database_role, protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- ------------------------------------ --------------------
VLIFE READWRITE PRIMARY MAXIMUM PERFORMANCE
SQL> select instance_name fromv$instance;
INSTANCE_NAME
----------------
vlife
主库与备库连接方式,采用默认的异步非确认方式。
SQL> select dest_id, dest_name,TRANSMIT_MODE, ASYNC_BLOCKS, AFFIRM TYPE, VALID_NOW, VALID_TYPE, VALID_ROLE,DB_UNIQUE_NAME from v$archive_dest where status<>'INACTIVE';
DEST_IDDEST_NAME TRANSMIT_MODEASYNC_BLOCKS TYPEVALID_NOW VALID_TYPE VALID_ROLE DB_UNIQUE_NAME
---------- --------------------------------- ------------ ---- ---------------- --------------- ---------------------------
1LOG_ARCHIVE_DEST_1 SYNCHRONOUS 0NO YES ALL_LOGFILES ALL_ROLES NONE
2LOG_ARCHIVE_DEST_2 ASYNCHRONOUS 61440NO YES ONLINE_LOGFILE PRIMARY_ROLEvlifesb
此时,传输通道配置。
SQL> show parameter LOG_ARCHIVE_DEST_2;
NAME TYPE VALUE
----------------------------------------------- ------------------------------
log_archive_dest_2 string SERVICE=vlifesbvalid_for=(online_logfiles,primary_role) db_unique_name=vlifesb
log_archive_dest_20 string
log_archive_dest_21 string
备库信息如下:
SQL> select name, open_mode,database_role, protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- ------------------------------------ --------------------
VLIFE READONLY WITH APPLY PHYSICALSTANDBY MAXIMUM PERFORMANCE
SQL> select instance_name fromv$instance;
INSTANCE_NAME
----------------
vlifesb
SQL> col dest_name for a20;
SQL> select dest_id, dest_name,TRANSMIT_MODE, ASYNC_BLOCKS, AFFIRM TYPE, VALID_NOW, VALID_TYPE, VALID_ROLE,DB_UNIQUE_NAME from v$archive_dest where status<>'INACTIVE';
DEST_ID DEST_NAME TRANSMIT_MODEASYNC_BLOCKS TYPEVALID_NOW VALID_TYPE VALID_ROLE DB_UNIQUE_NAME
---------- --------------------------------- ------------ ---- ---------------- --------------- ------------------------------------------
1LOG_ARCHIVE_DEST_1 SYNCHRONOUS 0NO YES ALL_LOGFILES ALL_ROLES NONE
2LOG_ARCHIVE_DEST_2 ASYNCHRONOUS 61440NO WRONG VALID_TYPE ONLINE_LOGFILE PRIMARY_ROLE vlife
32 STANDBY_ARCHIVE_DESTSYNCHRONOUS 0NO YES ALL_LOGFILES ALL_ROLES NONE
SQL> show parameter LOG_ARCHIVE_DEST_2;
NAME TYPE VALUE
----------------------------------------------- ------------------------------
log_archive_dest_2 string SERVICE=vlifevalid_for=(online_logfiles,primary_role) db_unique_name=vlife
log_archive_dest_20 string
log_archive_dest_21 string
3、最大可用模式Maximum Availability Mode测试
当前从默认的最大性能切换到最大可用模式,首先需要满足将日志传输模式进行修改。
SQL> alter system setlog_archive_dest_2='SERVICE=vlifesb sync affirm net_timeout=30valid_for=(online_logfiles,primary_role) db_unique_name=vlifesb';
System altered
SQL> select dest_id, dest_name,TRANSMIT_MODE, ASYNC_BLOCKS, AFFIRM TYPE, VALID_NOW, VALID_TYPE, VALID_ROLE,DB_UNIQUE_NAME, NET_TIMEOUT from v$archive_dest where status<>'INACTIVE';
DEST_IDDEST_NAME TRANSMIT_MODEASYNC_BLOCKS TYPEVALID_NOW VALID_TYPE VALID_ROLE DB_UNIQUE_NAME NET_TIMEOUT
---------- --------------------------------- ------------ ---- ---------------- --------------- ------------------------------------------ -----------
1LOG_ARCHIVE_DEST_1 SYNCHRONOUS 0NO YES ALL_LOGFILES ALL_ROLES NONE 0
2LOG_ARCHIVE_DEST_2 PARALLELSYNC 0YES YES ONLINE_LOGFILE PRIMARY_ROLEvlifesb 30
此时,将保护模式使用alter database进行设置。
SQL> alter database set standby database to maximizeavailability;
Database altered
SQL> select name, open_mode,database_role, protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- ------------------------------------ --------------------
VLIFE READWRITE PRIMARY MAXIMUM AVAILABILITY
在切换动作的时候,主库日志情况如下:
Wed Oct 21 15:13:48 2015
alter database set standby database tomaximize availability
Completed: alter database set standbydatabase to maximize availability
Wed Oct 21 15:13:49 2015
Destination LOG_ARCHIVE_DEST_2 isUNSYNCHRONIZED –发现没有同步,需要补充。
******************************************************************
LGWR: Setting 'active' archival fordestination LOG_ARCHIVE_DEST_2
******************************************************************
Wed Oct 21 15:13:49 2015
NSS2 started with pid=34, OS id=9186
LGWR: Standby redo logfile selected toarchive thread 1 sequence 82
LGWR: Standby redo logfile selected forthread 1 sequence 82 for destination LOG_ARCHIVE_DEST_2
Thread 1 advanced to log sequence 82 (LGWRswitch)
Current log# 3 seq# 82 mem# 0:/u01/app/oracle/oradata/VLIFE/onlinelog/o1_mf_3_c1kb1c24_.log
Current log# 3 seq# 82 mem# 1:/u01/app/oracle/fast_recovery_area/VLIFE/onlinelog/o1_mf_3_c1kb1c43_.log
Wed Oct 21 15:13:53 2015
Archived Log entry 104 added for thread 1sequence 81 ID 0xfad4f44b dest 1:
Wed Oct 21 15:13:54 2015
ARC3: Archive log rejected (thread 1sequence 81) at host 'vlifesb'
FAL[server, ARC3]: FAL archive failed, seetrace file.
ARCH: FAL archive failed. Archivercontinuing
ORACLE Instance vlife - Archival Error.Archiver continuing.
Wed Oct 21 15:14:42 2015
Destination LOG_ARCHIVE_DEST_2 isSYNCHRONIZED
LGWR: Standby redo logfile selected toarchive thread 1 sequence 83
LGWR: Standby redo logfile selected forthread 1 sequence 83 for destination LOG_ARCHIVE_DEST_2
Thread 1 advanced to log sequence 83 (LGWRswitch)
Current log# 1 seq# 83 mem# 0:/u01/app/oracle/oradata/VLIFE/onlinelog/o1_mf_1_c1kb19q4_.log
Current log# 1 seq# 83 mem# 1:/u01/app/oracle/fast_recovery_area/VLIFE/onlinelog/o1_mf_1_c1kb19sb_.log
Wed Oct 21 15:14:42 2015
Archived Log entry 107 added for thread 1sequence 82 ID 0xfad4f44b dest 1:
在Primary端,在进行切换之后,Oracle发现传输状态不是同步情况。于是自动加快进行日志传输和同步动作。在Standby端,也可以看到后续追赶动作。
SQL> select name, open_mode,database_role, protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- ------------------------------------ --------------------
VLIFE READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUMAVAILABILITY
Standby端上的日志追赶动作。
Wed Oct 21 08:27:05 2015
Primary database is in MAXIMUM PERFORMANCE mode
Re-archiving standby log 4 thread 1 sequence 80
Wed Oct 21 08:27:05 2015
Media Recovery Waiting for thread 1sequence 81
RFS[14]: Assigned to RFS process 31500
RFS[14]: Selected log 5 for thread 1sequence 81 dbid -87496857 branch 892734889
Wed Oct 21 08:27:05 2015
Archived Log entry 76 added for thread 1sequence 80 ID 0xfad4f44b dest 1:
Recovery of Online Redo Log: Thread 1 Group5 Seq 81 Reading mem 0
Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_5_c265gqd8_.log
Mem# 1:/u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_5_c265gqj0_.log
Wed Oct 21 15:13:52 2015
Primary database is in MAXIMUM AVAILABILITYmode
Changing standby controlfile to MAXIMUMAVAILABILITY mode
Changing standby controlfile toRESYNCHRONIZATION level
Standby controlfile consistent with primary
RFS[15]: Assigned to RFS process 969
RFS[15]: Selected log 4 for thread 1sequence 82 dbid -87496857 branch 892734889
Wed Oct 21 15:13:53 2015
Archived Log entry 77 added for thread 1sequence 81 ID 0xfad4f44b dest 1:
Wed Oct 21 15:13:53 2015
Media Recovery Waiting for thread 1sequence 82 (in transit)
Recovery of Online Redo Log: Thread 1 Group4 Seq 82 Reading mem 0
Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log
Mem# 1:/u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log
Wed Oct 21 15:14:41 2015
Archived Log entry 78 added for thread 1sequence 82 ID 0xfad4f44b dest 1:
Wed Oct 21 15:14:41 2015
Media Recovery Waiting for thread 1sequence 83
Wed Oct 21 15:14:42 2015
Primary database is in MAXIMUM AVAILABILITYmode
Changing standby controlfile to MAXIMUMAVAILABILITY level
Standby controlfile consistent with primary
RFS[16]: Assigned to RFS process 976
RFS[16]: Selected log 4 for thread 1sequence 83 dbid -87496857 branch 892734889
Recovery of Online Redo Log: Thread 1 Group4 Seq 83 Reading mem 0
Mem# 0:/u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log
Mem# 1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log
此时,两个库由于网络通畅,同步状态正常,同步测试正常。
(Maximium Availiablity模式下使用)
--主库下
SQL> create table t_m as select * fromdba_objects where rownum<10;
Table created
--Standby下
SQL> select count(*) from t_m;
COUNT(*)
----------
9
如果此时中断应用日志,Standby情况如下:
SQL> alter database recover managedstandby database cancel;
Database altered
SQL> select name, open_mode,database_role, protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- ------------------------------------ --------------------
VLIFE READONLY PHYSICALSTANDBY MAXIMUMAVAILABILITY
日志情况如下:
Wed Oct 21 15:20:49 2015
alter database recover managed standbydatabase cancel
Wed Oct 21 15:20:49 2015
MRP0: Background Media Recovery cancelledwith status 16037
Errors in file/u01/app/oracle/diag/rdbms/vlifesb/vlifesb/trace/vlifesb_pr00_17539.trc:
ORA-16037: user requested cancel of managedrecovery operation
Managed Standby Recovery not using Real TimeApply
Recovery interrupted!
Recovered data files to a consistent state atchange 1692263
Wed Oct 21 15:20:49 2015
MRP0: Background Media Recovery processshutdown (vlifesb)
Managed Standby Recovery Canceled (vlifesb)
Completed: alter database recover managedstandby database cancel
如果此时再中断监听器,中断连接。此时数据库不能做到实时同步。
[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctlstop
LSNRCTL for Linux: Version 11.2.0.4.0 -Production on 21-OCT-2015 15:24:17
Copyright (c) 1991, 2013,Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
The command completed successfully
--主库
***********************************************************************
Fatal NI connect error 12541, connectingto:
(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.19.90)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=vlifesb)(CID=(PROGRAM=oracle)(HOST=vLIFE-URE-OT-DB-PRIMARY)(USER=oracle))))
VERSION INFORMATION:
TNSfor Linux: Version 11.2.0.4.0 - Production
TCP/IPNT Protocol Adapter for Linux: Version 11.2.0.4.0 - Production
Time: 21-OCT-2015 15:24:38
Tracing not turned on.
Tns error struct:
ns main err code:12541
TNS-12541: TNS:no listener
ns secondary errcode: 12560
nt main err code:511
TNS-00511: No listener
nt secondary errcode: 111
nt OS err code: 0
Error 12541 received logging on to thestandby
Check whether the listener is up andrunning.
PING[ARC2]: Heartbeat failed to connect tostandby 'vlifesb'. Error is 12541.
强制日志切换。
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> select * fromv$archive_dest_status;
DEST_IDDEST_NAME STATUS TYPE DATABASE_MODE RECOVERY_MODE PROTECTION_MODE DESTINATION STANDBY_LOGFILE_COUNTSTANDBY_LOGFILE_ACTIVE ARCHIVED_THREAD# ARCHIVED_SEQ# APPLIED_THREAD#APPLIED_SEQ#ERROR SRLDB_UNIQUE_NAME SYNCHRONIZATION_STATUSSYNCHRONIZED GAP_STATUS
---------- -------------------- ----------------------- --------------- ----------------------- ------------------------------------------------------------------------------------------------------------------------- ---------------------- ---------------- ---------------------------- ----------------------------------------------------------------------------------------------- ------------------------------ ---------------------- ------------ ------------------------
1LOG_ARCHIVE_DEST_1 VALID LOCAL OPEN IDLE MAXIMUMPERFORMANCE /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch 0 0 1 85 0 0 NO NONE CHECKCONFIGURATION NO
2LOG_ARCHIVE_DEST_2 ERROR PHYSICAL OPEN_READ-ONLY IDLE RESYNCHRONIZATION vlifesb 3 0 1 82 1 82ORA-12541: TNS: ???à?????ò YESvlifesb CHECKCONNECTIVITY NO RESOLVABLEGAP
SQL> select recid, name, sequence# fromv$archived_log where sequence#>82;
RECIDNAME SEQUENCE#
----------------------------------------------------------------------------------------------------
108vlifesb 83
109/u01/app/oracle/fast_recovery_area/VLIFE/archivelog/2015_10_21/o1_mf_1_83_c2ghkz 83
110/u01/app/oracle/fast_recovery_area/VLIFE/archivelog/2015_10_21/o1_mf_1_84_c2ghl0 84
111/u01/app/oracle/fast_recovery_area/VLIFE/archivelog/2015_10_21/o1_mf_1_85_c2ghl4 85
而standby端,归档日志就没有传输到。
SQL> select recid, name, sequence# fromv$archived_log where sequence#>82;
RECIDNAME SEQUENCE#
----------------------------------------------------------------------------------------------------
79/u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_21/o1_mf_1_83_c2gh 83
SQL> select group#, dbid, archived fromv$standby_log;
GROUP#DBID ARCHIVED
-------------------------------------------------- --------
4UNASSIGNED NO
5UNASSIGNED NO
6UNASSIGNED YES
此时,Primary和Standby的连接明显被中断,日志不能传送,也就达不到同步确认的设置要求。但是此时,Primary还是可以进行事务操作。
(事务可以进行)
SQL> insert into t_m select * fromdba_objects where rownum<10;
9 rows inserted
SQL> commit;
Commit complete
此时,如果恢复两者连接,启动监听器和日志应用。
[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctlstart
LSNRCTL for Linux: Version 11.2.0.4.0 -Production on 21-OCT-2015 15:51:46
Copyright (c) 1991, 2013,Oracle. All rights reserved.
Starting/u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 -Production
System parameter file is/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to
(篇幅原因,有省略…….)
SQL> alter database recover managedstandby database using current logfile disconnect from session;
Database altered
之后主库和从库日志上进行归档日志传输和后续同步动作,篇幅原因,日志信息省略。
从上面实验中,我们可以看到最大可用性模式的核心即使“可用”。所谓可用,即使保证Primary和Standby整体的可用。如果在日志传输通路顺畅,两者之间会维持严格的同步关系,行为类似于最大保护模式。但是,如果连接或者同步动作不能满足要求,DG是不会终止实例运行,而是退而求其次,进行一种类似最大性能模式的工作方式。
4、最大保护模式Maximum Protection
最大保护模式是DG可以提供的最高保护级别,建立在日志同步传输和确认的基础上。同样,可以使用alter database方法进行设置。
SQL> alter database set standby database to maximizeprotection;
Database altered
主库上,可以查看到状态变化和日志情况。
SQL> select name, open_mode, database_role,protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- -------------------- ------------------------------------
VLIFE READWRITE PRIMARY MAXIMUM PROTECTION
Wed Oct 21 16:17:46 2015
alter database set standby database to maximizeprotection
Completed: alter database set standby database tomaximize protection
Wed Oct 21 16:17:50 2015
Destination LOG_ARCHIVE_DEST_2 is SYNCHRONIZED
******************************************************************
LGWR: Setting 'active' archival for destinationLOG_ARCHIVE_DEST_2
******************************************************************
LGWR: Standby redo logfile selected to archive thread 1sequence 89
LGWR: Standby redo logfile selected for thread 1 sequence89 for destination LOG_ARCHIVE_DEST_2
Thread 1 advanced to log sequence 89 (LGWR switch)
Currentlog# 1 seq# 89 mem# 0:/u01/app/oracle/oradata/VLIFE/onlinelog/o1_mf_1_c1kb19q4_.log
Currentlog# 1 seq# 89 mem# 1:/u01/app/oracle/fast_recovery_area/VLIFE/onlinelog/o1_mf_1_c1kb19sb_.log
Wed Oct 21 16:17:50 2015
Archived Log entry 119 added for thread 1 sequence 88 ID0xfad4f44b dest 1:
备库上信息也是同样变化信息。
SQL> selectname, open_mode, database_role, protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- -------------------- ------------------------------------
VLIFE READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PROTECTION
Wed Oct 21 15:52:45 2015
Primary database is in MAXIMUM AVAILABILITY mode
Changing standby controlfile to MAXIMUM AVAILABILITYlevel
Standby controlfile consistent with primary
RFS[21]: Assigned to RFS process 1172
RFS[21]: Selected log 4 for thread 1 sequence 88 dbid-87496857 branch 892734889
Recovery of Online Redo Log: Thread 1 Group 4 Seq 88Reading mem 0
Mem#0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log
Mem#1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log
Wed Oct 21 16:17:49 2015
Archived Log entry 84 added for thread 1 sequence 88 ID0xfad4f44b dest 1:
Wed Oct 21 16:17:49 2015
Media Recovery Waiting for thread 1 sequence 89
Wed Oct 21 16:17:50 2015
Primary database is in MAXIMUM PROTECTION mode
Changing standby controlfile to MAXIMUM PROTECTION mode
Standby controlfile consistent with primary
RFS[22]: Assigned to RFS process 1358
RFS[22]: Selected log 4 for thread 1 sequence 89 dbid-87496857 branch 892734889
Recovery of Online Redo Log: Thread 1 Group 4 Seq 89Reading mem 0
Mem#0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log
Mem#1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log
如果此时,我们终止Standby端的同步动作。
SQL> alter database recover managed standby databasecancel;
Database altered
SQL> selectname, open_mode, database_role, protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- -------------------- ------------------------------------
VLIFE READONLY PHYSICAL STANDBY MAXIMUM PROTECTION
此时,如果主库有事务执行,是否可以执行成功呢?
主库事务:
SQL> delete t_m;
9 rows deleted
SQL> commit;
Commit complete
备库
SQL> select count(*) from t_m;
COUNT(*)
----------
9
事务操作并没有能够传递到备库上。当前的日志传输机制是正常的,如果我们切断了这种连接,处在最大保护模式下的Primary端如何。
[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on21-OCT-2015 16:25:30
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
The command completed successfully
主库中立刻就有中断信息的显示:
***********************************************************************
Fatal NI connect error 12541, connecting to:
(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.19.90)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=vlifesb)(CID=(PROGRAM=oracle)(HOST=vLIFE-URE-OT-DB-PRIMARY)(USER=oracle))))
VERSIONINFORMATION:
TNS for Linux: Version 11.2.0.4.0 - Production
TCP/IP NT Protocol Adapter for Linux:Version 11.2.0.4.0 - Production
Time:21-OCT-2015 16:25:41
Tracingnot turned on.
Tnserror struct:
nsmain err code: 12541
TNS-12541: TNS:no listener
nssecondary err code: 12560
ntmain err code: 511
TNS-00511: No listener
ntsecondary err code: 111
ntOS err code: 0
Error 12541 received logging on to the standby
Check whether the listener is up and running.
PING[ARC2]: Heartbeat failed to connect to standby 'vlifesb'.Error is 12541.
此时,我们在Primary上进行事务操作。
SQL> insert into t_m select * from dba_objects whererownum<100;
99 rows inserted
SQL> commit;
Commit complete
SQL> select group#, sequence#, status from v$log;
GROUP# SEQUENCE# STATUS
---------- ---------- ----------------
1 89 CURRENT
2 87 INACTIVE
3 88 INACTIVE
事务操作成功。如果我们尝试重新启动standby,是不被允许的。
SQL> SQL> shutdown immediate
ORA-01154: database busy. Open, close, mount, and dismountnot allowed now
日志:
Wed Oct 21 16:34:41 2015
Attempt to shut down Standby Database
Standby Database operating in NO DATA LOSS mode
Detected primary database alive, shutdown primary first,shutdown aborted
但是,切换日志强制归档过程的时候,数据库立即发现Standby存在问题,停库。
SQL> alter system switch logfile;
alter system switch logfile
ORA-03113: 通信通道的文件结尾
进程 ID: 9478
会话 ID: 394 序列号: 33
Destination LOG_ARCHIVE_DEST_2 is UNSYNCHRONIZED
LGWR: All standby destinations have failed
******************************************************
WARNING: All standby database destinations have failed
WARNING: Instance shutdown required to protect primary
******************************************************
LGWR (ospid: 30597): terminating the instance due toerror 16098
Wed Oct 21 16:43:44 2015
System state dump requested by (instance=1, osid=30597(LGWR)), summary=[abnormal instance termination].
System State dumped to trace file/u01/app/oracle/diag/rdbms/vlife/vlife/trace/vlife_diag_30587_20151021164344.trc
Dumping diagnostic data indirectory=[cdmp_20151021164344], requested by (instance=1, osid=30597 (LGWR)),summary=[abnormal instance termination].
Instance terminated by LGWR, pid = 30597
此时,standby端日志信息:
--Standby端
Wed Oct 21 16:43:42 2015
Archived Log entry 85 added for thread 1 sequence 89 ID0xfad4f44b dest 1:
Wed Oct 21 16:43:43 2015
Wed Oct 21 16:43:43 2015
RFS[20]: Possible network disconnect with primarydatabaseRFS[17]: Possible network disconnect with primary database
说明:在最大保护状态的时候,如果Primary发现备库传输日志有问题,出于保护的必要,就会自动停机。
下面可以进行操作恢复,备库首先恢复应用日志状态:
SQL> alter database recover managed standby databaseusing current logfile disconnect from session;
Database altered
Wed Oct 21 16:46:19 2015
alter database recover managed standby database usingcurrent logfile disconnect from session
Attempt to start background Managed Standby Recoveryprocess (vlifesb)
Wed Oct 21 16:46:19 2015
MRP0 started with pid=25, OS id=1495
MRP0: Background Managed Standby Recovery process started(vlifesb)
started logmerger process
Wed Oct 21 16:46:24 2015
Managed Standby Recovery starting Real Time Apply
Parallel Media Recovery started with 4 slaves
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Media Recovery Log/u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_21/o1_mf_1_89_c2gn1ylm_.arc
Media Recovery Waiting for thread 1 sequence 90
Completed: alter database recover managed standbydatabase using current logfile disconnect from session
注意,此时第二个事务对应数据表t_m的数据已经发生变化。这说明之前虽然已经停止监听活动,但是依赖之前的已经确立连接,还是将日志传输过去。
SQL> select count(*) from t_m;
COUNT(*)
----------
99
尝试启动主库:
[oracle@vLIFE-URE-OT-DB-PRIMARY trace]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 2116:48:23 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 2471931904 bytes
Fixed Size 2255752 bytes
VariableSize 738198648 bytes
DatabaseBuffers 1711276032 bytes
RedoBuffers 20201472 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 9617
Session ID: 580 Serial number: 5
Error 12541 received logging on to the standby
Check whether the listener is up and running.
LGWR: Error 12541 creating archivelog file 'vlifesb'
Crash Recovery Foreground: All standby destinations havefailed
******************************************************
WARNING: All standby database destinations have failed
WARNING: Instance shutdown required to protect primary
******************************************************
USER (ospid: 9617): terminating the instance due to error16098
System state dump requested by (instance=1, osid=9617),summary=[abnormal instance termination].
System State dumped to trace file/u01/app/oracle/diag/rdbms/vlife/vlife/trace/vlife_diag_9581_20151021164839.trc
Dumping diagnostic data in directory=[cdmp_20151021164839],requested by (instance=1, osid=9617), summary=[abnormal instance termination].
Instance terminated by USER, pid = 9617
在mount到open的过程中,启动被终止。这个是可以理解的,在Standby端,监听器没有启动。
[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on21-OCT-2015 16:50:20
Copyright (c) 1991, 2013, Oracle. All rights reserved.
(篇幅原因,有省略……)
Service "vlifesb" has 1 instance(s).
Instance"vlifesb", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
此时,再次启动数据库主库,操作成功。
SQL> startup
ORACLE instance started.
Total System Global Area 2471931904 bytes
FixedSize 2255752 bytes
VariableSize 738198648 bytes
DatabaseBuffers 1711276032 bytes
RedoBuffers 20201472 bytes
Database mounted.
Database opened.
最后,从最大保护“退化”到最大性能模式。
SQL> alter database set standby database to maximizeperformance
2 ;
Database altered
SQL> select name, open_mode, database_role,protection_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE
--------- -------------------- ------------------------------------
VLIFE READWRITE PRIMARY MAXIMUM PERFORMANCE
5、结论
Oracle DG的三种模式,是与归档日志传输机制紧密相关的。归档日志传输确定了保护模式的基础前提,通过alter database set操作定义了数据库行为,特别是主库工作行为