Wednesday, April 22, 2009

ORACLE DATA GUARD

Steps to Perform Switchover from Primary to Standby database

Primary Database

===============

1. See the switchover_status from v$database. If it shows TO STANDBY then we can switchover to physical standby database

SQL> SELECT SWITCHOVER_STATUS FROM v$DATABASE;

Your browser may not support display of this image.


2.Give this command to switchover to physical standby database

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

Your browser may not support display of this image.

3. Shutdown and startup in mount stage

Your browser may not support display of this image..

4. Alter database open read only

Your browser may not support display of this image.

NOTE: Do the below steps after completing the all steps on Standby Database

5. Apply redo log by using the command



SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;

Your browser may not support display of this image.

6.

Your browser may not support display of this image.

7. To cancel the redo log apply

Your browser may not support display of this image.




Standby Database:

==============

1. See the switchover_status from v$database. If it shows TO PRIMARY then we can switchover to primary database

SQL> SELECT SWITCHOVER_STATUS FROM v$DATABASE;

Your browser may not support display of this image.




2.

Your browser may not support display of this image.




3. Give this command to switchover to primary database

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

After switchover to primary database,

shutdown and startup the database

Your browser may not support display of this image.

4. Verify that log are applying to standby database

Steps to Perform Manual Fail over :

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. Enable Flashback on both primary and standby databases

In order to utilize Flashback you'll need to put your database in ARCHIVELOG mode. Then you can set the

DB_FLASHBACK_RETENTION_TARGET parameter that defines the period of time which we want to retain flashback logs, and finally

turn Flashback on with an ALTER DATABASE statement. Lets look at the setup.

SQL> shutdown immediate;

SQL> startup mount;

SQL> alter database archivelog;

SQL> alter database flashback on;

SQL> alter database open;


2. Performing a Manual Failover Operation

Manual Failover Using DGMGRL:

On the target standby database, issue the FAILOVER command to invoke a complete failover, specifying the name of the standby

database that you want to change into the primary role:

DGMGRL> FAILOVER TO database-name [IMMEDIATE];

http://download.oracle.com/docs/cd/B28359_01/server.111/b28295/sofo.htm#BCGBFFIH

command run on standby database orclsby1

-----------------------------------------------

DGMGRL> FAILOVER TO orclsby1;

Performing failover NOW, please wait...

Failover succeeded, new primary is "orclsby1"

DGMGRL> show configuration

Configuration

Name: DGConfig

Enabled: YES

Protection Mode: MaxPerformance

Databases:

orclsby1 - Primary database

orcl - Physical standby database (disabled)

Fast-Start Failover: DISABLED

Current status for "DGConfig":

SUCCESS

3. To reinstate a database:

1. Restart the database to the mounted state

2. Connect to the new primary database

3. Use Enterprise Manager or DGMGRL to reinstate the database

Reinstatement Using DGMGRL

Issue the following command while connected to any database in the broker configuration, except the database that is to be

reinstated:

DGMGRL> REINSTATE DATABASE db_unique_name;

The newly reinstated standby database will begin serving as standby database to the new primary database. If the database is

not reinstated successfully, then you must reenable it from a copy of the new primary database, as described in Section

5.4.3.2.

command run on primary database orcl

------------------------------------------------

SQL> shutdown immediate

SQL> startup mount

DGMGRL> REINSTATE DATABASE orcl

Error: ORA-16795: the standby database needs to be re-created

Configuration details cannot be determined by DGMGRL

http://download.oracle.com/docs/cd/B28359_01/server.111/b28295/cli.htm#BGBBDEBC

4. How to Re-create and Re enable a Disabled Database

-------------------------------------------------------------------------

a. Copied all the datafile and altered P-file from the New primary(orclsby1) to New standby(orcl)

b. Standby control file created in Section 3.2.2

c. STARTUP MOUNT;

d. ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOG FILE DISCONNECT;

e. On New primary we have given "ALTER SYSTEM SWITCH LOGFILE;"

f. SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;


http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14239/create_ps.htm#i67520

Note.241374.1 - Script to Collect Data Guard Primary Site Diagnostic Information.

Note.241438.1 - Script to Collect Data Guard Standby Diagnostic Information.

Make sure that you have password files set on both servers

Make sure that you can connect from:

A. primary database:

sqlplus 'sys/password@ as sysdba' - connection to Standby database

sqlplus 'sys/password@ as sysdba' - connection to the itself

B. standby database:

sqlplus 'sys/password@ as sysdba' - connection to Primary database

sqlplus 'sys/password@ as sysdba' - connection to the itself

5. Recreate the DG Broker configuration because the meta data of the data guard configuration corrupted. Prefer you to remove and then recreate it :

1) Stop the broker on both the primary and standby using following command

alter system set dg_broker_start = false scope=both;

2) Remove the old broker files from $ORACLE_HOME/dbs/*.dat from Primary and Standby.

3) Start the broker on both the primary and standby using following command

alter system set dg_broker_start = true scope=both;

4) Invoke DGMGRL and connect to your primary database.

$ dgmgrl

DGMGRL> connect sys/dba123



5) Create the broker configuration including a profile for the primary database.

6) Display information about the configuration.

DGMGRL> show configuration

7) Use the following commands to add your physical standby database to the broker configuration.

8) Use the SHOW CONFIGURATION command to verify that the orclsby1 database was added to the configuration.

9) Enabling the Broker Configuration

With the Data Guard environment set successfully for your primary and standby databases. you can now enable the broker

configuration.

Enable the entire configuration. This may take some time to complete.

DGMGRL> ENABLE CONFIGURATION;

DGMGRL> SHOW CONFIGURATION;

10)Enable the database.

This step is unnecessary except if the standby database was previously disabled with the DISABLE DATABASE command. Normally,

enabling the configuration also enables the standby database.

DGMGRL> ENABLE DATABASE orcl;

Enabled.

DGMGRL> SHOW CONFIGURATION;


"7.2 Scenario 1: Creating a Configuration"

http://download.oracle.com/docs/cd/B19306_01/server.102/b14230/cli.htm#CIAGDCHH


er.102/b14230/cli.htm>

"7.4 Scenario 3: Enabling the Configuration and Databases"

http://download.oracle.com/docs/cd/B19306_01/server.102/b14230/cli.htm#i1010364




6. Now we can do switchover ( follow switchover steps)

7. After switchover

DGMGRL> show configuration

8. Recreate the DG Broker configuratio