共计 1994 个字符,预计需要花费 5 分钟才能阅读完成。
一. 首先保证主从数据库的闪回数据库功能以及强制归档都打开,如下保证都为 yes
SQL> select flashback_on,force_logging from v$database;
FLASHBACK_ON FOR
—————— —
NO NO
1.1 开启闪回数据库
SQL> ALTER SYSTEM SET db_recovery_file_dest_size=3g SCOPE=BOTH;
System altered.
SQL> alter system set db_recovery_file_dest=’/data/u01/app/Oracle/fast_recovery_area’;
System altered.
SQL> alter database flashback on;
Database altered.
1.2 开启强制归档
SQL> alter database force logging;
Database altered.
SQL> select flashback_on,force_logging from v$database;
FLASHBACK_ON FOR
—————— —
YES YES
二:开启 fast-start failover
2.1:开启 fast-start failover
[oracle@beijing-fuli-Hadoop-02 ~]$ dgmgrl sys/ oracle@db2
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.
DGMGRL> enable fast_start failover;
Enabled.
2.2. 查看配置状态,发现警告,因为没有启动 observer 而告警!
DGMGRL> show configuration
Configuration – dbha_c
Protection Mode: MaxPerformance
Databases:
db2 – Primary database
Warning: ORA-16819: fast-start failover observer not started
db1 – (*) Physical standby database
Warning: ORA-16819: fast-start failover observer not started
Fast-Start Failover: ENABLED
Configuration Status:
WARNING
2.3 开启 启动观察器(observer):
DGMGRL> show configuration
Configuration – dbha_c
Protection Mode: MaxPerformance
Databases:
db2 – Primary database
db1 – (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS
由于 observer 的启动会一直占用 session 窗口的,所以建议写成脚本挂后台
这里我们在备库上创建脚本,具体如下
创建一个名叫 observer.sql 的脚本,把下面的命令放进去,然后执行该脚本即可。
nohup dgmgrl sys/oracle@db2 “start observer”>>observer.log 2>&1 &
三:验证自动切换:
db2 主库:
SQL> select DATABASE_ROLE,OPEN_MODE from v$database;
DATABASE_ROLE OPEN_MODE
—————- ——————–
PRIMARY READ WRITE
db1 为 standby
SQL> select DATABASE_ROLE,OPEN_MODE from v$database;
DATABASE_ROLE OPEN_MODE
—————- ——————–
PHYSICAL STANDBY READ ONLY WITH APPLY
db2 主库模拟异常关闭
SQL> shu abort
ORACLE instance shut down.
再次查看 db1 的状态:
SQL> select DATABASE_ROLE,OPEN_MODE from v$database;
DATABASE_ROLE OPEN_MODE
—————- ——————–
PRIMARY READ WRITE