2012/07/20

Oracle Data Guard 11g – Using DBMS_DG


Oracle Database 11g  Release 1 onward new package - DBMS_DG. Package contains a procedure INITIATE_FS_FAILOVER, yet. This procedure for using to specify a condition string that, when encountered by an application, allows the application to request the primary database to immediately invoke a fast-start failover.
Syntax
DBMS_DG.INITIATE_FS_FAILOVER (condstr IN VARCHAR2)
RETURN BINARY_INTEGER;

condstr - parameter
Specifies the condition string for which a fast-start failover should be requested. If no condition string argument is supplied, the default string of "Application Failover Requested" will be logged in the broker log file and in the database alert log of the primary database.

There are conditions detectable by applications running outside of the Oracle database that may warrant the Oracle Data Guard broker to perform a fast-start failover. Because the range of possible conditions is virtually unlimited, it is left to the applications to determine which conditions warrant a fast-start failover.
When such conditions occur, the application calls the DBMS_DG.INITIATE_FS_FAILOVER procedure to alert the primary database that the application wants a fast-start failover to occur immediately. The primary database then notifies the observer, which immediately initiates a fast-start failover as long as the standby database is in a valid fast-start failover state ("observed" and either "synchronized" or "within lag") to accept a failover.If the configuration is not in a valid fast-start failover state, the INITIATE_FS_FAILOVER subprogram returns an ORA error message (it will not signal an exception) to inform the calling application that a fast-start failover could not be performed.

We can use DBMS_DG package with PL/SQL block. For example :
1. Have a Broker-managed Data Guard Configuration DG, Fast Start Failover is started

DGMGRL> show configuration

Configuration - dg

  Protection Mode: MaxPerformance
  Databases:
    admdb - Primary database
      Error: ORA-16820: fast-start failover observer is no longer observing this
 database

    stldb - (*) Physical standby database
      Error: ORA-16820: fast-start failover observer is no longer observing this
 database

Fast-Start Failover: ENABLED

Configuration Status:
ERROR

DGMGRL> start observer
Observer started


and now observing both databases.

DGMGRL> show configuration

Configuration - dg

  Protection Mode: MaxPerformance
  Databases:
    admdb - Primary database
    stldb - (*) Physical standby database

Fast-Start Failover: ENABLED

Configuration Status:
SUCCESS

2. Connect as user SYS  with SYSDBA privileges to SQL*Plus Command Line tool, and call following PL/SQL block.

SET SERVEROUTPUT ON
DECLARE
 v_status INTEGER;
 v_error  VARCHAR2(300);
BEGIN
  v_status := dbms_dg.initiate_fs_failover('Application Failover Requested');
  SELECT 
     DECODE(v_status,0,'normal, successful completion',
               16646,'Fast-Start Failover is disabled',
               16666,'unable to initiate Fast-Start Failover on a standby database',
               16817,'unsynchronized Fast-Start Failover configuration',
               16819,'Fast-Start Failover observer not started',
               16820,'Fast-Start Failover observer is no longer observing this database',
               16829,'lagging Fast-Start Failover') INTO v_error
   FROM dual; 
  dbms_output.put_line('Actual Status = ORA-' ||v_status||' : '||v_error);
END;
/

Result
Actual Status = ORA-0 : normal, successful completion
PL/SQL procedure successfully completed.


3. Observer is performing failover

DGMGRL> start observer
Observer started

11:31:01.36  Friday, July 20, 2012
Initiating Fast-Start Failover to database "stldb"...
Performing failover NOW, please wait...
Failover succeeded, new primary is "stldb"
11:31:06.70  Friday, July 20, 2012


Table INITIATE_FS_FAILOVER Procedure Errors
ErrorDescription
ORA-00000: normal, successful completion
The request to initiate a fast-start failover has been posted to the observer.
ORA-16646: Fast-Start Failover is disabled
Either a broker configuration does not exist or fast-start failover has not been enabled.
ORA-16666: unable to initiate Fast-Start Failover on a standby database
DBMS_DG.INITIATE_FS_FAILOVER was invoked on a standby site.
ORA-16817: unsynchronized Fast-Start Failover configuration
DBMS_DG.INITIATE_FS_FAILOVER was invoked in a maximum available fast-start failover configuration when the configuration was not synchronized.
ORA-16819: Fast-Start Failover observer not started
DBMS_DG.INITIATE_FS_FAILOVER was invoked but an observer had not yet been started.
ORA-16820: Fast-Start Failover observer is no longer observing this database
DBMS_DG.INITIATE_FS_FAILOVER was invoked but the configuration detects that the observer may not be running.
ORA-16829: lagging Fast-Start Failover configuration
DBMS_DG.INITIATE_FS_FAILOVER was invoked in a maximum performance fast-start failover configuration when the configuration was not in the user-specified redo lag limit.



Regards
Mahir M. Quluzade