Step-by-Step Guide to Set Up Data Guard Broker in Oracle


Oracle Data Guard Broker is a distributed management framework that automates and centralizes the creation, configuration, and monitoring of a Data Guard configuration. It simplifies many of the tasks related to managing Data Guard.

This guide outlines the step-by-step process for setting up the Data Guard Broker in Oracle.

Pre-Requisites

Before setting up Data Guard Broker, ensure that:

  1. You have an Oracle Database environment configured with a primary and standby database.
  2. Data Guard is already configured and running between the primary and standby databases.
  3. Both the primary and standby databases are using Oracle Enterprise Edition.
  4. Oracle Net Services is configured to allow connectivity between the primary and standby systems.

Step 1: Enable Force Logging and Archive Log Mode on Primary

First, ensure that the primary database is in archive log mode and force logging is enabled:

  1. Log in to the primary database as SYSDBA:


    sqlplus / as sysdba
  2. Enable force logging:


    ALTER DATABASE FORCE LOGGING;
  3. Ensure the database is in ARCHIVELOG mode:


    ARCHIVE LOG LIST;

    If the database is not in archive log mode, put it in archive log mode:


    SHUTDOWN IMMEDIATE; STARTUP MOUNT; ALTER DATABASE ARCHIVELOG; ALTER DATABASE OPEN;

Step 2: Configure the Primary and Standby Database Parameters

You need to configure several initialization parameters on both the primary and standby databases to enable Data Guard Broker.

On the Primary Database:

  1. Set the DB_UNIQUE_NAME and LOG_ARCHIVE_CONFIG:


    ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary_db, standby_db)' SCOPE=BOTH; ALTER SYSTEM SET DB_UNIQUE_NAME='primary_db' SCOPE=SPFILE;
  2. Set the LOG_ARCHIVE_DEST_2 parameter to point to the standby database:

    ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=standby_db ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby_db' SCOPE=BOTH;

  3. Enable the Data Guard Broker:


    ALTER SYSTEM SET DG_BROKER_START=TRUE SCOPE=BOTH;
  4. Set the FAL_SERVER and FAL_CLIENT:


    ALTER SYSTEM SET FAL_SERVER='standby_db' SCOPE=BOTH; ALTER SYSTEM SET FAL_CLIENT='primary_db' SCOPE=BOTH;

On the Standby Database:

  1. Set the DB_UNIQUE_NAME and LOG_ARCHIVE_CONFIG:


    ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary_db, standby_db)' SCOPE=BOTH; ALTER SYSTEM SET DB_UNIQUE_NAME='standby_db' SCOPE=SPFILE;
  2. Set the LOG_ARCHIVE_DEST_2 parameter to point to the primary database:


    ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=primary_db ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary_db' SCOPE=BOTH;
  3. Enable the Data Guard Broker:


    ALTER SYSTEM SET DG_BROKER_START=TRUE SCOPE=BOTH;
  4. Set the FAL_SERVER and FAL_CLIENT:


    ALTER SYSTEM SET FAL_SERVER='primary_db' SCOPE=BOTH; ALTER SYSTEM SET FAL_CLIENT='standby_db' SCOPE=BOTH;

Step 3: Set Up Static Listener Entries

Make sure that the static listener entries are present on both the primary and standby databases to handle the Data Guard Broker connections.

  1. Open the listener.ora file on both primary and standby servers.

  2. Add a static listener entry for the databases. Example:


    (SID_DESC = (GLOBAL_DBNAME = primary_db_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1) (SID_NAME = primary_db) )
  3. Restart the listener:


    lsnrctl reload

Step 4: Create the Data Guard Configuration Using DGMGRL

Now that the initialization parameters are set, use the Data Guard Command-Line Interface (DGMGRL) to configure the Data Guard Broker.

  1. Connect to the primary database using DGMGRL:


    dgmgrl sys/password@primary_db
  2. Create a Data Guard configuration:


    CREATE CONFIGURATION 'DGConfig' AS PRIMARY DATABASE IS 'primary_db' CONNECT IDENTIFIER IS 'primary_db';
  3. Add the standby database to the configuration:


    ADD DATABASE 'standby_db' AS CONNECT IDENTIFIER IS 'standby_db';
  4. Enable the configuration:


    ENABLE CONFIGURATION;
  5. Verify the Data Guard configuration:


    SHOW CONFIGURATION;

Step 5: Verify the Data Guard Setup

You can verify that the Data Guard Broker is working properly by using DGMGRL commands.

  1. Check the configuration status:


    SHOW CONFIGURATION;

    This command should return the status of both the primary and standby databases. If everything is correct, the status should be "SUCCESS".

  2. Check the primary and standby database status:


    SHOW DATABASE 'primary_db'; SHOW DATABASE 'standby_db';

    The status of each database should show "SUCCESS" and "ONLINE" as the role.

Step 6: Switchover and Failover Using Data Guard Broker

After setting up Data Guard Broker, you can easily perform switchover and failover operations using the DGMGRL command-line utility.

Switchover

To perform a switchover from the primary to the standby database:

  1. Connect to DGMGRL:


    dgmgrl sys/password@primary_db
  2. Issue the switchover command:


    SWITCHOVER TO 'standby_db';
  3. Verify the switchover status:


    SHOW CONFIGURATION;

    After the switchover, the former standby database becomes the primary database, and the former primary database becomes the standby.

Failover

To perform a failover to the standby database (in case of a primary database failure):

  1. Connect to DGMGRL:


    dgmgrl sys/password@standby_db
  2. Issue the failover command:


    FAILOVER TO 'standby_db';
  3. Verify the failover status:


    SHOW CONFIGURATION;

    After the failover, the standby database takes over as the primary database.

Step 7: Monitoring and Managing Data Guard with Broker

  1. Monitor the configuration:


    SHOW CONFIGURATION VERBOSE;

    This will give you detailed information about the Data Guard configuration.

  2. Check log gaps:

    You can check for log transport and apply lag between the primary and standby databases.


    SHOW DATABASE 'standby_db' STATUSREPORT;
  3. Disable or enable specific databases:

    To disable a database:


    DISABLE DATABASE 'standby_db';

    To enable it again:


    ENABLE DATABASE 'standby_db';
  4. Remove a database from the configuration (e.g., for maintenance):


    REMOVE DATABASE 'standby_db';






Please do like and subscribe to my youtube channel: https://www.youtube.com/@foalabs If you like this post please follow,share and comment