Setup DB2 HADR Environment for Connections, Sametime or Traveler

In this post I would like to show you a possible high availability configuration, based on the DB2 HADR (High Availability Disaster Recovery) feature. You are able to use this configuration to secure your Connection, Traveler or Sametime environment (Please verify your license before using this feature).

In my example I will configure a high availability configuration for one database which is running active/passive on two database nodes. Both on Linux. Of course it is possible to use more nodes, active/active configuration or Windows OS.

First of all some informations about the used software and features:

  • DB2 HADR (High Availability Disaster Recovery) feature: We will use this feature to replicate the database transaction logs across many database nodes. Furthermore HADR provides the active/passive or active/active database functionality and commands.
  • TSAMP (Tivoli Systems Automation): This software provides scripts to monitor the environment and handle the fallback if needed. On a fallback, TSAMP will switch the active/passive nodes and reassign the virtual IP, which DB2 clients or JDBC connections are using, to the active node. You have to install TSAMP on Windows on your own. On Linux it will be installed during the DB2 setup.

Steps to setup the environment:

  1. Install a typical DB2 database server on both nodes. I will skip this part in my post.
  2. Configure your network settings: In my case, I am using a VLAN for the replication between the two nodes (node1-ip, node2-ip). To access the database via client or JDBC, I configured a virtual IP and DNS alias (vip-alias).
  3. Add HADR port in /etc/services on both nodes:
    DB2_HADR 60500/tcp
  4. Restart DB2 on both nodes
  5. Create a database on node 1:
    CREATE DB TESTDB
  6. Configure database “testdb” on node 1:
    UPDATE DB CFG FOR TESTDB USING HADR_LOCAL_HOST ;
    UPDATE DB CFG FOR TESTDB USING HADR_LOCAL_SVC ;
    UPDATE DB CFG FOR TESTDB USING HADR_REMOTE_HOST ;
    UPDATE DB CFG FOR TESTDB USING HADR_REMOTE_SVC ;
    UPDATE DB CFG FOR TESTDB USING HADR_REMOTE_INST ;
    UPDATE DB CFG FOR TESTDB USING HADR_TIMEOUT 120;
    UPDATE DB CFG FOR TESTDB USING HADR_TARGET_LIST :;
    UPDATE DB CFG FOR TESTDB USING HADR_SYNCMODE NEARSYNC;
    UPDATE DB CFG FOR TESTDB USING HADR_PEER_WINDOW 120;
    UPDATE DB CFG FOR TESTDB USING HADR_SPOOL_LIMIT 0;
    UPDATE DB CFG FOR TESTDB USING HADR_REPLAY_DELAY 0;
    UPDATE DB CFG FOR TESTDB USING BLOCKNONLOGGED YES;
    UPDATE DB CFG FOR TESTDB USING LOGINDEXBUILD ON;
    UPDATE DB CFG FOR TESTDB USING INDEXREC RESTART; 
    UPDATE ALTERNATE SERVER FOR DATABASE TESTDB USING HOSTNAME  PORT ;
    CONNECT TO TESTDB;
    QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS;
    UNQUIESCE DATABASE;
    CONNECT RESET;
    BACKUP DATABASE TESTDB TO  COMPRESS EXCLUDE LOGS WITHOUT PROMPTING;
  7. Copy the created backup to node 2.
  8. Configure database “testdb” on node 2:
    RESTORE DATABASE TESTDB FROM ;
    UPDATE DB CFG FOR TESTDB USING HADR_LOCAL_HOST ;
    UPDATE DB CFG FOR TESTDB USING HADR_LOCAL_SVC ;
    UPDATE DB CFG FOR TESTDB USING HADR_REMOTE_HOST ;
    UPDATE DB CFG FOR TESTDB USING HADR_REMOTE_SVC ;
    UPDATE DB CFG FOR TESTDB USING HADR_REMOTE_INST ;
    UPDATE DB CFG FOR TESTDB USING HADR_TIMEOUT 120;
    UPDATE DB CFG FOR TESTDB USING HADR_TARGET_LIST :;
    UPDATE DB CFG FOR TESTDB USING HADR_SYNCMODE NEARSYNC;
    UPDATE DB CFG FOR TESTDB USING HADR_PEER_WINDOW 120;
    UPDATE DB CFG FOR TESTDB USING HADR_SPOOL_LIMIT 0;
    UPDATE DB CFG FOR TESTDB USING HADR_REPLAY_DELAY 0;
    UPDATE DB CFG FOR TESTDB USING BLOCKNONLOGGED YES;
    UPDATE DB CFG FOR TESTDB USING LOGINDEXBUILD ON;
    UPDATE DB CFG FOR TESTDB USING INDEXREC RESTART; 
    UPDATE ALTERNATE SERVER FOR DATABASE TESTDB USING HOSTNAME  PORT ;
    CONNECT RESET;
    START HADR ON DATABASE TESTDB AS STANDBY;
  9. Start HADR on node 1:
    START HADR ON DATABASE TESTDB AS PRIMARY;
  10. Preconfigure both nodes for TSAMP (use root account):
    preprpnode node1 node2
  11. Configure TSAMP on node 2 first. After it is finished, configure node 1. The script will configure TSAMP domain, network configuration and databases (use DB2 instance user):
    db2haicu

The setup is finished. After this, you can connect to your high availability DB2 environment, using the configured virtual IP. You are able to add more nodes or databases using db2haicu.

Some useful commands:

  • lssam (check domain and database status)
  • db2pd -db testdb -hadr (check database status)
  • db2 takeover hadr on db testdb (takeover database)

Leave a Reply

Your email address will not be published. Required fields are marked *