Oracle9iR2 Data Guard的保护模式的详细信息
一、三种保护模式
最大性能(maximize performance):这是data guard默认的保护模式。primay上的事务commit前不需要从standby上收到反馈信息。该模式在primary故障时可能丢失数据,但standby对primary的性能影响最校
最大可用(maximize availability):在正常情况下,最大可用模式和最大保护模式一样;在standby不可用时,最大可用模式会自动降低成最大性能模式,所以standby故障不会导致primay不可用。只要至少有一个standby可用的情况下,即使primarydown机,也能保证不丢失数据。
最大保护(maximize protection):最高级别的保护模式。primay上的事务在commit前必须确认redo已经传递到至少一个standby上,如果所有standby不可用,则primary会挂起。该模式能保证零数据丢失。
二、查看当前保护模式
SQL> select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
三、两种日志传输方式
Arch:传统的日志传送方式。现在只有在最大性能模式时才能采用。归档日志通过primary上的arch进程传送给standby的RFS进程。
LGWr:oracle9i开始可以使用LGWR即时将日志传送到standby,而不再需要等到归档操作时才传送,已减少可能的数据丢失。在三种保护模式下都可以使用该方式传送日志。使用LGWR方式传送,在standby必须先建立standby redo logfile
四、查看日志传送方式
SQL> select dest_name,archiver from v$archive_dest;
DEST_NAME ARCHIVER
-------------------- ----------
LOG_ARCHIVE_DEST_1 ARCH
LOG_ARCHIVE_DEST_2 LGWR
LOG_ARCHIVE_DEST_3 ARCH
LOG_ARCHIVE_DEST_4 ARCH
LOG_ARCHIVE_DEST_5 ARCH
LOG_ARCHIVE_DEST_6 ARCH
LOG_ARCHIVE_DEST_7 ARCH
LOG_ARCHIVE_DEST_8 ARCH
LOG_ARCHIVE_DEST_9 ARCH
LOG_ARCHIVE_DEST_10 ARCH
10 rows selected.
五、添加standby redo logfile
首先停止standby的自动恢复状态
SQL> alter database recover managed standby database finish;
Database altered.
如果没有停止自动恢复状态就添加standby logfile,会报错:
ORA-01156: recovery in progress may need access to files
SQL> alter database add standby logfile group 4 ('d:oracleoradatateststandby
04.redo') size 10m;
Database altered.
SQL> alter database add standby logfile group 5 ('d:oracleoradatateststandby
05.redo') size 10m;
Database altered.
SQL> alter database add standby logfile group 6 ('d:oracleoradatateststandby
06.redo') size 10m;
Database altered.
SQL> alter database add standby logfile group7 ('d:oracleoradatateststandby
07.redo') size 10m;
Database altered.
注意standby logfile的group名不能和primary的redo logfile group重复,因为我的primay已经有3组日志了,这里添加的四组standby logfile从group 4开始。standby redo logfile的大小要和primary保持一致,另外由于主备库归档的速度可能不一致,standby redo logfile一般要比主库的online redo logfile多建一组,否则在最大保护模式时可能导致主库挂起。
六、设置standby的归档路径
log_archive_dest_1='location=d:oraclearchtest'
七、在primary上修改为用LGWR传送日志
SQL> alter system set log_archive_dest_2='service=test lgwr async';
System altered.
在primary上swith logfile
SQL> alter system switch logfile;
System altered.
在primary的alter中可以看到成功的记录
Thu Nov 23 12:41:28 2006
ALTER SYSTEM SET log_archive_dest_2='service=test lgwr async' SCOPE=BOTH;
Thu Nov 23 12:43:12 2006
******************************************************************
LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2
******************************************************************
Creating archive destination LOG_ARCHIVE_DEST_2: 'test'
LNS0 started with pid=13
Thu Nov 23 12:43:16 2006
LGWR: Beginning to archive log 3 thread 1 sequence 102
Thread 1 advanced to log sequence 102
Current log# 3 seq# 102 mem# 0: D:ORACLEORADATANINGREDO03.LOG
Thu Nov 23 12:43:16 2006
ARC0: Evaluating archive log 2 thread 1 sequence 101
ARC0: LGWR is actively archiving destination LOG_ARCHIVE_DEST_2
ARC0: Beginning to archive log 2 thread 1 sequence 101
Creating archive destination LOG_ARCHIVE_DEST_2: 'test'
Creating archive destination LOG_ARCHIVE_DEST_1: 'D:ORACLEARCHNINGARC00101.001'
ARC0: Completed archiving log 2 thread 1 sequence 101
八、切换standby的保护模式
切换保护模式的操作必须在primay执行,且primay必须处于mount状态
如果在open状态执行,则报错:
ORA-01126: database must be mounted EXCLUSIVE and not open for this operation
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 134814580 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 143360 bytes
Database mounted.
SQL> alter database set standby database to maximize availability;
Database altered.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
注意,这时需要先修改日志传送方式为lgwr同步方式,否则,数据库是无法open的
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 134814580 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 143360 bytes
Database mounted.
SQL> alter system set log_archive_dest_2='service=test lgwr sync';
System altered.
SQL> alter database open;
Database altered.
再来看看当前保护模式
SQL> select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
切换成maximize protection也需要类似的步骤,这里就不演示了。
本文地址:http://www.45fan.com/a/question/73603.html