Example: Setting up Db2 HADR in a single IBM Cloud cluster

This example has one primary and one principal standby in different OpenShift® projects within the same cluster on IBM Cloud. The same logic applies for deployments in a single OpenShift project, except the project names would be the same for primary and standby.

Note the project for each deployment. In this example:

  • Primary: project primary-project
  • Standby: project standby-project

The ports for each database:

  • Primary: 60006
  • Standby: 60007

Instead of using IP addresses, use the fully qualified domain name for each db2u-0 pod instead:

  • Primary: c-db2oltp-primary-db2u-0.c-db2oltp-primary-db2u-internal.primary-project.svc.cluster.local
  • Standby: c-db2oltp-standby-db2u-0.c-db2oltp-standby-db2u-internal.standby-project.svc.cluster.local

Procedure

  1. Set up HADR using the setup_config_hadr script on the primary database db2u 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 c-db2oltp-primary-db2u-0.c-db2oltp-primary-db2u-internal.primary-project.svc.cluster.local --standby-clusterip c-db2oltp-standby-db2u-0.c-db2oltp-standby-db2u-internal.standby-project.svc.cluster.local --etcd-host my-etcd-client.my-etcd --etcd-port 2379

    The HADR configuration settings are in the script output:

    ################################################################################
    ###        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|c-db2oltp-primary-db2u-0.c-db2oltp-primary-db2u-internal.primary-project.svc.cluster.local
    HADR_LOCAL_SVC 60006|60006
    HADR_REMOTE_HOST c-db2oltp-standby-db2u-0.c-db2oltp-standby-db2u-internal.standby-project.svc.cluster.local
    HADR_REMOTE_SVC 60007
    HADR_TARGET_LIST c-db2oltp-standby-db2u-0.c-db2oltp-standby-db2u-internal.standby-project.svc.cluster.local:60007
    etcd: my-etcd-client.my-etcd:2379
    

    If the setup is successful, you should see the following message 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 database 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. Set up HADR by using the setup_config_hadr script on the standby database db2u 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 c-db2oltp-primary-db2u-0.c-db2oltp-primary-db2u-internal.primary-project.svc.cluster.local --standby-clusterip c-db2oltp-standby-db2u-0.c-db2oltp-standby-db2u-internal.standby-project.svc.cluster.local --etcd-host my-etcd-client.my-etcd --etcd-port 2379

    Script output:

    ################################################################################
    ###        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|c-db2oltp-standby-db2u-0.c-db2oltp-standby-db2u-internal.standby-project.svc.cluster.local
    HADR_LOCAL_SVC 60007|60007
    HADR_REMOTE_HOST c-db2oltp-primary-db2u-0.c-db2oltp-primary-db2u-internal.primary-project.svc.cluster.local
    HADR_REMOTE_SVC 60006
    HADR_TARGET_LIST c-db2oltp-primary-db2u-0.c-db2oltp-primary-db2u-internal.primary-project.svc.cluster.local:60006
    etcd: my-etcd-client.my-etcd:2379