failover 主端故障,备库变为主库
主库开启数据库的flashback
[oracle@12cr2 admin]$ sqlplus / as sysdba
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38709: Recovery Area is not enabled.
SQL> alter system set db_recovery_file_dest_size=2g;
System altered.
SQL> alter system set db_recovery_file_dest='/archive/recovery';
System altered.
SQL> alter database flashback on;
Database altered.
备库开启数据库的flashback
[oracle@oracle admin]$ sqlplus / as sysdba
SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-01153: an incompatible media recovery is active
SQL> RECOVER MANAGED STANDBY DATABASE CANCEL;
Media recovery complete.
SQL> alter database flashback on;
Database altered.
SQL> RECOVER MANAGED STANDBY DATABASE DISCONNECT USING CURRENT LOGFILE;
Media recovery complete.
[oracle@oracle admin]$ dgmgrl sys/oracle@newcdbdg
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Jul 4 22:30:16 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected to "newcdbdg"
Connected as SYSDBA.
DGMGRL> SHOW CONFIGURATION
Configuration - dg_newcdb
Protection Mode: MaxPerformance
Members:
newcdb - Primary database
newcdbdg - Physical standby database
frasync - Far sync instance
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 24 seconds ago)
failover是在主库不可访问的情况下将备库升级为主库,所以模拟failover在备端执行,将备库提升为主库。
[oracle@oracle admin]$ dgmgrl sys/oracle@newcdbdg
DGMGRL> failover to newcdbdg
Performing failover NOW, please wait...
Failover succeeded, new primary is "newcdbdg"
DGMGRL> SHOW CONFIGURATION
Configuration - dg_newcdb
Protection Mode: MaxPerformance
Members:
newcdbdg - Primary database
newcdb - Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
frasync - Far sync instance
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 41 seconds ago)
reinstated 将原主库(newcdb)变为备库
此时,如果主库(newcdb)还存活或者将主库(newcdb)修复之后,主库(newcdb)依然是PRIMARY角色,两个节点都可以读写。
SQL> select DB_UNIQUE_NAME,NAME,database_role,open_mode from v$database;
DB_UNIQUE_NAME NAME DATABASE_ROLE OPEN_MODE
------------------------------ --------- ---------------- --------------------
newcdb NEWCDB PRIMARY READ WRITE
SQL> select DB_UNIQUE_NAME,NAME,database_role,open_mode from v$database;
DB_UNIQUE_NAME NAME DATABASE_ROLE OPEN_MODE
------------------------------ --------- ---------------- --------------------
newcdbdg NEWCDB PRIMARY READ WRITE
如果想将原主库(newcdb)变成备库,可以在dgmgrl中执行reinstated将修复后的原主库(newcdb)变为备库。
[oracle@oracle admin]$ dgmgrl sys/oracle@newcdbdg
DGMGRL> reinstate database newcdb
Reinstating database "newcdb", please wait...
Operation requires shut down of instance "newcdb" on database "newcdb"
Shutting down instance "newcdb"...
Connected to "newcdb"
ORACLE instance shut down.
Operation requires start up of instance "newcdb" on database "newcdb"
Starting instance "newcdb"...
ORACLE instance started.
Database mounted.
Connected to "newcdb"
Continuing to reinstate database "newcdb" ...
Reinstatement of database "newcdb" succeeded
DGMGRL> SHOW CONFIGURATION
Configuration - dg_newcdb
Protection Mode: MaxPerformance
Members:
newcdbdg - Primary database
newcdb - Physical standby database
frasync - Far sync instance
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 28 seconds ago)
SQL> select DB_UNIQUE_NAME,NAME,database_role,open_mode from v$database;
DB_UNIQUE_NAME NAME DATABASE_ROLE OPEN_MODE
------------------------------ --------- ---------------- --------------------
newcdb NEWCDB PHYSICAL STANDBY READ ONLY WITH APPLY
SQL> select DB_UNIQUE_NAME,NAME,database_role,open_mode from v$database;
DB_UNIQUE_NAME NAME DATABASE_ROLE OPEN_MODE
------------------------------ --------- ---------------- --------------------
newcdbdg NEWCDB PRIMARY READ WRITE
switchover 修复原主库
再使用switchover将reinstated之后的备库(newcdb)变为主库
[oracle@oracle admin]$ dgmgrl sys/oracle@newcdbdg
DGMGRL> switchover to newcdb
Performing switchover NOW, please wait...
Operation requires a connection to database "newcdb"
Connecting ...
Connected to "newcdb"
Connected as SYSDBA.
New primary database "newcdb" is opening...
Operation requires start up of instance "newcdb" on database "newcdbdg"
Starting instance "newcdb"...
ORACLE instance started.
Database mounted.
Database opened.
Connected to "newcdbdg"
Switchover succeeded, new primary is "newcdb"
DGMGRL> SHOW CONFIGURATION
Configuration - dg_newcdb
Protection Mode: MaxPerformance
Members:
newcdb - Primary database
newcdbdg - Physical standby database
frasync - Far sync instance
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 1 second ago)
SQL> select DB_UNIQUE_NAME,NAME,database_role,open_mode from v$database;
DB_UNIQUE_NAME NAME DATABASE_ROLE OPEN_MODE
------------------------------ --------- ---------------- --------------------
newcdb NEWCDB PRIMARY READ WRITE
SQL> select DB_UNIQUE_NAME,NAME,database_role,open_mode from v$database;
DB_UNIQUE_NAME NAME DATABASE_ROLE OPEN_MODE
------------------------------ --------- ---------------- --------------------
newcdbdg NEWCDB PHYSICAL STANDBY READ ONLY WITH APPLY