In the Data Guard environment, there are two types of role switching for databases, Switchover and Failover. According to the name, the former is a normal role switching between the active and standby databases, which will not lose data; the latter is a Failover, which means that the primary database cannot continue to provide services, which may cause data loss. Since version 12.1, the operation of switching to the physical standby database has been simplified. This article demonstrates the two switching modes respectively.
1 switch over to the standby database
1) Verify whether the target standby database is well switched
SQL> alter database switchover to orcldg verify; Database altered.
2) Start switch of main database
SQL> alter database switchover to orcldg; Database altered.
3) Open new main library
SQL> select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ orcldg MOUNTED SQL> alter database open; Database altered.
4) Start a new standby Library
SQL> startup ORACLE instance started. Total System Global Area 1644167168 bytes Fixed Size 2925024 bytes Variable Size 1056968224 bytes Database Buffers 570425344 bytes Redo Buffers 13848576 bytes Database mounted. Database opened.
5) New standby database opens log application
SQL> alter database recover managed standby database disconnect from session; Database altered.
6) View the active / standby database status
Main library:
SQL> select name,database_role,switchover_status from v$database; NAME DATABASE_ROLE SWITCHOVER_STATUS --------- ---------------- -------------------- ORCL PRIMARY TO STANDBY
Standby:
SQL> select name,database_role,switchover_status from v$database; NAME DATABASE_ROLE SWITCHOVER_STATUS --------- ---------------- -------------------- ORCL PHYSICAL STANDBY NOT ALLOWED
2. Failover to the standby database
1) The main library fails, but it can be started to mount
SQL> shutdown abort ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 1644167168 bytes Fixed Size 2925024 bytes Variable Size 1073745440 bytes Database Buffers 553648128 bytes Redo Buffers 13848576 bytes Database mounted.
2) Refresh unused redo to standby database
SQL> alter system flush redo to orcl; System altered.
3) The standby database confirms whether there is GAP. If there is, copy the missing archived logs to the standby database and complete the registration
SQL> select * from v$archive_gap;
Registration syntax:
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';
4) Cancel log application of standby database
SQL> alter database recover managed standby database cancel; Database altered.
5) Standby database failover to primary database
SQL> alter database failover to orcl; Database altered.
6) Open new main library
SQL> select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ orcl MOUNTED SQL> alter database open; Database altered.
7) After opening a new primary database, it is recommended to make a full database backup. In addition, after failover, you can use flash back database or use RMAN backup to convert it to a new standby database.
The scene of failover is complex and can be handled according to the actual situation.
The above is to use switchover or failover to realize the transformation of the role of the physical backup.