Configuring high availability for a data source database

To configure a high availability database as a data source, you need to perform the required steps to set up the standby and the primary databases.

About this task

It is important to ensure the consistency between the primary database and the standby database when you configure high availability on the data source database. You should not make any changes to the federated database or the data source database (that is, DDL or DML) during the configuration.

When the data source is Db2® Database, configuration of automatic client reroute is required for a data source database acting as the high availability database. The federated server requires automatic client reroute to automatically establish a connection to the new primary database after takeover.

The following procedure provides configuration instructions for the Db2 Database data source.

Procedure

  1. Choose an existing data source database, or create the data source database on primary database server by using the CREATE DATABASE statement.
    For example:
    db2 create db ds
    create table t11 (i int, c char(20));
    insert into t11 values (11, 'dsds');
  2. Backup the database on the primary database server and restore the database on the standby database server.
    You must specify logretain on for the high availability database. For example:
    On the primary server:
    db2 update db cfg for ds using logretain on
    
    db2 backup db ds to /directory
    On the standby server:
    db2 restore db ds from /directory
  3. Configure the standby database for high availability and automatic client reroute.
    For example:
    db2 UPDATE DB CFG FOR ds USING HADR_LOCAL_HOST hostnamest;
    db2 UPDATE DB CFG FOR ds USING HADR_REMOTE_HOST hostnampr;
    db2 START HADR ON DB ds AS STANDBY;
    db2 UPDATE ALTERNATE SERVER FOR DATABASE ds USING HOSTNAME hostnamepr PORT port1
  4. Configure the primary database for high availability and automatic client reroute.
    For example:
    db2 UPDATE DB CFG FOR feddb USING HADR_LOCAL_HOST hostnamepr;
    db2 UPDATE DB CFG FOR feddb USING HADR_REMOTE_HOST hostnamest;
    db2 START HADR ON DB ds AS PRIMARY;
    db2 UPDATE ALTERNATE SERVER FOR DATABASE ds USING HOSTNAME hostnamest PORT port2
    For additional information about configuring high availability, see Database configuration for high availability disaster recovery (HADR). For additional information about configuring automatic client reroute, see Configuring automatic client reroute and High Availability Disaster Recovery (HADR).

    What to do next

    After HADR is configured on the data source database, you can create a federated database by following the procedure to create a federated database and create each of the following objects on the federated database for accessing the data source database with high availability:
    1. Create a wrapper by using the CREATE WRAPPER statement.
    2. Create a server by using the CREATE SERVER statement.
    3. Create a user mapping by using the CREATE USER MAPPING statement.
    4. Create a nickname by using the CREATE NICKNAME statement.
    You can also access the data source database with high availability though nicknames on an existing federated database.

    On the data source, if the primary database fails, you can issue the TAKEOVER HADR command on the standby database. The standby database then becomes the new primary database that can take over transaction processing. The federation server automatically switches the connection to the new primary database.