Example: Setting up HADR in multiple OpenShift clusters

This example has one primary and one principal standby in the same OpenShift® project within the same cluster, and one auxiliary standby in a different OpenShift cluster (disaster site).

Using Determining the NodePorts for a multiple cluster configuration configuration, the ports for each database in the example are:

  • Primary: 32457
  • Standby: 31384
  • Aux1: 32649

To set up HADR for databases that are in different OpenShift clusters:

  1. Run the following command to invoke the setup_config_hadr script on the primary database Db2® 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 32457 --standby-port 31384 --aux1-name db2oltp-aux --aux1-port 32649 --etcd-host my-etcd-client.my-etcd --etcd-port 2379 --multicluster

    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|c-db2oltp-standby-hadr-svc-ext
    HADR_LOCAL_SVC 60006|32457
    HADR_REMOTE_HOST c-db2oltp-standby-hadr-svc-ext
    HADR_REMOTE_SVC 31384
    HADR_TARGET_LIST c-db2oltp-standby-hadr-svc-ext:31384|c-db2oltp-aux-hadr-svc-ext:32649
    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. An extra step is required here to copy from Cluster1 (where the primary database is located) to Cluster2 (where the auxiliary standby database is located).
    # 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 principal standby database
    oc rsync /tmp/hadr/ c-db2oltp-standby-db2u-0:/mnt/backup/ 
    
    # After copying /tmp/hadr/ from Cluster1 to Cluster2
    oc rsync /tmp/hadr/ c-db2oltp-aux-db2u-0:/mnt/backup/ 
    
  3. Run the following command to invoke the setup_config_hadr script on the principal standby database Db2 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 32457 --standby-port 31384 --aux1-name db2oltp-aux --aux1-port 32649 --etcd-host my-etcd-client.my-etcd --etcd-port 2379 --multicluster

    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|c-db2oltp-primary-hadr-svc-ext
    HADR_LOCAL_SVC 60007|31384
    HADR_REMOTE_HOST c-db2oltp-primary-hadr-svc-ext
    HADR_REMOTE_SVC 32457
    HADR_TARGET_LIST c-db2oltp-primary -hadr-svc-ext:32457|c-db2oltp-aux-hadr-svc-ext:32649
    etcd: my-etcd-client.my-etcd:2379
    
  4. Run the following command to invoke the setup_config_hadr script on the auxiliary standby database Db2 pod:
    oc exec -it c-db2oltp-aux-db2u-0 -- setup_config_hadr --db-role aux1 --primary-name db2oltp-primary --standby-name db2oltp-standby --primary-port 32457 --standby-port 31384 --aux1-name db2oltp-aux --aux1-port 32649 --etcd-host my-etcd-client.my-etcd --etcd-port 2379 --multicluster

    The output of the command:

    ################################################################################
    ###        Creating HADR configuration file for HADR setup.                  ###
    ################################################################################
    
        Database role -- aux1
        primary database formation_id -- db2oltp-aux
    
    HADR_REMOTE_INST db2inst1
    HADR_TIMEOUT 120
    HADR_SYNCMODE NEARSYNC
    HADR_PEER_WINDOW 120
    LOGINDEXBUILD ON
    HADR_LOCAL_HOST c-db2oltp-aux-db2u-0|c-db2oltp-aux-hadr-svc-ext
    HADR_LOCAL_SVC 60008|32649
    HADR_REMOTE_HOST c-db2oltp-primary-hadr-svc-ext
    HADR_REMOTE_SVC 32457
    HADR_TARGET_LIST c-db2oltp-standby-hadr-svc-ext:31384|c-db2oltp-primary-hadr-svc-ext:32457
    etcd: my-etcd-client.my-etcd:2379