You are on page 1of 4

8 Role Transitions :

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

1] Introduction to Role Transitions


2] Role Transitions Involving Physical Standby Databases
3] Role Transitions Involving Logical Standby Databases
4] Using Flashback Database After a Role Transition

1] Introduction to Role Transitions :

-- A Data Guard configuration consists of one database that functions in the


primary role and one or more databases that function in the standby role.
-- Query DATABASE_ROLE column in the V$DATABASE view.
-- A database operates in one of the following mutually exclusive roles:
-- primary or
-- standby.
-- Data Guard enables you to change these roles dynamically by issuing the
SQL statements or using Data Guard broker's
interfaces.

Dataguard supports 2 ROLE Transitions :

a) SWITCHOVER (using SQL query or using Dataguard Brocker interface)


-- It allows the Primary Db to switch roles with one of its STANDBY
databases.
-- No Data loss during switchover.
-- Each database continues in dataguard config with its new role. (Standby
become Primary, and primary become standby role)

b) FAILOVER (using SQL query or using Dataguard Brocker interface)


-- Changes a Standby db to the Primary role, when the Primary db fails.
-- If Primary db is not in Max Protection or Max Availiability mode, then
some data loss may occour.
-- If Flashback db is enabled on Primary db, it can be REINSTATED as a
STANDBY for the New Primary db, once the reason for the failure is corrected.

Preparing for a ROLE Transition:


-- Before starting any ROLE Transition, Some PRE-REQUISITES :
-- Check each DBs is properly configured for the ROLE,
-- Configure Db parameters,
-- Primary DB in archivelog mode,
-- PrimaryDB must be set to FORCE LOGGING.
-- Must Have SRL (standby redologs) and ORL(online redologs) (On
PRIMARY and STANDBY dbs)

-- Check that there are no REDO Transport ERRORS or REDO GAPS at the STANDBY
dbs. (v$archive_dest_status view on Primary db)

SQL> SELECT STATUS, GAP_STATUS FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID


= 2;

STATUS GAP_STATUS
--------- ------------------------
VALID NO GAP
-- Do not proceed until the value of the STATUS column is VALID and the value
of the GAP_STATUS column is NOGAP.

-- Ensure TEMPORARY files exist on the STANDBY DB, that match the TEMPORARY
files on PRIMARY DB.

-- Remove any delay in applying redo that may be in effect on the standby
database..

SWITCH OVER :
=============
A SWITCH OVER is typically used to reduce PRIMARY database DOWNTIME during PLANNED
OUTAGES like :
-- OS or H/w upgrades,
-- Rolling Upgrades of oracle db sw
-- Patch sets

A SWITCH OVER takes in 2 Phases :


-- First Phase, the existing PRIMARY db goes a transition to a STANDBY Role,
-- Second Phase, a STANDBY db undergoes a transition to the PRIMARY Role.

Prerequisites before SWITCH OVER:

-- For PHYSICAL STANDBY db :


-- Verify that the PRIMARY db is OPEN.
-- Check the REDO Apply is ACTIVE on the STANDBY db. Standby is in Managed
Recovery Mode (REAL-TIME Recovery)
-- SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT
LOGFILE disconnect;

-- For Logical STANDBY db:


-- Both the PRIMARY db and STANDBY db instances are open that SQL apply is
ACTIVE.

FAILOVERS:
==========

Failover is typically used only when the PRIMARY db becomes UNAVAILABLE and there
is no POSSIBILITY of Restoring it.

Prerequisited before FAILOVER:

--Before performing a FAILOVER we should transfer as much of the available and


unapplied PRIMARY database REDO data as possible to the STANDBY db.
-- Place the STANDBY db in MAX PERFORMANCE mode. Because we cannot FAIL OVER to a
STANDBY db that is in MAX PROTECTION mode. because PRIMARY db in MAX PROTECTION
mode is still communicating with STANDBY db.

How to perform a SWITCHOVE or FAILOVER to a Physical STANDBY database:

1) Performing a Switchover to a Physical Standby Database.

STEP 1 : Check the PRIMARY db can be SWITCHOVER to the STANDBY ROLE.

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
-----------------
TO STANDBY

Step 2 Initiate the switchover on the primary database.

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;

Step 3 Shut down and then mount the former primary database.

SQL> SHUTDOWN ABORT;


SQL> STARTUP MOUNT;

Step 4 Verify that the switchover target is ready to be switched to the primary
role.

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
-----------------
TO_PRIMARY

Step 5 Switch the target physical standby database role to the primary role.

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

Step 6 Open the new primary database.


SQL> ALTER DATABASE OPEN;

Step 7 Start Redo Apply on the new physical standby database.


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

2) Performing a Failover to a Physical Standby Database.

Step 1 Flush any unsent redo from the primary database to the target standby
database.

-- If the primary database can be mounted, it may be possible to flush any unsent
archived and current redo from the primary database to the standby database

Issue the following SQL statement at the primary database:

SQL> ALTER SYSTEM FLUSH REDO TO target_db_name;

Step 2 Verify that the standby database has the most recently archived redo log
file for each primary database redo thread.

SQL> SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS


LAST from V$ARCHIVED_LOG;

Step 3 Identify and resolve any archived redo log gaps.

SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;


THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
--------------- ---------------------------- ------------------------------
1 90 92

Step 4 Repeat Step 3 until all gaps are resolved.

Step 5 Stop Redo Apply.

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Step 6 Finish applying all received redo data.

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

If the error condition cannot be resolved, a failover can still be performed (with
some
data loss)

SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;

Step 7 Verify that the target standby database is ready to become a primary
database

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
-----------------
TO PRIMARY

Step 8 Switch the physical standby database to the primary role.

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

Step 9 Open the new primary database.

SQL> ALTER DATABASE OPEN;

Step 10 Back up the new primary database.

Step 11 Restart Redo Apply if it has stopped at any of the other physical standby
databases in your Data Guard configuration.

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

Step 12 Optionally, restore the failed primary database.

You might also like