You are on page 1of 8

Data Guard Failover Test using SQL

This failover will be to a Physical Standby. FRA is being used.

Things to check before beginning


1. Check if V$DATABASE for issues : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select switchover_status from v$database; SWITCHOVER_STATUS -------------------TO STANDBY 2. Obtain the current sequence number on the primary : SQL> select max(sequence#) from v$archived_log; MAX(SEQUENCE#) -------------23 3. As the BIGSHOW user on the primary check the CUSTOMER table and add some data : SQL> select max(id) from customer; MAX(ID) ---------5000 SQL> execute add_customers; PL/SQL procedure successfully completed. SQL> select max(id) from customer; MAX(ID) D a t a G u a r d F a i l o v e r T est Page 1

---------6000 4. Execute a shutdown immediate on the Primary SQL> shutdown immediate /home/oracle:PRIMARY >ps -ef | grep ora_ oracle 4582 2981 0 09:12 pts/1 00:00:00 grep ora_ Oracle down!

Failover to Physical Standby


SQL> alter database recover managed standby database cancel; Database altered. SQL> alter database recover managed standby database finish; Database altered. SQL> alter database commit to switchover to primary with session shutdown; Database altered. SQL> alter database open; Database altered. SQL> select max(id) from bigshow.customer; MAX(ID) ---------6000

D a t a G u a r d F a i l o v e r T est

Page 2

Bring back the Old Primary


SQL> SELECT TO_CHAR(STANDBY_BECAME_PRIMARY_SCN) FAILOVER_SCN FROM V$DATABASE; FAILOVER_SCN ---------------------------------------1011295 /home/oracle:PRIMARY >sqlplus "/ as sysdba" SQL*Plus: Release 11.2.0.1.0 Production on Sat Nov 12 09:31:00 2011 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> startup mount ORACLE instance started. Total System Global Area 417546240 bytes Fixed Size 2213936 bytes Variable Size 335546320 bytes Database Buffers 75497472 bytes Redo Buffers 4288512 bytes Database mounted. Warning : Once you do this your RMAN options for recovery are limited. SQL> FLASHBACK DATABASE TO SCN 1011295; Flashback complete. SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY; Database altered. SQL> SQL> SHUTDOWN IMMEDIATE ORA-01507: database not mounted ORACLE instance shut down. SQL> STARTUP MOUNT ORACLE instance started. D a t a G u a r d F a i l o v e r T est Page 3

Total System Global Area 417546240 bytes Fixed Size 2213936 bytes Variable Size 335546320 bytes Database Buffers 75497472 bytes Redo Buffers 4288512 bytes Database mounted. SQL> alter database recover managed standby database using current logfile disconnect; At this point its a great idea to check if MRP is working on the current standby. //home/oracle:PRIMARY >ps -ef | grep mrp oracle 4801 4713 0 19:36 pts/2 00:00:00 grep mrp I dont see it. And the query below confirms its not running SQL> select process,status,client_process,sequence# from v$managed_standby; The Alert log shows this :
Sun Nov 13 19:34:05 2011 Media Recovery Log /u01/app/oracle/flash_recovery_area/PRIMARY/archivelog/2011_11_13/o1_mf_1_25_7d0vws 2s_.arc Identified End-Of-Redo for thread 1 sequence 25 Resetting standby activation ID 1603749534 (0x5f97469e) Media Recovery End-Of-Redo indicator encountered Media Recovery Applied until change 1011351 Media Recovery archivelogs detected beyond End-Of-REDO MRP0: Media Recovery Complete: End-Of-REDO (PRIMARY) MRP0: Background Media Recovery process shutdown (PRIMARY)

So MRP has shutdown because THROUGH ALL SWITCHOVER was not specified. To correct this : SQL> alter database recover managed standby database using current logfile disconnect; Database altered. SQL> select process,status,client_process,sequence# from v$managed_standby;
PROCESS --------RFS RFS MRP0 STATUS -----------IDLE IDLE APPLYING_LOG CLIENT_P SEQUENCE# -------- ---------UNKNOWN 0 LGWR 4 N/A 4

D a t a G u a r d F a i l o v e r T est

Page 4

Notice the log sequence number is 4. This is because a failover in 11g will also reset the sequence numbers much like an open reset logs. The next sequence is 5, the question is will an alter system switch logfile show this? SQL> alter system switch logfile; SQL> select process,status,client_process,sequence# from v$managed_standby;
PROCESS --------RFS RFS MRP0 STATUS -----------IDLE IDLE APPLYING_LOG CLIENT_P SEQUENCE# -------- ---------UNKNOWN 0 LGWR 5 N/A 5

On the current Primary we can check the switchover status. SQL> select switchover_status from v$database; SWITCHOVER_STATUS -------------------TO STANDBY To make it interesting we can add some data again as the BIGSHOW user before the switchover : SQL> execute add_customers; PL/SQL procedure successfully completed. SQL>

D a t a G u a r d F a i l o v e r T est

Page 5

Switchover
Step 1 Verify that it is possible to perform a switchover operation. SQL> select switchover_status from v$database; SWITCHOVER_STATUS -------------------TO STANDBY Step 2 Convert the primary database to the new standby SQL> alter database commit to switchover to standby with session shutdown; Database altered. Step 3 Shutdown the former primary and mount as a standby database SQL> shutdown immediate ORA-01507: database not mounted ORACLE instance shut down. SQL> startup nomount ORACLE instance started. Total System Global Area 630501376 bytes Fixed Size 2215984 bytes Variable Size 553652176 bytes Database Buffers 67108864 bytes Redo Buffers 7524352 bytes SQL> alter database mount standby database; Database altered. Step 4 Defer the remote archive destination on the old primary SQL> alter system set log_archive_dest_state_2=defer;

System altered. D a t a G u a r d F a i l o v e r T est Page 6

Step 5 Verify that the physical standby can be converted to the new primary SQL> select switchover_status from v$database; SWITCHOVER_STATUS -------------------TO PRIMARY Step 6 Convert the physical standby to the new primary SQL> alter database commit to switchover to primary; Database altered. Step 7 Shutdown and startup the new primary SQL> shutdown immediate ORA-01109: database not open Database dismounted. ORACLE instance shut down. SQL> startup Step 8 Enable remote archiving on the new primary to the new standby SQL> alter system set log_archive_dest_state_2=enable; System altered. Step 9 Start managed recover on the new standby database SQL> recover managed standby database disconnect; Media recovery complete. Finally check the BIGSHOW data again : SQL> select max(id) from bigshow.customer; MAX(ID) ---------7000 Success!! D a t a G u a r d F a i l o v e r T est Page 7

D a t a G u a r d F a i l o v e r T est

Page 8

You might also like