Activating the Standby Database – Switchover Method
The main advantage of a graceful switchover is that it avoids the resetlogs operation. By avoiding the resetlogs operation, the source database can resume its role as the standby database almost immediately with no data loss. Another feature to a graceful switchover is that it does not invalidate previous backups.
1. Prerequisites :-
There is no loss of any archive logs that haven’t been (yet) applied to the standby database.
2. Setjob_queue_processes value to 0 in both (PRIMARY and STANDBY) (PROD & DR)
SQL>SHOW PARAMETER JOB_QUEUE_PROCESS
NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 10
SQL> ALTERSYSTEM SET JOB_QUEUE_PROCESSES=0 scope=both;
3. In PRIMARY database check the database role. (PROD server)
SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;
NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
DBNAMEPRIMARY NONE SESSIONS ACTIVE 4106602309 READ WRITE MAXIMUM PERFORMANCE
4. In STANDBY database check the database role. (DR server)
SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;
NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
DBNAME PHYSICAL STANDBY NONE SESSIONS ACTIVE 4106602309 MOUNTED MAXIMUM PERFORMANCE
5. Shutdown the PRIMARY database. (PROD server)
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
6. Open the PRIMARY database in RESTRICTED mode. (PROD server)
SQL> startup restrict
ORACLE instance started.
Total System Global Area 252777660 bytes
Fixed Size 451772 bytes
Variable Size 218103808 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
7. Archive the current log on the PRIMARY database. (PROD server)
SQL> alter system archive log current;
System altered.
8. Make sure the primary database and standby database are in sync. On both the primary and standby instances, issue the following. (PROD & DR)
SQL> select thread#, max (sequence#) from v$archived_log where APPLIED=’YES’ group by thread#;
THREAD# MAX(SEQUENCE#)
———- ————–
1 1934
Now, compare the results and make sure the Thread and Sequence # are the same. If the standby instance is ahead by 1 or none, you are in sync.
9. Initiate the switchover on the PRIMARY database. (PROD)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
10. Once the step above has completed, log on to the STANDBY database and issues the following command. (DR)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
11. Immediately return to the FORMER PRIMARY database and issue a shutdown and mount the NEW STANDBY database. (PROD server)
SQL> shutdown immediate
SQL> startup mount;
12. On the NEW PRIMARY/OLD STANDBY, you can now open the database as the PRIMARY database. (DR server)
SQL> alter database open;
Database opened.
13. Verify the new STANDBY’S status. (PROD server)
SQL> select name, database_role from v$database;
NAME DATABASE_ROLE
——— —————-
PHYSICAL STANDBY
14. Setjob_queue_processes value to 10 in both (PRIMARY and STANDBY) (PROD & DR)
SQL>SHOW PARAMETER JOB_QUEUE_PROCESS
NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 0
SQL> ALTERSYSTEM SET JOB_QUEUE_PROCESSES=10 scope=both;
15. Put the NEW STANDBY/FORMER PRIMARY database into managed recovery mode. (PROD)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
16. Test the communications for archive by performing a log switch. (DR server)
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
Now check whether these logs are applying in the NEW STANDBY and also check the listener status.
17. On the NEW PRIMARY database instance, create the temporary tablespace. (DR server)
SQL> Create temporary tablespace temp tempfile ‘/u01/dbname/oradata/temp01.dbf’ size 5120m;
Tablespace created.
18. On the NEW PRIMARY database instance, take a backup if possible. (DR server)
Switch back to Orginal Primary Database – Switchover Method
1. Prerequisites :-
There is no loss of any archive logs that haven’t been (yet) applied to the standby database.
2. Setjob_queue_processes value to 0 in both (PRIMARY and STANDBY) (PROD & DR)
SQL>SHOW PARAMETER JOB_QUEUE_PROCESS
NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 10
SQL> ALTERSYSTEM SET JOB_QUEUE_PROCESSES=0 scope=both;
3. In New PRIMARY database check the database role. (DR server)
SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;
NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
DBNAMEPRIMARY NONE SESSIONS ACTIVE 4106602309 READ WRITE MAXIMUM PERFORMANCE
4. In New STANDBY database check the database role. (PROD server)
SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;
NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
DBNAME PHYSICAL STANDBY NONE SESSIONS ACTIVE 4106602309 MOUNTED MAXIMUM PERFORMANCE
5. Shutdown the New PRIMARY database. (DR server)
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
6. Open the New PRIMARY database in RESTRICTED mode. (DR server)
SQL> startup restrict
ORACLE instance started.
Total System Global Area 252777660 bytes
Fixed Size 451772 bytes
Variable Size 218103808 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
7. Archive the current log on the New PRIMARY database. (DR server)
SQL> alter system archive log current;
System altered.
8. Make sure the primary database and standby database are in sync. On both the primary and standby instances, issue the following. (PROD & DR)
SQL> select thread#, max (sequence#) from v$archived_log where APPLIED=’YES’ group by thread#;
THREAD# MAX(SEQUENCE#)
———- ————–
1 1934
Now, compare the results and make sure the Thread and Sequence # are the same. If the standby instance is ahead by 1 or none, you are in sync.
9. Initiate the switchover on the New PRIMARY database. (DR)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
10. Once the step above has completed, log on to the New STANDBY database/Orginal Primary and issues the following command. (PROD)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
11. Immediately return to the FORMER PRIMARY database/Orginal STANDBY and issue a shutdown and mount the Orginal STANDBY database. (DR server)
SQL> shutdown immediate
SQL> startup mount;
12. On the Orginal PRIMARY/OLD STANDBY, you can now open the database as the PRIMARY database. (PROD server)
SQL> alter database open;
Database opened.
13. Verify the orginal STANDBY’S status. (DR server)
SQL> select name, database_role from v$database;
NAME DATABASE_ROLE
——— —————-
PHYSICAL STANDBY
14. Setjob_queue_processes value to 10 in both (PRIMARY and STANDBY) (PROD & DR)
SQL>SHOW PARAMETER JOB_QUEUE_PROCESS
NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 0
SQL> ALTERSYSTEM SET JOB_QUEUE_PROCESSES=10 scope=both;
15. Put the Orginal STANDBY/FORMER PRIMARY database into managed recovery mode. (DR)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
16. Test the communications for archive by performing a log switch. (PROD server)
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
Now check whether these logs are applying in the Orginal STANDBY and also check the listener status.
17. On the Orginal PRIMARY database instance, take a backup if possible. (PROD server)