环境:
OS:Centos 7
DB:11.2.0.4
一主两从
slnngk->slavea
slnngk->slaveb
observer部署在主库slnngk
ob启动脚本如下:
[oracle@dbmaster scripts]$ more start_ob.sh #!/bin/bash . /etc/profile . ~/.bash_profile dgmgrl -logfile /tmp/observer.log sys/oracle@tnsslnngk "start observer" &
1.主库slnngk关闭数据库
SQL> shutdown abort
ORACLE instance shut down.
大概等待30秒,可以看到observer输出日志,这个时候已经切换到了slavea
[oracle@dbmaster scripts]$ tail -200f /tmp/observer.log Observer started [W000 09/01 02:58:10.12] Observer started. 03:01:16.04 Wednesday, September 01, 2021 Initiating Fast-Start Failover to database "slavea"... Performing failover NOW, please wait... Failover succeeded, new primary is "slavea" 03:01:31.81 Wednesday, September 01, 2021
2.登录原备库slavea查看,这个时候主库已经关闭了,是无法登录进去的
DGMGRL> show configuration Configuration - slnngktest Protection Mode: MaxPerformance Databases: slavea - Primary database Warning: ORA-16829: fast-start failover configuration is lagging slnngk - (*) Physical standby database (disabled) ORA-16661: the standby database needs to be reinstated slaveb - Physical standby database Fast-Start Failover: ENABLED Configuration Status: WARNING
3.模拟原来的从库(现在为主库)slavea创建表
connect hxl/oracle
create table tb_test_bak as select * from tb_test;
4.将原来的主库slnngk启动到mount阶段
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
这个时候observer日志继续输出 [oracle@dbmaster scripts]$ more /tmp/observer.log Observer started [W000 09/01 02:58:10.12] Observer started. [oracle@dbmaster scripts]$ tail -200f /tmp/observer.log Observer started [W000 09/01 02:58:10.12] Observer started. 03:01:16.04 Wednesday, September 01, 2021 Initiating Fast-Start Failover to database "slavea"... Performing failover NOW, please wait... Failover succeeded, new primary is "slavea" 03:01:31.81 Wednesday, September 01, 2021 03:07:34.31 Wednesday, September 01, 2021 Initiating reinstatement for database "slnngk"... Reinstating database "slnngk", please wait... Operation requires shutdown of instance "slnngk" on database "slnngk" Shutting down instance "slnngk"... ORA-01109: database not open Database dismounted. ORACLE instance shut down. Operation requires startup of instance "slnngk" on database "slnngk" Starting instance "slnngk"... ORACLE instance started. Database mounted. Continuing to reinstate database "slnngk" ... Reinstatement of database "slnngk" succeeded 03:08:21.99 Wednesday, September 01, 2021 这里原来的主库slnngk变成了从库
5.这个时候查看ob情况,在slnngk和slave上查看都可以
DGMGRL> show configuration Configuration - slnngktest Protection Mode: MaxPerformance Databases: slavea - Primary database slnngk - (*) Physical standby database slaveb - Physical standby database Fast-Start Failover: ENABLED Configuration Status: SUCCESS
遇到的问题
1.若发现另外一个从库slaveb没有自动指向slaveb,下面尝试删除后再添加
删除后再添加,在slnngk和slave上操作都可以
DGMGRL> remove database 'slaveb'; DGMGRL> add database 'slaveb' as connect identifier is 'tnsslaveb'; DGMGRL> enable database 'slaveb';
2.切换回来发现不能自动REINSTATE
03:31:53.82 Wednesday, September 01, 2021 Initiating reinstatement for database "slavea"... Reinstating database "slavea", please wait... Operation requires shutdown of instance "slavea" on database "slavea" Shutting down instance "slavea"... Unable to connect to database ORA-12521: TNS:listener does not currently know of instance requested in connect descriptor Failed. Warning: You are no longer connected to ORACLE. Please complete the following steps and reissue the REINSTATE command: shut down instance "slavea" of database "slavea" start up and mount instance "slavea" of database "slavea" 03:32:01.89 Wednesday, September 01, 2021
按照步骤执行:
shutdown immediate
startup mount
DGMGRL> reinstate database slavea