Skip to main content

Oracle RAC Switchover & Switchback: Step-by-Step Guide

 Ensuring business continuity requires regular Disaster Recovery (DR) drills. This guide covers the Switchover and Switchback process between Primary (DC) and Standby (DR) databases.

Pre-checks Before Performing Switchover

Before starting the activity, ensure there are no active sessions in the database. If any are found, share the session details with the application team, get their confirmation, and terminate the sessions.

Primary Database Name: PRIMARY

Standby Database Name: STANDBY 

Identify Active Sessions

set lines 999 pages 999
col machine for a30
col username for a30
col program for a30
compute sum of count on report
break on report
select inst_id,username,osuser,machine,program,status,count(1) "count" from gv$session where inst_id=1 and program like 'JDBC%' group by inst_id,username,osuser,machine,program,status order by 1,2;

select inst_id,username,osuser,machine,program,status,count(1) "count" from gv$session where inst_id=2 and program like 'JDBC%' group by inst_id,username,osuser,machine,program,status order by 1,2;

Terminate Sessions

select 'alter system kill session ''' || sid || ',' || serial# || ',' || '@' || INST_ID || ''' IMMEDIATE;' from gv$session where username not in ('OGG','sys');

select 'alter system kill session ''' || sid || ',' || serial# || ',' || '@' || INST_ID || ''' IMMEDIATE;' from gv$session where sql_id='SQL_ID';

Switchover: Data Center (DC) to Disaster Recovery (DR)

On Primary Database Check (10.44.101.71/72)

Verify Database Readiness

Check the primary and standby database synchronization using:
SQL> select status,instance_name,database_role,open_mode,switchover_status from v$database,gv$instance;

Ensure that the status is "TO STANDBY" on the primary and "TO PRIMARY" on the standby.

SQL> select status, gap_status from v$archive_dest_status where dest_id = 2;

Ensure no archive log gap exists between DC and DR.

SQL> alter database switchover to STANDBY verify;
SQL> alter system archive log current;
SQL> alter database switchover to STANDBY;

On Standby Database Activation (10.22.101.71)

SQL> select status,instance_name,database_role,open_mode from v$database,gv$instance;
SQL> shut immediate;
SQL> startup mount;
SQL> alter database open;

Restart Standby Database (Former Primary: 10.44.101.71/72)

srvctl start database -d PRIMARY -o mount;
SQL> alter database recover managed standby database disconnect from session;

Ensure Synchronization

SQL> alter system archive log current;
SQL> select thread#,process,status,sequence#,blocks from gv$managed_standby;

Confirm synchronization before notifying the application team.


Switchback: Disaster Recovery (DR) to Data Center (DC)

Check Current Roles

Current Primary (10.22.101.71)

SQL> select name, DB_UNIQUE_NAME from gv$database;
SQL> select switchover_status from v$database;
SQL> select inst_id,status, gap_status,error from gv$archive_dest_status where dest_id = 2;

Ensure switchover_status is TO STANDBY and no archive log gap exists.

Execute Switchover

SQL> alter database switchover to PRIMARY verify;
SQL> alter system archive log current;
SQL> alter database switchover to PRIMARY;

Revert Roles

Standby (Current Primary: 10.44.101.71/72)

srvctl stop database -d PRIMARY;
srvctl start database -d PRIMARY -o open;
SQL> select status,instance_name,database_role,open_mode from v$database,gv$instance;

Former Primary (Current Standby: 10.22.101.71)

srvctl start database -d STANDBY -o mount;
SQL> alter database recover managed standby database disconnect from session;

Final Synchronization Check

SQL> alter system archive log current;
SQL> select thread#,process,status,sequence#,blocks from gv$managed_standby;

Confirm standby synchronization before notifying the application team that the switchback is completed.

Regular DR drills are critical for business continuity. By following this step-by-step guide, teams can ensure seamless switchover and switchback processes without data loss.

Comments

Popular posts from this blog

πŸš€ Automating Oracle Database Patching with Ansible: A Complete Guide

Oracle database patching has long been the bane of DBAs everywhere. It's a critical task that requires precision, expertise, and often results in extended maintenance windows. What if I told you that you could automate this entire process, reducing both risk and downtime while ensuring consistency across your Oracle estate? πŸ’‘ In this comprehensive guide, I'll walk you through a production-ready Ansible playbook that completely automates Oracle patch application using OPatch. Whether you're managing a single Oracle instance or hundreds of databases across your enterprise, this solution will transform your patch management strategy! 🎯 πŸ”₯ The Challenge: Why Oracle Patching is Complex Before diving into the solution, let's understand why Oracle patching is so challenging: πŸ”— Multiple dependencies : OPatch versions, Oracle Home configurations, running processes ⚠️ Risk of corruption : Incorrect patch application can render databases unusable ⏰ Downtime requirements : Da...

⚡ Automating Oracle 19c Database Patching on Windows Server with PowerShell

Applying Oracle patches on Windows often feels repetitive and error-prone — stopping services, updating OPatch, applying patches, running datapatch , and restarting services. To save time ⏱ and reduce mistakes ⚠, I created a PowerShell automation script that performs the patching process end-to-end πŸš€. πŸ”Ή Why Automate Oracle Patching? ⏱ Save time by automating repetitive steps ⚙ Avoid manual errors during patching πŸ“œ Maintain logs for auditing and troubleshooting πŸ›‘ Ensure consistent, reliable patching πŸ”Ή Full PowerShell Script # --- CONFIGURATION --- $oracleHome = "c:\users\administrator\downloads\v982656-01" # Change if this is not your actual Oracle Home! $patchDir = "C:\Users\Administrator\Downloads\p37962957_190000_MSWIN-x86-64\37962957" #update the Patchfile directory $opatchDir = "$oracleHome\OPatch" $opatchZip = "C:\Users\Administrator\Downloads\p6880880_190000_MSWIN-x86-64.zip" #Based on your setup update Opatch di...

Installing pgBackRest on Linux (RHEL 9 / Rocky / AlmaLinux)

 When you work with PostgreSQL in real environments, one thing becomes very clear very quickly: Backups are not optional. It doesn’t matter how stable your database is — failures happen. Disks crash Files get corrupted Someone runs the wrong delete query A patch goes wrong A standby needs rebuilding. So having a proper backup strategy is not just good practice, it’s survival. That’s exactly why tools like pgBackRest are so widely used in PostgreSQL production systems. In this post, I’ll walk through a simple installation of pgBackRest on a Linux server (RHEL 9 / Rocky Linux / AlmaLinux). Why pgBackRest? PostgreSQL already provides tools like: pg_dump pg_basebackup And yes, they work. But once your database grows, or you start managing HA setups, these tools start feeling limited. pgBackRest is built for serious PostgreSQL backup requirements. Some of the reasons it stands out: Supports full, differential, and incremental backups Built-in compre...