Business continuity (Disaster Recovery) has become a very critical factor for every business. When implementing a DR solution there is always a primary and secondary (standby) site – and in some cases more than one secondary site to provide extra protection. When talking about Switchover, you can see it as a controlled process that is executed to change the roles between the primary and secondary (standby) site. It is done in a controlled manner and the key is that during this process there is no data loss. Yes, downtime is usually experienced with this process, but it is done during a scheduled, planned amount of time. The risk with this process is low and it should be something that is tested regularly so that you are familiar with the process but also with the timing – this will help with your planning as you will know exactly how long this process takes.

Very recently, there was a request from one of the clients to perform a reverse replication and rollback (i.,e switchover & switchback) between the HO and DR for one of the business critical databases. Similar activities performed with easy on pre 12c databases. However, this was my first experience with Oracle 12c. After spending a bit of time to explore what’s new in 12c Switchover, it was amazing to learn how 12c simplified the procedure. So, I decided to write a post on my experience.

This post demonstrates how Switchover and Switchback procedure is simplified in Oracle 12c.

The following is used in the scenario:

  • 2 instances Oracle 12c RAC primary database (JITPRD)
  • Single instance Oracle 12c RAC Standby database (JITSDB)

Look at the current status of the both databases:

— Primary

JITPRD> select status,instance_name,database_role from v$database,v$instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE

———— —————- —————-

OPEN         JITPRD1           PRIMARY

— Standby

JITSDB> select status,instance_name,database_role from v$database,v$instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE

———— —————- —————-

OPEN         JITSDB1           PHYSICAL STANDBY

Before getting into the real action, validate the following to avoid any failures during the course of role transition:

  • Ensure log_archive_dest_2 is configured on PRIMARY and STANDBY databases
  • Media Recovery Process (MRP) is active on STANDBY and in sync with PRIMARY database
  • Create STANDBY REDO logs on PRIMARY, if not exists
  • FAL_CLIENT & FAL_SERVER parameters set on both databases
  • Verify TEMP tablespaces on STANDBY, add them if required, as TEMPFFILES created after STANDBY creation won’t be propagated to STANDBY site.

Pre-Switchover in 12c

For a smooth role transition, it is important to have everything in-place and in sync. Pre-Oracle 12c, a set of commands used on PRIMARY and STANDBY to validate the readiness of the systems. However, with Oracle 12c, this is simplified with the ALTER DATABASE SWITCHOVER VERIFY command. The command performs the following set of actions:

  • Verifies minimum Oracle version, i.e, Oracle 12.1
  • PRIMRY DB REDO SHIPPING
  • Verify MRP status on Standby database

Let’s run the command on the primary database to validate if the environments are ready for the role transition :

JITPRD>  alter database switchover to JITSDB verify;

alter database switchover to JITSDB verify

*

ERROR at line 1:

ORA-16475: succeeded with warnings, check alert log for more details

When the command is executed, an ORA-16475 error was encountered. For more details, lets walk through the PRIMARY and STANDBY databases alert.log file, and pay attention to the SWITCHOVER VERIFY WARNING.

–primary database alert.log

Mon Feb 24 11:16:00 2020

SWITCHOVER VERIFY: Send VERIFY request to switchover target JITSDB

SWITCHOVER VERIFY COMPLETE

SWITCHOVER VERIFY WARNING: switchover target has no standby database defined in LOG_ARCHIVE_DEST_n parameter.

If the switchover target is converted to a primary database, the new primary database will not be protected.

ORA-16475 signalled during:  alter database switchover to JITSDB verify…

The LOG_ARCHIVE_DEST_2 parameter was not set on the STANDBY database and the VERIFY command produced the warning. After setting the parameter on the STANDBY, the verify command was re-ran, and it went well this time.

JITPRD> alter database switchover to JITSDB verify;

Database altered.

PRIMARY database alert.log confirms no WARINGS

alter database switchover to JITSDB verify

Mon Feb 24 08:49:20 2020

SWITCHOVER VERIFY: Send VERIFY request to switchover target JITSDB

SWITCHOVER VERIFY COMPLETE

Completed: alter database switchover to JITSDB verify.

Switchover in 12c :

After successful validation and confirmation about the DBs readiness for the role transition, execute the actual switchover command on the primary database. (advised to view the alert.log files of PRIMARY and STANDBY instances).

JITPRD> alter database switchover to JITSDB;

Database altered.

Let’s walk through the PRIMARY and STANDBY database alert.log files to review what Oracle has internally done.

–Primary database alert.log

alter database switchover to JITSDB

Mon Feb 24 08:50:21 2020

Starting switchover [Process ID: 302592]

Mon Feb 24 08:50:21 2020

ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY [Process Id: 302592] (JITPRD1)

Waiting for target standby to receive all redo

Mon Feb 24 08:50:21 2020

Waiting for all non-current ORLs to be archived…

Mon Feb 24 08:50:21 2020

All non-current ORLs have been archived.

Mon Feb 24 08:50:21 2020

Waiting for all FAL entries to be archived…

Mon Feb 24 08:50:21 2020

All FAL entries have been archived.

Mon Feb 24 08:50:21 2020

Waiting for dest_id 2 to become synchronized…

Mon Feb 24 08:50:22 2020

Active, synchronized Physical Standby switchover target has been identified

Preventing updates and queries at the Primary

Generating and shipping final logs to target standby

Switchover End-Of-Redo Log thread 1 sequence 24469 has been fixed

Switchover End-Of-Redo Log thread 2 sequence 23801 has been fixed

Switchover: Primary highest seen SCN set to 0x960.0x8bcd0f48

ARCH: Noswitch archival of thread 2, sequence 23801

ARCH: End-Of-Redo Branch archival of thread 2 sequence 23801

ARCH: LGWR is scheduled to archive destination LOG_ARCHIVE_DEST_2 after log switch

ARCH: Standby redo logfile selected for thread 2 sequence 23801 for destination LOG_ARCHIVE_DEST_2

ARCH: Noswitch archival of thread 1, sequence 24469

ARCH: End-Of-Redo Branch archival of thread 1 sequence 24469

ARCH: LGWR is scheduled to archive destination LOG_ARCHIVE_DEST_2 after log switch

ARCH: Standby redo logfile selected for thread 1 sequence 24469 for destination LOG_ARCHIVE_DEST_2

ARCH: Archiving is disabled due to current logfile archival

Primary will check for some target standby to have received all redo

Waiting for target standby to apply all redo

Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/JITPRD/JITPRD1/trace/JITPRD1_ora_302592.trc

Converting the primary database to a new standby database

Clearing standby activation ID 627850507 (0x256c3d0b)

The primary database controlfile was created using the

‘MAXLOGFILES 192’ clause.

There is space for up to 186 standby redo logfiles

Use the following SQL commands on the standby database to create

standby redo logfiles that match the primary database:

ALTER DATABASE ADD STANDBY LOGFILE ‘srl1.f’ SIZE 104857600;

ALTER DATABASE ADD STANDBY LOGFILE ‘srl2.f’ SIZE 104857600;

ALTER DATABASE ADD STANDBY LOGFILE ‘srl3.f’ SIZE 104857600;

ALTER DATABASE ADD STANDBY LOGFILE ‘srl4.f’ SIZE 104857600;

ALTER DATABASE ADD STANDBY LOGFILE ‘srl5.f’ SIZE 104857600;

ALTER DATABASE ADD STANDBY LOGFILE ‘srl6.f’ SIZE 104857600;

ALTER DATABASE ADD STANDBY LOGFILE ‘srl7.f’ SIZE 104857600;

Archivelog for thread 1 sequence 24469 required for standby recovery

Archivelog for thread 2 sequence 23801 required for standby recovery

Switchover: Primary controlfile converted to standby controlfile succesfully.

Switchover complete. Database shutdown required

USER (ospid: 302592): terminating the instance

Mon Feb 24 08:50:44 2020

Instance terminated by USER, pid = 302592

Completed: alter database switchover to JITSDB

Shutting down instance (abort)

–Standby database alert.log

SWITCHOVER: received request ‘ALTER DTABASE COMMIT TO SWITCHOVER  TO PRIMARY’ from primary database.

Mon Feb 24 08:50:32 2020

ALTER DATABASE SWITCHOVER TO PRIMARY (JITSDB1)

Maximum wait for role transition is 15 minutes.

Switchover: Media recovery is still active

Role Change: Canceling MRP – no more redo to apply

SMON: disabling cache recovery

Mon Feb 24 08:50:41 2020

Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/imsdb/JITSDB1/trace/JITSDB1_rmi_120912.trc

SwitchOver after complete recovery through change 10310266982216

Online logfile pre-clearing operation disabled by switchover

Online log +DATAD1/JITSDB/ONLINELOG/group_1.3018.922980623: Thread 1 Group 1 was previously cleared

Standby became primary SCN: 10310266982214

Switchover: Complete – Database mounted as primary

SWITCHOVER: completed request from primary database.

Mon Feb 24 08:51:11 2020

At this point-in-time, the new PRIMARY database is in MOUNT state, so you need to OPEN the database.

JITSDB> alter database open

And startup the STANDBY database and enable MRP: (below is the active standby database command)

JITPRD> startup

JITPRD> recover managed standby database using current logfile disconnect from session;

Post Switchover, run through the following:

  • JITSDB> alter system switch logfile;
  • JITSDB> select dest_id,error,status from v$archive_dest where dest_id=2;
  • JITSDB> select max(sequence#),thread# from v$log_history group by thread#;
  • JITSDB> select max(sequence#)  from v$archived_log where applied=’YES’ and dest_id=2;

On Standby Database:

  • JITPRD> select thread#,sequence#,process,status from gv$managed_standby;
  • — in 12.2, use gv$dataguard_status instead of gv$managed_standby view
  • JITPRD> select max(sequence#),thread# from v$archived_log group by thread#;
  • You can also enable the trace on primary and standby before performing the role transition to analyze any failures during the procedure. Use the below procedure on the PRIMARY database to enable the tracing:
  • SQL> alter system set log_archive_trace=8191;  — enabling trace
  • SQL> alter system set log_archive_trace=0;      — disabling trace

Switchback

To revert (switch back) to the previous situation, perform the same action. Remember, now, your primary is your previous STANDBY “JITSDB” and standby is “JITPRD” previous PRIMARY.

References:

12c Data guard Switchover Best Practices using SQLPLUS (Doc ID 1578787.1)

Thanks,

Jitendra Kumar

+91 9354075393

Recent Posts

Start typing and press Enter to search