环境:
OS:Centos 7
DB:11.2.0.4
架构:1主2从
slnngk->slavea
slnngk->slaveb
1.主库开启flashback on(若已经开启了,则省略)
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> alter database flashback on;
Database altered.
2.备库开启flashback on(备库slavea和slaveb都做同样的操作,若已经开启了,则省略)
这里在主库上登录dgmgrl
备库slavea:
在备库开启flashback之前,要先将备库的intended state的状态更改为apply-off.
DGMGRL> edit database slavea set state='apply-off';
Succeeded.
DGMGRL> show database slavea;
Database - slavea
Role: PHYSICAL STANDBY
Intended State: APPLY-OFF
Transport Lag: 0 seconds (computed 1 second ago)
Apply Lag: 0 seconds (computed 1 second ago)
Apply Rate: (unknown)
Real Time Query: OFF
Instance(s):
slavea
Database Status:
SUCCESS
sqlplus登录到备库slavea执行如下命令:
SQL> alter database flashback on;
Database altered.
打开flashback之后,要将standby数据库的intended state的状态更改为apply-on
DGMGRL> edit database slavea set state='apply-on';
Succeeded.
DGMGRL> show database slavea;
Database - slavea
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 1 second ago)
Apply Lag: 0 seconds (computed 1 second ago)
Apply Rate: (unknown)
Real Time Query: ON
Instance(s):
slavea
Database Status:
SUCCESS
备库slaveb
DGMGRL>edit database slaveb set state='apply-off';
SQL> alter database flashback on;
DGMGRL> edit database slaveb set state='apply-on';
3.配置和启用observer
官方建议observer应该与primary和standby数据库隔离,不能在一台机器上,我这里资源有限,将observer部署在主库上面
[oracle@dbmaster ~]$ pwd
/home/oracle
[oracle@dbmaster ~]$ dgmgrl -logfile /tmp/observer.log sys/oracle@tnsslnngk "start observer" &
[oracle@dbmaster ~]$ ps -ef|grep start
oracle 27400 4049 0 03:59 pts/0 00:00:00 dgmgrl start observer file=FSFO.dat
查看启动日志
[oracle@dbmaster ~]$ more fsfo.log
nohup: ignoring input
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected.
Observer started
或是写成脚本使用nohup后台运行
[oracle@dbmaster scripts]$ more start_ob.sh
#!/bin/bash
. /etc/profile
. ~/.bash_profile
dgmgrl -logfile /tmp/observer.log sys/oracle@tnsslnngk "start observer" &
4.启用failover(主库上登录)
查看fast_start failover的状态
[oracle@dbmaster ~]$ dgmgrl
DGMGRL> connect sys/oracle
DGMGRL> show fast_start failover Fast-Start Failover: DISABLED Threshold: 30 seconds Target: (none) Observer: dbmaster Lag Limit: 30 seconds Shutdown Primary: TRUE Auto-reinstate: TRUE Observer Reconnect: (none) Observer Override: FALSE Configurable Failover Conditions Health Conditions: Corrupted Controlfile YES Corrupted Dictionary YES Inaccessible Logfile NO Stuck Archiver NO Datafile Offline YES Oracle Error Conditions: (none)
启用
DGMGRL> enable fast_start failover
Error: ORA-16651: requirements not met for enabling fast-start failover
Failed.
解决办法:配置同步模式(若已经是 ASYNC 模式就不需要修改了)
EDIT DATABASE slnngk SET PROPERTY LogXptMode='async';
EDIT DATABASE slavea SET PROPERTY LogXptMode='async';
EDIT DATABASE slaveb SET PROPERTY LogXptMode='async';
如果主备的设置为最大高可用保护模式,则需要设置LogXptMode为sync
如果主备的设置为最大性能保护模式,则需要设置LogXptMode为async
我这里是最大性能模式
指定故障转移目的,我们这里将slavea作为故障目的,这里只能设置一个目的,两个的话好像不行FastStartFailoverTarget=slavea,slaveb
DGMGRL> edit database slnngk set property FastStartFailoverTarget=slavea;
DGMGRL> enable fast_start failover
Enabled.
查看
DGMGRL> show fast_start failover Fast-Start Failover: ENABLED Threshold: 30 seconds Target: slavea Observer: dbmaster Lag Limit: 30 seconds Shutdown Primary: TRUE Auto-reinstate: TRUE Observer Reconnect: (none) Observer Override: FALSE Configurable Failover Conditions Health Conditions: Corrupted Controlfile YES Corrupted Dictionary YES Inaccessible Logfile NO Stuck Archiver NO Datafile Offline YES Oracle Error Conditions: (none)
5.要是observer没有启动的话,会提示如下的错误信息
DGMGRL> show configuration;
Configuration - slnngktest
Protection Mode: MaxPerformance
Databases:
slnngk - Primary database
Error: ORA-16820: fast-start failover observer is no longer observing this database
slavea - (*) Physical standby database
Error: ORA-16820: fast-start failover observer is no longer observing this database
slaveb - Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
ERROR
后台启动observer
[oracle@dbmaster ~]$ dgmgrl -logfile /tmp/observer.log sys/oracle@tnsslnngk "start observer" &
可以写个脚本做成自启动的方式
再次查看数据库状态
DGMGRL> show configuration;
Configuration - slnngktest
Protection Mode: MaxPerformance
Databases:
slnngk - Primary database
slavea - (*) Physical standby database
slaveb - Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS
可以做成脚本开机自动执行:
[oracle@dbmaster scripts]$ more start_ob.sh
#!/bin/bash
dgmgrl -logfile /tmp/observer.log sys/oracle@tnsslnngk "start observer" &
后台运行
nohup ./start_ob.sh > start_ob.out 2>&1 &
或是将脚本添加到启动文件,先启动监听,然后启动数据库,最后启动observer
[root@dbmaster ~]# more /etc/rc.d/rc.local
su - oracle -lc "/u01/app/oracle/product/11.2.0.4/db_1/bin/lsnrctl start"
su - oracle -lc "/u01/app/oracle/product/11.2.0.4/db_1/bin/dbstart"
su - oracle -c "/home/oracle/scripts/start_ob.sh"
遇到的问题:
[oracle@dbmaster scripts]$ more fsfo.log
nohup: ignoring input
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected.
Error: ORA-16647: could not start more than one observer
解决办法:
stop observer