How to Open the Standby Database When the Primary Is Lost

Share:

In critical scenarios where the Primary Oracle Database is lost or unrecoverable, and only the Standby Database remains, we must convert the standby into a new primary and open it in read-write mode.

Below is the step-by-step guide to safely activate the standby database.

๐Ÿ”น Step 1: Startup and Mount the Standby Database

SQL> STARTUP MOUNT;

๐Ÿ“„ Output Example:

ORACLE instance started.

Total System Global Area 1073741824 bytes
Fixed Size 8902824 bytes
Variable Size 301990776 bytes
Database Buffers 738197504 bytes
Redo Buffers 7876608 bytes
Database mounted.

๐Ÿ”น Step 2: Check Database Role & Status

SQL> SELECT NAME, OPEN_MODE, DATABASE_ROLE FROM V$DATABASE;

๐Ÿ“„ Output:

NAME     OPEN_MODE            DATABASE_ROLE
------ ------------------ ----------------
STBY MOUNTED PHYSICAL STANDBY

๐Ÿ”น Step 3: Cancel Managed Recovery (If Active)

If the database was applying logs, you’ll get:

SQL> RECOVER STANDBY DATABASE;
ORA-01153: an incompatible media recovery is active

โžก๏ธ Cancel it:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

๐Ÿ“„ Output:

Database altered.

๐Ÿ”น Step 4: Finish the Recovery Process

Use the following command to perform the final transition:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

๐Ÿ“„ Output:

Database altered.

๐Ÿ”น Step 5: Activate the Standby Database

Now convert the standby to a primary:

SQL> ALTER DATABASE ACTIVATE STANDBY DATABASE;

๐Ÿ“„ Output:

Database altered.

โš ๏ธ Note: This is an irreversible action โ€” after activation, the standby can no longer receive logs from the old primary.

๐Ÿ”น Step 6: Confirm New Role

SQL> SELECT NAME, OPEN_MODE, DATABASE_ROLE FROM V$DATABASE;

๐Ÿ“„ Output:

NAME     OPEN_MODE            DATABASE_ROLE
------ ------------------ ----------------
STBY MOUNTED PRIMARY

๐Ÿ”น Step 7: Open the Database in Read-Write Mode

SQL> ALTER DATABASE OPEN;

๐Ÿ“„ Output:

Database altered.

โœ… Final Verification

SQL> SELECT OPEN_MODE, DATABASE_ROLE FROM V$DATABASE;

๐Ÿ“„ Expected Result:

OPEN_MODE  |  DATABASE_ROLE
-----------|----------------
READ WRITE | PRIMARY

๐Ÿ” Summary

StepDescription
1Startup and mount the standby
2Check current database role
3Cancel managed recovery
4Finish recovery (final redo apply)
5Activate standby (makes it a primary)
6Verify role switch
7Open the database in read-write mode

Written by

W3Buddy
W3Buddy @W3Buddy

Leave a Reply

Your email address will not be published. Required fields are marked *