Oracle 10g Dataguard Broker Failover切换与Observer

设置从库的日志模式为SYNC,为改为Max Availability模式做好准备:
EDIT DATABASE stdby SET PROPERTY 'LogXptMode'='SYNC';

DGMGRL> EDIT DATABASE stdby SET PROPERTY 'LogXptMode'='SYNC';
Property "LogXptMode" updated

也设置主库日志模式为SYNC,为以后主库切换为从库再切回来做准备:
EDIT DATABASE pri SET PROPERTY 'LogXptMode'='SYNC';

DGMGRL> EDIT DATABASE pri SET PROPERTY 'LogXptMode'='SYNC';
Property "LogXptMode" updated

设置主从库为Max Availability模式:
EDIT CONFIGURATION SET PROTECTION MODE AS MAXAVAILABILITY;

DGMGRL> EDIT CONFIGURATION SET PROTECTION MODE AS MAXAVAILABILITY;

Operation requires shutdown of instance "prod" on database "pri"
Shutting down instance "prod"...
Database closed.
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "prod" on database "pri"
Starting instance "prod"...
ORACLE instance started.
Database mounted.

配置主从库的Failover的目标:
edit database pri set property 'FastStartFailoverTarget'='stdby';

DGMGRL> edit database pri set property 'FastStartFailoverTarget'='stdby';
Property "FastStartFailoverTarget" updated

edit database stdby set property 'FastStartFailoverTarget'='pri';

DGMGRL> edit database stdby set property 'FastStartFailoverTarget'='pri';
Property "FastStartFailoverTarget" updated

设定FastStartFailoverThreshold值,这个设置是决定了primary坏了多长时间之后会执行自动的failover操作,这里我们设置的是30秒:
EDIT CONFIGURATION SET PROPERTY FastStartFailoverThreshold = 30;

DGMGRL> EDIT CONFIGURATION SET PROPERTY FastStartFailoverThreshold = 30;
Property "faststartfailoverthreshold" updated

检查主从库都在flashback开启状态:
select name, current_scn, flashback_on from v$database;

SQL> select name, current_scn, flashback_on from v$database;

NAME      CURRENT_SCN FLASHBACK_ON
--------- ----------- ------------------
PROD           732929 YES

如果不是,启用flashback:
alter system set db_recovery_file_dest_size=2G;
alter system set db_recovery_file_dest='/u01/app/oracle/flash_recovery_area/';
alter database flashback on;


启用Fast-Start Failover:
ENABLE FAST_START FAILOVER;

DGMGRL> ENABLE FAST_START FAILOVER;
Enabled.

从机上开启Obserser:
start observer;

DGMGRL> start observer;
Observer started
启动成功,屏幕进入等待输出状态。

设置delaymins:
edit database pri set property delaymins=1;  
edit database stdby set property delaymins=1;


主机上查看配置状态:
show configuration;

DGMGRL> show configuration;
Configuration
  Name:                broker_prod
  Enabled:             YES
  Protection Mode:     MaxAvailability
  Fast-Start Failover: ENABLED
  Databases:
    pri   - Primary database
    stdby - Physical standby database
          - Fast-Start Failover target
Current status for "broker_prod":
SUCCESS
可以看到Fast-Start Failover都启动成功了。

做主机故障测试,看能否自动切换到从机:
主库上非正常关闭
shutdown abort;

SQL> shutdown abort
ORACLE instance shut down.

看从机上observer输出
13:38:21.03  Thursday, July 26, 2012
Initiating fast-start failover to database "stdby"...
Performing failover NOW, please wait...
Failover succeeded, new primary is "stdby"
13:38:28.73  Thursday, July 26, 2012

显示Fast-Start Failover 自动故障切换成功。

从库上查看instance状态:
select instance_name,host_name,database_status,instance_role from v$instance;

SQL> select instance_name,host_name,database_status,instance_role from v$instance;

INSTANCE_NAME    HOST_NAME  DATABASE_STATUS   INSTANCE_ROLE
---------------- ---------- ----------------- ------------------
stdby            xxxxstdby  ACTIVE            PRIMARY_INSTANCE

从库上查看数据库状态:
select open_mode,database_role from v$database;

SQL> select open_mode,database_role from v$database;

OPEN_MODE  DATABASE_ROLE
---------- ----------------
READ WRITE PRIMARY

表明故障自动切换成功。

恢复主库:
startup


SQL> startup
ORACLE instance started.

Total System Global Area  419430400 bytes
Fixed Size                  1219736 bytes
Variable Size             192938856 bytes
Database Buffers          218103808 bytes
Redo Buffers                7168000 bytes
Database mounted.
ORA-16649: database will open after Data Guard broker has evaluated Fast-Start Failover status
显示启动到mount状态,登台broker评估故障状态,reinstate主库。

再观察从库上observer的输出:
14:07:04.31  Thursday, July 26, 2012
Initiating reinstatement for database "pri"...
Reinstating database "pri", please wait...
Operation requires shutdown of instance "prod" on database "pri"
Shutting down instance "prod"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "prod" on database "pri"
Starting instance "prod"...
ORACLE instance started.
Database mounted.
Continuing to reinstate database "pri" ...
Reinstatement of database "pri" succeeded
14:08:12.52  Thursday, July 26, 2012
显示observer检测到主库的变化,在reinstate主库,只到最后成功。

查看主库状态:
select open_mode,database_role from v$database;

SQL> select open_mode,database_role from v$database;

OPEN_MODE  DATABASE_ROLE
---------- ----------------
MOUNTED    PHYSICAL STANDBY

查看主库mrp进程:
ps -ef |grep mrp

$ ps -ef |grep mrp
oracle    3341     1  0 14:06 ?        00:00:00 ora_mrp0_prod
oracle    3592 15046  0 14:09 pts/4    00:00:00 grep mrp

可以确认主库现已恢复到PHYSICAL STANDBY 状态了。

猜你喜欢

转载自wwtang9527.iteye.com/blog/1607860