In the data guard environment, there are two kinds of role switching of database, namely switchover and failover. According to the name, the former is a normal role switching between the primary and standby databases, which will not lose data; the latter is a failure switching, which means that the primary database cannot continue to provide services, and data loss may occur. Starting from version 12.1, the operation of switching to physical backup database is simplified. This article demonstrates the two switching methods.
1 switch over to standby database
1) Verify whether the target standby database is well switched
SQL> alter database switchover to orcldg verify;
Database altered.
2) Start the switch of master 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 database
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 status of active and standby databases
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
ORCL PRIMARY TO STANDBY
Backup Library:
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
ORCL PHYSICAL STANDBY NOT ALLOWED
2 fail to switch to 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 backup database confirms whether there is gap. If there is, copy the lost archive log to the backup 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) Fail over from standby database 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 backup of the database. In addition, after a failure, you can use flash back database or use RMAN backup to convert it to a new standby database.
The scene of fail over is complex and can be handled according to the actual situation.
The above is to use switchover or fail to realize the role conversion of physical standby database.