Skip to main content

Oracle Standalone Database Manual Switchover: A Comprehensive Guide

 

Oracle Database Manual Switchover: A Comprehensive Guide

Database high availability is critical for enterprise applications. Oracle's Data Guard provides robust disaster recovery capabilities, including the ability to perform planned switchovers between primary and standby databases. This blog post walks through the process of manually switching over from a primary database (DC) to a standby database (DR) and then switching back.

Environment Details

  • Primary Database (DC): testpri
  • Standby Database (DR): testsby

Pre-Switchover Verification

Before initiating a switchover, it's essential to verify the current database state and ensure log shipping synchronization.

Step 1: Check Active Sessions

First, check for active database sessions that might be affected during the switchover: There should not be not active session, if there are any check with application team and kill those sessions.

set time on
col machine for a30
select MACHINE, count(*), status from v$session group by machine, status;
MACHINE                         COUNT(*) STATUS
------------------------------ --------- --------
db-client1.example.com                15 INACTIVE
db-client2.example.com                 8 INACTIVE
application-server1.example.com       22 INACTIVE
monitoring-server.example.com          5 INACTIVE
select status, count(*) from v$session group by status;
STATUS     COUNT(*)
---------- ---------
INACTIVE         50

Step 2: Verify Log Shipping Synchronization

Ensure that archived logs are being properly shipped and applied:

select SEQUENCE#, ARCHIVED, APPLIED from (
  select SEQUENCE#, ARCHIVED, APPLIED 
  from v$archived_log 
  where to_date(COMPLETION_TIME) = to_Date(sysdate) 
  order by SEQUENCE# desc
) where rownum < 10;
 SEQUENCE# ARC APPLIED
---------- --- -------
     12345 YES YES
     12344 YES YES
     12343 YES YES
     12342 YES YES
     12341 YES YES
     12340 YES YES
     12339 YES YES
     12338 YES YES
     12337 YES YES

This indicates good synchronization as all logs are both archived and applied to the standby database.

Manual Switchover: DC to DR

Once you've confirmed the database status, you can proceed with the switchover process.

Step 1: Check Switchover Status at Primary (DC - testpri)

select switchover_status from v$database;
SWITCHOVER_STATUS
---------- -------
TO STANDBY

The status "TO STANDBY" confirms that the primary database is ready for switchover.

Step 2: Check Switchover Status at Standby (DR - testsby)

select switchover_status from v$database;
SWITCHOVER_STATUS
---------- -------
NOT ALLOWED

This status is normal for a standby database before initiating the switchover process.

Step 3: Initialize Switchover at Primary (DC - testpri)

alter database commit to switchover to standby with session shutdown;
---------- -------
Database altered.

Step 4: Verify Standby Is Ready (DR - testsby)

select switchover_status from v$database;
SWITCHOVER_STATUS
---------- -------
TO PRIMARY

The status "TO PRIMARY" indicates that the standby database is ready to assume the primary role.

Step 5: Shutdown and Restart Primary as Standby (DC - testpri)

shutdown immediate;
---------- -------
Database closed.
Database dismounted.
ORACLE instance shut down.
startup nomount;
---------- -------
ORACLE instance started.
Total System Global Area 4294967296 bytes
Fixed Size                  8621184 bytes
Variable Size            1275068416 bytes
Database Buffers         3002344448 bytes
Redo Buffers                8933376 bytes
alter database mount standby database;
---------- -------
Database altered.

Step 6: Complete Role Transition at Standby (DR - testsby)

alter database commit to switchover to primary with session shutdown;
---------- -------
Database altered.
shutdown immediate;
---------- -------
Database closed.
Database dismounted.
ORACLE instance shut down.
startup;
---------- -------
ORACLE instance started.
Total System Global Area 4294967296 bytes
Fixed Size                  8621184 bytes
Variable Size            1275068416 bytes
Database Buffers         3002344448 bytes
Redo Buffers                8933376 bytes
Database mounted.
Database opened.

Step 7: Configure New Standby (DC - testpri)

alter system set log_archive_dest_state_2=defer scope=both;
---------- -------
System altered.
alter database recover managed standby database disconnect from session;
---------- -------
Database altered.

Step 8: Enable Archive Log Destination on New Primary (DR - testsby)

alter system set log_archive_dest_state_2=enable scope=both;
---------- -------
System altered.

Step 9: Test Log Shipping Synchronization

Generate a new archive log on the new primary:

alter system switch logfile;
---------- -------
System altered.

Then verify log shipping on the new standby:

select SEQUENCE#, ARCHIVED, APPLIED from (
  select SEQUENCE#, ARCHIVED, APPLIED 
  from v$archived_log 
  where to_date(COMPLETION_TIME) = to_Date(sysdate) 
  order by SEQUENCE# desc
) where rownum < 10;
 SEQUENCE# ARC APPLIED
---------- --- -------
     12346 YES YES
     12345 YES YES
     12344 YES YES
     12343 YES YES
     12342 YES YES
     12341 YES YES
     12340 YES YES
     12339 YES YES
     12338 YES YES

Switch Back: DR to DC

After operating with DR as your primary database for the necessary period, you may need to switch back to your original primary in DC.

Step 1: Check Switchover Status at Current Primary (DR - testsby)

select switchover_status from v$database;
SWITCHOVER_STATUS
---------- -------
TO STANDBY

Step 2: Convert Current Primary to Standby (DR - testsby)

alter database commit to switchover to standby with session shutdown;
---------- -------
Database altered.
shutdown immediate;
---------- -------
Database closed.
Database dismounted.
ORACLE instance shut down.
startup nomount;
---------- -------
ORACLE instance started.
Total System Global Area 4294967296 bytes
Fixed Size                  8621184 bytes
Variable Size            1275068416 bytes
Database Buffers         3002344448 bytes
Redo Buffers                8933376 bytes
alter database mount standby database;
---------- -------
Database altered.

Step 3: Convert Current Standby to Primary (DC - testpri)

select switchover_status from v$database;
SWITCHOVER_STATUS
---------- -------
TO PRIMARY
alter database commit to switchover to primary;
---------- -------
Database altered.
shutdown immediate;
---------- -------
Database closed.
Database dismounted.
ORACLE instance shut down.
startup;
---------- -------
ORACLE instance started.
Total System Global Area 4294967296 bytes
Fixed Size                  8621184 bytes
Variable Size            1275068416 bytes
Database Buffers         3002344448 bytes
Redo Buffers                8933376 bytes
Database mounted.
Database opened.
alter system set log_archive_dest_state_2=enable scope=both;
---------- -------
System altered.

Step 4: Configure New Standby (DR - testsby)

alter system set log_archive_dest_state_2=defer scope=both;
---------- -------
System altered.
alter database recover managed standby database disconnect from session;
---------- -------
Database altered.

Step 5: Test Log Shipping Synchronization

Generate a new archive log on the new primary:

alter system switch logfile;
---------- -------
System altered.

Verify log shipping on the new standby:

select SEQUENCE#, ARCHIVED, APPLIED from (
  select SEQUENCE#, ARCHIVED, APPLIED 
  from v$archived_log 
  where to_date(COMPLETION_TIME) = to_Date(sysdate) 
  order by SEQUENCE# desc
) where rownum < 10;
 SEQUENCE# ARC APPLIED
---------- --- -------
     12350 YES YES
     12349 YES YES
     12348 YES YES
     12347 YES YES
     12346 YES YES
     12345 YES YES
     12344 YES YES
     12343 YES YES
     12342 YES YES

Best Practices for Database Switchover

  1. Plan Maintenance Window: Schedule the switchover during a low-activity period to minimize impact.

  2. Application Coordination: Notify application teams before switchover to ensure proper handling of database connections.

  3. Verify Log Shipping: Always verify log shipping synchronization before and after the switchover process.

  4. Document Procedure: Keep detailed records of each switchover, including timing and any issues encountered.

  5. Post-Switchover Verification: Run application tests after switchover to verify functionality.

  6. Monitor Alert Logs: Keep an eye on database alert logs throughout the process to catch any potential issues.

  7. Database Parameters: Ensure that database parameters related to Data Guard are properly configured on both databases.

Oracle Database switchover provides a controlled method for transferring database roles with minimal downtime. When properly executed, this process ensures business continuity while allowing for planned maintenance activities. The step-by-step approach outlined in this guide should help database administrators perform switchover operations confidently and efficiently.

By having well-documented procedures and following best practices, your organization can maintain high availability and disaster recovery readiness while minimizing operational risks.


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...

🐳Oracle 19c Database Deployment with Docker

Oracle 19c Database Deployment with Docker 🐳 Oracle 19c Database Deployment with Docker Welcome to this comprehensive guide on deploying, configuring, and managing Oracle 19c Database using Docker containers. This blog will walk you through the entire process from setup to production best practices with practical code examples. Docker provides an excellent way to run Oracle databases in isolated, portable containers, making it easy to deploy and manage Oracle 19c instances for development, testing, and production environments. This approach offers numerous benefits: πŸ”’ Isolation : Run Oracle in a containerized environment without affecting your host system 🚚 Portability : Easily move your database between different environments πŸ”„ Reproducibility : Quickly spin up identical database instances ⚡ Resource Efficiency : Use Docker's resource management capabilities to control CPU, memory, and stor...

Mastering Oracle RAC with CRSCTL commands

Mastering Oracle Clusterware Administration: Essential Commands & Best Practices Oracle Clusterware is a key component for managing cluster environments, ensuring high availability and resource management for Oracle databases. Below are essential commands for managing Oracle Clusterware effectively. What is crsctl? crsctl (Cluster Ready Services Control) is a command-line utility provided by Oracle to manage Oracle Clusterware. It allows administrators to start, stop, check, and configure various aspects of cluster services. With crsctl , DBAs can control cluster resources, manage voting disks, check the status of Oracle High Availability Services, and ensure the proper functioning of Oracle RAC environments. Starting and Stopping Oracle Clusterware On Local Node Stop Clusterware: crsctl stop cluster Start Clusterware: crsctl start cluster On RAC Standalone/Oracle Restart Stop Cluster: crsctl stop has Start Cluster: crsctl start has On All Nodes or All Hub Nodes Start Clusterware:...