Example: Setting up Db2 HADR in a single OpenShift cluster across multiple OpenShift projects

This example has one primary and one principal standby in different OpenShift projects within the same cluster.

Because the services were created by using Setting up the HADR configuration for Db2, the ports for each database are:

  • Primary: 60006
  • Standby: 60007

The IP addresses for each database are:

  • Primary: 172.30.77.20
  • Standby: 172.30.247.77

In the example below, the IP address of the primary database is 172.30.77.20:

oc get svc | grep hadr-svc
# Output:
c-db2oltp-primary-hadr-svc        ClusterIP   172.30.77.20     <none>        60006/TCP,60007/TCP,60008/TCP,60009/TCP                                           26s

oc describe svc c-db2oltp-primary-hadr-svc
# Output:
Name:                     c-db2oltp-primary-hadr-svc
Namespace:                zen
Labels:                   <none>
Annotations:              <none>
Selector:                 app=db2oltp-primary,type=engine
Type:                     ClusterIP
IP:                       172.30.77.20
Port:                     db2u-hadrp  60006/TCP
TargetPort:               60006/TCP
Endpoints:                10.254.27.150:60006
Port:                     db2u-hadrs  60007/TCP
TargetPort:               60007/TCP
Endpoints:                10.254.27.150:60007
Port:                     db2u-hadra1  60008/TCP
TargetPort:               60008/TCP
Endpoints:                10.254.27.150:60008
Port:                     db2u-hadra2  60009/TCP
TargetPort:               60009/TCP
Endpoints:                10.254.27.150:60009
Session Affinity:         None
Events:                   <none>
  1. Run the following command to invoke the setup_config_hadr script on the primary Db2 database pod:
    oc exec -it c-db2oltp-primary-db2u-0 -- setup_config_hadr --db-role primary --primary-name db2oltp-primary --standby-name db2oltp-standby --primary-port 60006 --standby-port 60007 --primary-clusterip 172.30.77.20 --standby-clusterip 172.30.247.77 --etcd-host my-etcd-client.my-etcd --etcd-port 2379

    The output of the command contains the HADR configuration settings:

    ################################################################################
    ###        Creating HADR configuration file for HADR setup.                  ###
    ################################################################################
    
        Database role -- primary
        primary database formation_id -- db2oltp-primary
    
    HADR_REMOTE_INST db2inst1
    HADR_TIMEOUT 120
    HADR_SYNCMODE NEARSYNC
    HADR_PEER_WINDOW 120
    LOGINDEXBUILD ON
    HADR_LOCAL_HOST c-db2oltp-primary-db2u-0|172.30.77.20
    HADR_LOCAL_SVC 60006|60006
    HADR_REMOTE_HOST 172.30.247.77
    HADR_REMOTE_SVC 60007
    HADR_TARGET_LIST 172.30.247.77:60007
    etcd: my-etcd-client.my-etcd:2379

    If the setup is successful, the following message displays at the end of the script output:

    ################################################################################
    ###        The HADR setup command completed the primary node setup.          ###
    ################################################################################
    
  2. Copy the database backup image and keystore file in the backup storage area (/mnt/backup/) from the primary database to the standby databases by using rsync.
    # Copy from primary database to a directory on the host called /tmp/hadr
    oc rsync c-db2oltp-primary-db2u-0:/mnt/backup/ /tmp/hadr
    
    # Copy from the /tmp/hadr directory on the host to the standby database
    oc rsync /tmp/hadr/ c-db2oltp-standby-db2u-0:/mnt/backup/
  3. Run the following command to invoke the setup_config_hadr script on the standby Db2 database pod:
    oc exec -it c-db2oltp-standby-db2u-0 -- setup_config_hadr --db-role standby --primary-name db2oltp-primary --standby-name db2oltp-standby --primary-port 60006 --standby-port 60007 --primary-clusterip 172.30.77.20 --standby-clusterip 172.30.247.77 --etcd-host my-etcd-client.my-etcd --etcd-port 2379

    The output of the command:

    ################################################################################
    ###        Creating HADR configuration file for HADR setup.                  ###
    ################################################################################
    
        Database role -- standby
        primary database formation_id -- db2oltp-standby
    
    HADR_REMOTE_INST db2inst1
    HADR_TIMEOUT 120
    HADR_SYNCMODE NEARSYNC
    HADR_PEER_WINDOW 120
    LOGINDEXBUILD ON
    HADR_LOCAL_HOST c-db2oltp-standby-db2u-0|172.30.247.77
    HADR_LOCAL_SVC 60007|60007
    HADR_REMOTE_HOST 172.30.77.20
    HADR_REMOTE_SVC 60006
    HADR_TARGET_LIST 172.30.77.20:60006
    etcd: my-etcd-client.my-etcd:2379