DG有3个种保护模式:
1.最大性能模式
2.最高可用模式
3.最大保护模式
今天来做个关于保护模式的测试
当我们配置完DG,默认使用的是最大性能保护模式:
SYS@PDA> select open_mode,database_role,protection_mode,protection_level from v$database;
OPEN_MODE DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------- ---------------- -------------------- --------------------
READ WRITE PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
先修改为最高可用保护模式
SYS@PDA> alter database set standby database to maximize availability;
Database altered.
SYS@PDA> select protection_mode,protection_level from v$database;
PROTECTION_MODE PROTECTION_LEVEL
-------------------- --------------------
MAXIMUM AVAILABILITY
RESYNCHRONIZATION
此时,出现了一个重新同步的操作,此时去备库查看,依然是最高性能模式,说明模式并没有修改成功
SYS@PDADG> select open_mode,database_role,protection_mode,protection_level from v$database;
OPEN_MODE DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------- ---------------- -------------------- --------------------
MOUNDED PH
YSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM
PERFORMANCE
查看DG状态,没有发现什么异常
SYS@PDA> select message from
v$dataguard_status
;
MESSAGE
--------------------------------------------------------------------------------
ARC0: Archival started
ARC1: Archival started
Error 1034 received logging on to the standby
LGWR: Error 1034 creating archivelog file 'PDADG'
LGWR: Failed to archive log 2 thread 1 sequence 26 (1034)
ARC1: Becoming the 'no FAL' ARCH
ARC1: Becoming the 'no SRL' ARCH
ARC2: Archival started
ARC0: Becoming the heartbeat ARCH
ARCH shutting down
ARC2: Archival stopped
LGWR: Standby redo logfile selected to archive thread 1 sequence 28
LGWR: Standby redo logfile selected for thread 1 sequence 28 for destination LOG
_ARCHIVE_DEST_2
ARC1: LGWR is actively archiving destination LOG_ARCHIVE_DEST_2
ARC1: Standby redo logfile selected for thread 1 sequence 27 for destination LOG
_ARCHIVE_DEST_2
继续修改到最高保护模式
SYS@PDA> alter database set standby database to maximize protection;
alter database set standby database to maximize protection
*
ERROR at line 1:
ORA-01126: database
must be mounted
in this instance and not open in any
instance
提示必须要在MOUNT状态下才能修改,比最高可用要求高了点
SYS@PDA> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PDA> startup mount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 96470416 bytes
Database Buffers 213909504 bytes
Redo Buffers 2973696 bytes
Database mounted.
此时,由于是再mount状态下,PROTECTION_LEVEL从
RESYNCHRONIZATION变成了
UNPROTECTED,这2中状态只是在不同的启动模式中的区别,但有一点是共同的,就是表示之前的模式修改都没有成功,尽管PROTECTION_MODE中已经显示为我们期望的模式
SYS@PDA> select protection_mode,protection_level from v$database;
PROTECTION_MODE PROTECTION_LEVEL
-------------------- --------------------
MAXIMUM AVAILABILITY
UNPROTECTED
SYS@PDA> alter database set standby database to maximize protection;
Database altered.
SYS@PDA> select protection_mode,protection_level from v$database;
PROTECTION_MODE PROTECTION_LEVEL
-------------------- --------------------
MAXIMUM PROTECTION UNPROTECTED
执行切换到最高保护模式后,仅仅是把
PROTECTION_MODE的值变成了最高保护,
PROTECTION_LEVEL的值依然是
UNPROTECTED,即不受保护的模式
此时如果去open数据库,就会报ORA-03113,与数据库通信中断
SYS@PDA> alter database open;
alter database open
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
跟踪一下alert日志,来看看有什么故障线索
SYS@PDA> !
[oracle@ocm1 ~]$ tail -100 /u01/app/oracle/admin/PDA/bdump/alert_PDA.log
Tue Jan 13 16:12:24 2015
Starting ORACLE instance (normal)
Cannot determine all dependent dynamic libraries for /proc/self/exe
Unable to find dynamic library libocr10.so in search paths
RPATH = /ade/aime1_build2101/oracle/has/lib/:/ade/aime1_build2101/oracle/lib/:/ade/aime1_build2101/oracle/has/lib/:
LD_LIBRARY_PATH is not set!
The default library directories are /lib and /usr/lib
Unable to find dynamic library libocrb10.so in search paths
Unable to find dynamic library libocrutl10.so in search paths
Unable to find dynamic library libocrutl10.so in search paths
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 2
Autotune of undo retention is turned on.
IMODE=BR
ILAT =15
LICENSE_MAX_USERS = 0
SYS auditing is disabled
ksdpec: called for event 13740 prior to event group initialization
Starting up ORACLE RDBMS Version: 10.2.0.1.0.
System parameters with non-default values:
processes = 120
sga_max_size = 314572800
__shared_pool_size = 88080384
__large_pool_size = 4194304
__java_pool_size = 4194304
__streams_pool_size = 0
sga_target = 314572800
control_files = /u01/app/oracle/oradata/PDA/Disk1/control01.ctl, /u01/app/oracle/oradata/PDA/Disk2/control02.ctl, /u01/app/oracle/oradata/PDA/Disk3/control03.ctl
db_file_name_convert = PDADG, PDA
log_file_name_convert = PDADG, PDA
__db_cache_size = 213909504
log_archive_config = DG_CONFIG=(PDA,PDADG)
log_archive_dest_1 = LOCATION=/home/oracle/arch1
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=PDA
log_archive_dest_2 = SERVICE=PDADG LGWR SYNC
--注意这里使用的传归档参数,并没有使用AFFIRM
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=PDADG
log_archive_dest_state_1 = ENABLE
log_archive_dest_state_2 = ENABLE
log_archive_format = %t_%s_%r.arc
fal_client = PDA
fal_server = PDADG
log_buffer = 2927616
log_checkpoint_interval = 10000
db_files = 80
db_file_multiblock_read_count= 8
standby_file_management = AUTO
undo_management = AUTO
undo_tablespace = undotbs
remote_login_passwordfile= EXCLUSIVE
global_names = FALSE
parallel_max_servers = 5
max_dump_file_size = 10240
db_name = PDA
db_unique_name = PDA
PMON started with pid=2, OS id=11923
PSP0 started with pid=3, OS id=11925
MMAN started with pid=4, OS id=11927
DBW0 started with pid=5, OS id=11929
LGWR started with pid=6, OS id=11931
CKPT started with pid=7, OS id=11933
SMON started with pid=8, OS id=11935
RECO started with pid=9, OS id=11937
MMON started with pid=10, OS id=11939
MMNL started with pid=11, OS id=11941
Tue Jan 13 16:12:25 2015
ALTER DATABASE MOUNT
Tue Jan 13 16:12:29 2015
Setting recovery target incarnation to 1
Tue Jan 13 16:12:29 2015
Successful mount of redo thread 1, with mount id 280730729
Tue Jan 13 16:12:29 2015
Database mounted in Exclusive Mode
Completed: ALTER DATABASE MOUNT
Tue Jan 13 16:13:45 2015
alter database set standby database to maximize protection
Tue Jan 13 16:13:45 2015
Completed: alter database set standby database to maximize protection
Tue Jan 13 16:14:25 2015
alter database open
Tue Jan 13 16:14:25 2015
LGWR: STARTING ARCH PROCESSES
ARC0 started with pid=13, OS id=11949
Tue Jan 13 16:14:25 2015
ARC0: Archival started
ARC1: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
LGWR: Primary database is in MAXIMUM PROTECTION mode
LGWR: Destination LOG_ARCHIVE_DEST_1 is not serviced by LGWR
LGWR: Minimum of 1 synchronous standby database required
Tue Jan 13 16:14:25 2015
Errors in file /u01/app/oracle/admin/PDA/bdump/PDA_lgwr_11931.trc:
ORA-16072: a minimum of one standby database destination is required
Tue Jan 13 16:14:25 2015
Errors in file /u01/app/oracle/admin/PDA/bdump/PDA_lgwr_11931.trc:
ORA-16072: a minimum of one standby database destination is required
LGWR: terminating instance due to error 16072
Instance terminated by LGWR, pid = 11931
这里提示很明显,提示目标归档目录
LOG_ARCHIVE_DEST_1
没有被LGWR服务,这里有点纳闷了,LGO_ARCHIVE_DEST_1在我的DG配置环境中,其实只是一个本地目录,配置的参数是:
log_archive_dest_1= LOCATION=/home/oracle/arch1
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
这和LGWR应该没关系才对啊,还提示最小要分配一个和备库同步,其实是有配置的,那就是
log_archive_dest_1,这个目录是作为远程归档目录,和备库进行归档传递的
再来看一下trace文件,提示的是同样的错误
[oracle@ocm1 ~]$ tail -100 /u01/app/oracle/admin/PDA/bdump/PDA_lgwr_11931.trc
Dump file /u01/app/oracle/admin/PDA/bdump/PDA_lgwr_11931.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - PDAuction
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME = /u01/app/oracle/PDAuct/10.2.0/db_1
System name: Linux
Node name: ocm1.localdomain
Release: 2.6.32-300.10.1.el5uek
Version: #1 SMP Wed Feb 22 17:22:40 EST 2012
Machine: i686
Instance name: PDA
Redo thread mounted by this instance: 1
Oracle process number: 6
*** 2015-01-13 16:14:25.587
*** SERVICE NAME:() 2015-01-13 16:14:25.587
*** SESSION ID:(133.1) 2015-01-13 16:14:25.587
Destination LOG_ARCHIVE_DEST_1 is not serviced by LGWR
Standby database verification failed:16072
ORA-16072: a minimum of one standby database destination is required
error 16072 detected in background process
ORA-16072: a minimum of one standby database destination is required
[oracle@ocm1 ~]$ exit
exit
trace文件中也是这个ORA-16072的错误
SYS@PDA>
SYS@PDA> show parameter log_archvie_dest_1
ERROR:
ORA-03114: not connected to ORACLE
SYS@PDA> conn / as sysdba
Connected to an idle instance.
SYS@PDA> show parameter log_archive_dest_1
ORA-01034: ORACLE not available
SYS@PDA> startup mount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 96470416 bytes
Database Buffers 213909504 bytes
Redo Buffers 2973696 bytes
Database mounted.
SYS@PDA> show parameter log_archive_dest_1
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1 string LOCATION=/home/oracle/arch1
VALID_FOR=(ALL_LOGFILES,ALL_
ROLES)
DB_UNIQUE_NAME=PDA
log_archive_dest_10 string
SYS@PDA> show parameter log_archive_dest_2
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string SERVICE=PDADG LGWR SYNC
VALID_FOR=(ONLINE_LOGFILES,P
RIMARY_ROLE)
DB_UNIQUE_NAME=PDADG
SYS@PDA> alter system set log_archive_dest_2='SERVICE=PDADG LGWR SYNC VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG';
alter system set log_archive_dest_2='SERVICE=PDADG LGWR SYNC VALID_OR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG'
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-16025: parameter LOG_ARCHIVE_DEST_2 contains repeated or conflicting
attributes
SYS@PDA> alter system set log_archive_dest_2='SERVICE=PDADG LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG';
alter system set log_archive_dest_2='SERVICE=PDADG LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG'
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-16025: parameter LOG_ARCHIVE_DEST_2 contains repeated or conflicting
attributes
提示参数取值重复或有冲突,这里觉得挺奇怪的,最大保护模式不是应该需要这些参数配置的嘛,为何又不让设置
SYS@PDA> alter system set LOG_ARCHIVE_DEST_2='SERVICE=PDADG LGWR VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG';
System altered.
改为只保留一个LGWR,去掉其他2个,就可以设置
SYS@PDA> select protection_mode,protection_level from v$database;
PROTECTION_MODE PROTECTION_LEVEL
-------------------- --------------------
MAXIMUM PROTECTION UNPROTECTED
目前数据库启动到的是MOUNT状态,PROTECTION_LEVEL仍然是UNPROTECTED状态,但是无法open数据库,以open就断开连接
SYS@PDA> alter database open;
alter database open
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
SYS@PDA> shutdown immediate
ORA-24324: service handle not initialized
ORA-01041: internal error. hostdef extension doesn't exist
SYS@PDA> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - PDAuction
With the Partitioning, OLAP and Data Mining options
[oracle@ocm1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - PDAuction on Tue Jan 13 16:33:47 2015
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SYS@PDA> startup mount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 96470416 bytes
Database Buffers 213909504 bytes
Redo Buffers 2973696 bytes
Database mounted.
SYS@PDA> alter system set LOG_ARCHIVE_DEST_2=
2 'SERVICE=PDADG LGWR SYNC AFFIRM
3 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
4 DB_UNIQUE_NAME=PDADG';
System altered.
重新设置了一次,这次没报冲突,设置成功了,然后再查看保护模式,尽管仍然是UNPROTECTED,但是却可以open数据库了
SYS@PDA> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PROTECTION UNPROTECTED
SYS@PDA> alter database open;
Database altered.
再次查看,发现PROTECTION_LEVEL的状态值也终于改过来了,和PROTECTION_MODE一致了
SYS@PDA> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PROTECTION MAXIMUM PROTECTION
而这个时候,备库也终于都变成了最大保护模式:
SYS@PRODSTD> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PROTECTION MAXIMUM PROTECTION
SYS@PDA> alter system set LOG_ARCHIVE_DEST_2='SERVICE=PDADG LGWR VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=PDADG LGWR VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG'
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-16159: Cannot change protected standby destination attributes
此时已经是最大保护模式,如果想要去掉SYNC和AFFIRM这2个参数,就会报错,因为最大保护模式时需要它们的,尤其是AFFIRM,之前一直不能成功修改,或者修改后不能open数据库,就是因为没有加这个参数导致的
继续修改为最高可用模式(无须在mount状态下修改)
SYS@PDA> alter database set standby database to maximize availability;
Database altered.
SYS@PDA> alter system set LOG_ARCHIVE_DEST_2='SERVICE=PDADG LGWR VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG';
System altered.
当前允许在参数中去掉SYNC和AFFIRM而只留一个LGWR,其实只是因为修改并没有完全生效,PROTECTION_LEVEL的状态并没有和PROTECTION_MODE相同
SYS@PDA> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM AVAILABILITY RESYNCHRONIZATION
再加上SYNC参数,结果一样,还是
RESYNCHRONIZATION状态
SYS@PDA> alter system set LOG_ARCHIVE_DEST_2='SERVICE=PDADG LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PDADG';
System altered.
SYS@PDA> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM AVAILABILITY RESYNCHRONIZATION
SYS@PDA> alter database open;
alter database open
*
ERROR at line 1:
ORA-01531: a database already open by the instance
SYS@PDA> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PDA> startup
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 96470416 bytes
Database Buffers 213909504 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
重启以后,发现PROTECTION_LEVEL的状态由之前的
RESYNCHRONIZATION又变为和PROTECTION_MODE一致了
SYS@PDA> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
SYS@PDA> alter database set standby database to maximize protection;
alter database set standby database to maximize protection
*
ERROR at line 1:
ORA-01126: database must be mounted in this instance and not open in any
instance
最高保护模式需要在mount状态下修改
SYS@PDA> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PDA> startup mount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 96470416 bytes
Database Buffers 213909504 bytes
Redo Buffers 2973696 bytes
Database mounted.
SYS@PDA> alter database set standby database to maximize protection;
Database altered.
SYS@PDA> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PROTECTION UNPROTECTED
SYS@PDA> alter database open;
Database altered.
SYS@PDA> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PROTECTION MAXIMUM PROTECTION
这次虽然没有设置AFFIRM,但是却也能正常open数据库
总结:
不知是否是一种巧合,还是有其他原理。就目前实验得到的结果而言,我是这么认为的,当从低的级别设置到高的级别时,对参数的要求比较严格,必须设置LGWR,SYNC,AFFIRM,尤其是AFFIRM,如果不添加,直接导致无法启动主库。但是当从高级别的保护模式往低调整时,对参数的要求就没那么严格了,最后一个步骤中,去掉了AFFIRM,只剩下LGWR和SYNC,最后依然能顺利设置为最大保护模式,并且能顺利open数据库。这一结论还有待更进一步的测试,也许我的猜测不一定准确。
最后附上PROTECTION_MODE和PROTECTION_LEVEL两个字段值得含义表:
PROTECTION_MODE |
VARCHAR2(20) |
Protection mode currently in effect for the database:
- MAXIMUM PROTECTION - Database is running in maximized protection mode
- MAXIMUM AVAILABILITY - Database is running in maximized availability mode
- RESYNCHRONIZATION - Database is running in resynchronization mode
- MAXIMUM PERFORMANCE - Database is running in maximized protection mode
- UNPROTECTED - Database is unprotected (this normally occurs when the primary database is mounted and not open)
|
PROTECTION_LEVEL |
VARCHAR2(20) |
Aggregated protection mode currently in effect for the database:
- MAXIMUM PROTECTION - Database is running in maximized protection mode
- MAXIMUM AVAILABILITY - Database is running in maximized availability mode
- RESYNCHRONIZATION - Database is running in resynchronization mode
- MAXIMUM PERFORMANCE - Database is running in maximized protection mode
- UNPROTECTED - Database is unprotected (this normally occurs when the primary database is mounted and not open)
Note: This column is an aggregation of the PROTECTION_MODE of all standby archive log destinations. |
后记:刚才又测试了几次,当保护模式从高往低调,也必须设置AFFIRM,否则最高可用和最大保护模式是无法设置的!之前的理解有偏颇。