Sunday, September 23, 2012

Oracle 10g Data Guard – Quick Switchover with Physical Standby Database

Visit the Below Website to access unlimited exam questions for all IT vendors and Get Oracle Certifications for FREE
http://www.free-online-exams.com
Once the standby database is setup using Data Guard and works properly, you may want to test switchover, or perform switchover to reduce primary database downtime during OS upgrades or hardware upgrades. (To set up a Physical Standby database, please refer to my OraFAQ blog "Oracle 10g – Manually Create a Physical Standby Database Using Data Guard".)

A switchover allows the primary database to switch roles with its standby database. There is no data loss during a switchover. You can switch back to the original Primary database later by performing another switchover.

In case of primary database failure, you will need to perform failover to transition the standby database to the primary role. After a failover, the original primary database can no longer participate in the Data Guard configuration. So if the original Primary database is still accessible, you should always consider a switchover first.

This document only talks about switchover involving physical standby database. In this example, the original primary data is called PRIM and the original standby database is called STAN.

I. Before Switchover:

1. As I always recommend, test the Switchover first on your testing systems before working on Production.

2. Verify the primary database instance is open and the standby database instance is mounted.

3. Verify there are no active users connected to the databases.

4. Make sure the last redo data transmitted from the Primary database was applied on the standby database. Issue the following commands on Primary database and Standby database to find out:
SQL>select sequence#, applied from v$archvied_log;
Perform SWITCH LOGFILE if necessary.

In order to apply redo data to the standby database as soon as it is received, use Real-time apply.

II. Quick Switchover Steps

1. Initiate the switchover on the primary database PRIM:
SQL>connect /@PRIM as sysdba
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;

2. After step 1 finishes, Switch the original physical standby db STAN to primary role;
Open another prompt and connect to SQLPLUS:
SQL>connect /@STAN as sysdba
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

3. Immediately after issuing command in step 2, shut down and restart the former primary instance PRIM:
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP MOUNT;

4. After step 3 completes:
- If you are using Oracle Database 10g release 1, you will have to Shut down and restart the new primary database STAN.
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP;

- If you are using Oracle Database 10g release 2, you can open the new Primary database STAN:
SQL>ALTER DATABASE OPEN;

STAN is now transitioned to the primary database role.

5. On the new primary database STAN, perform a SWITCH LOGFILE to start sending redo data to the standby database PRIM.
SQL>ALTER SYSTEM SWITCH LOGFILE;

Reference:
1. Oracle Data Guard Concepts and Administration 10g Release 2 (10.2), B14239-04;
2. Switchover and Failover Best Practices: Oracle Data Guard 10g release 2 by Oracle.
Get Oracle Certifications for all Exams
Free Online Exams.com

How To Open The Standby Database When The Primary Is Lost

Visit the Below Website to access unlimited exam questions for all IT vendors and Get Oracle Certifications for FREE
http://www.free-online-exams.com
Startup Mount

[oracle@rac2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Wed Feb 4 19:51:12 2009
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
Connected to an idle instance.

SQL> STARTUP MOUNT
ORACLE instance started.
Total System Global Area  218103808 bytes
Fixed Size                  1260984 bytes
Variable Size             184549960 bytes
Database Buffers           29360128 bytes
Redo Buffers                2932736 bytes
Database mounted.
Check Status

SQL> SELECT OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE FROM V$DATABASE;
OPEN_MODE  PROTECTION_MODE      DATABASE_ROLE
---------- -------------------- ----------------
MOUNTED    MAXIMUM PERFORMANCE  PHYSICAL STANDBYHow To Open The Standby Database When The Primary Is Lost
3/5  2/4/2009 
Recover if you have logs to apply
In this example the primary is lost and I don't have more archived logs to apply:

SQL> RECOVER STANDBY DATABASE;
ORA-00279: change 794348 generated at 12/29/2008 12:23:02 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/oradata/dgfdb/archive/1_49_633452428.dbf
ORA-00280: change 794348 for thread 1 is in sequence #49
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log
'/u01/app/oracle/oradata/dgfdb/archive/1_49_633452428.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
SQL> !ls -l /u01/app/oracle/oradata/dgfdb/archive/
total 31072
-rw-r-----  1 oracle oinstall  1158656 Dec 29 11:31 1_37_633452428.dbf
-rw-r-----  1 oracle oinstall  7385600 Dec 29 11:31 1_38_633452428.dbf
-rw-r-----  1 oracle oinstall  4941824 Dec 29 11:31 1_39_633452428.dbf
-rw-r-----  1 oracle oinstall 13739008 Dec 29 11:31 1_40_633452428.dbf
-rw-r-----  1 oracle oinstall  2272256 Dec 29 11:50 1_41_633452428.dbf
-rw-r-----  1 oracle oinstall     1024 Dec 29 11:51 1_42_633452428.dbf
-rw-r-----  1 oracle oinstall    89088 Dec 29 11:51 1_43_633452428.dbf
-rw-r-----  1 oracle oinstall  1847296 Dec 29 12:18 1_44_633452428.dbf
-rw-r-----  1 oracle oinstall   135680 Dec 29 12:18 1_45_633452428.dbf
-rw-r-----  1 oracle oinstall    67584 Dec 29 12:19 1_46_633452428.
-rw-r-----  1 oracle oinstall    34816 Dec 29 12:22 1_47_633452428.dbf
-rw-r-----  1 oracle oinstall     2048 Dec 29 12:22 1_48_633452428.dbf
Finish the Recovery process

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
Database altered.
Activate the Standby Database

SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
Database altered.
Check the new status

SQL> SELECT OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE FROM V$DATABASE;
OPEN_MODE  PROTECTION_MODE      DATABASE_ROLE
---------- -------------------- ----------------
MOUNTED    MAXIMUM PERFORMANCE  PRIMARY
Open the Database

SQL> ALTER DATABASE OPEN
Database altered.

SQL> SELECT OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE FROM V$DATABASE;
OPEN_MODE  PROTECTION_MODE      DATABASE_ROLE
---------- -------------------- ----------------
READ WRITE MAXIMUM PERFORMANCE  PRIMARY
Get Oracle Certifications for all Exams
Free Online Exams.com