os: centos 7.4
database:12.2.0.1 + dbf
switchover
一般指的时正常情况下,人为执行的切换命令或者在符合某些条件执行的。不会丢失数据
failover
一般指的是实例失效的情况下,进行的故障转移。丢失的数据多少依赖配置的dg级别。
生产环境肯定时希望能够 fast failover的,这是就需要额外设置下。
dataguard broker 自动 failover
DGMGRL> SHOW FAST_START FAILOVER;
Fast-Start Failover: DISABLED
Threshold: 30 seconds
Target: (none)
Observer: (none)
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 Write Errors YES
Oracle Error Conditions:
(none)
DGMGRL> enable fast_start failover;
Warning: ORA-16827: Flashback Database is disabled
启用 fast_start failover 是要设置 flashback database
启用 flashback database
SQL> alter system set db_recovery_file_dest_size = 4G ;
System altered.
SQL> alter system set db_recovery_file_dest='/u01/app/oracle/fra/' ;
System altered.
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> alter database flashback on;
Database altered.
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
SQL> show parameter db_recovery;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /u01/app/oracle/fra/
db_recovery_file_dest_size big integer 4G
主设置后,switchover 一次,再次设置.
所以啊,本地归档和flashback database 在前期就一并设置了,这很重要。
再次设置
DGMGRL> enable fast_start failover;
Enabled.
DGMGRL> show configuration;
Configuration - dgconf
Protection Mode: MaxPerformance
Members:
orclp - Primary database
Warning: ORA-16819: fast-start failover observer not started
orcls1 - (*) Physical standby database
Warning: ORA-16819: fast-start failover observer not started
Fast-Start Failover: ENABLED
Configuration Status:
WARNING (status updated 45 seconds ago)
DGMGRL> start observer;
[W000 07/09 22:41:16.40] FSFO target standby is orcls1
[W000 07/09 22:41:18.95] Observer trace level is set to USER
[W000 07/09 22:41:18.95] Try to connect to the primary.
[W000 07/09 22:41:18.95] Try to connect to the primary tns_orclp.
[W000 07/09 22:41:18.96] The standby orcls1 is ready to be a FSFO target
[W000 07/09 22:41:20.96] Connection to the primary restored!
[W000 07/09 22:41:22.97] Disconnecting from database tns_orclp.
新打开一个窗口
$dgmgrl
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Mon Jul 9 22:42:43 2018
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Welcome to DGMGRL, type "help" for information.
DGMGRL>
DGMGRL> connect sys/oracleoracle@tns_orclp;
Connected to "orclp"
Connected as SYSDBA.
DGMGRL>
DGMGRL> show configuration;
Configuration - dgconf
Protection Mode: MaxPerformance
Members:
orclp - Primary database
orcls1 - (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS (status updated 18 seconds ago)
验证
在主库上 shutdown abort
SQL> shutdown abort;
ORACLE instance shut down.
查看备库状态
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
start observer 窗口一直提示错误
[W000 07/09 22:46:50.17] Failed to ping the new standby.
[W000 07/09 22:46:51.17] Try to connect to the new standby orclp.
[W000 07/09 22:46:54.17] Connection to the new standby restored!
旧的master变为新的standby
SQL> startup mount;
这个时候就需要使用 flashback database,如果dg保护级别不够,损失的就是这一部分已提交的数据。
类似 postgresql 的 pg_rewind,有兴趣的哥们可以搜搜看。
start observer 窗口有提示信息
[W000 07/09 22:51:26.68] Try to connect to the new standby orclp.
[W000 07/09 22:51:28.68] Connection to the new standby restored!
[W000 07/09 22:52:00.72] Try to connect to the primary tns_orcls1.
[W000 07/09 22:52:02.72] Connection to the primary restored!
[W000 07/09 22:52:03.73] Wait for new primary to be ready to reinstate.
[W000 07/09 22:52:04.73] New primary is now ready to reinstate.
[W000 07/09 22:52:04.73] Issuing REINSTATE command.
22:52:04.73 Monday, July 09, 2018
Initiating reinstatement for database "orclp"...
Reinstating database "orclp", please wait...
Reinstatement of database "orclp" succeeded
22:52:25.65 Monday, July 09, 2018
[W000 07/09 22:52:25.76] Successfully reinstated database orclp.
[W000 07/09 22:52:25.76] The standby orclp is ready to be a FSFO target
[W000 07/09 22:52:25.76] The reinstatement of standby orclp was just done
查询新的standby状态
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
参考:
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/high-availability.html