Using the Db2 Warehouse HADR API

The Db2 Warehouse HADR API provides the interface to configure and start HADR for two databases that are on the same cluster and in the same Red Hat® OpenShift® project. This API is supported by an OpenShift custom resource definition (CRD).

Quick links

Configuring the primary and standby databases

When you set up HADR, you must define a primary and standby database. At a minimum, you must specify the Db2uCluster or Db2uInstance name for both the primary and standby. You can find these names by using the oc get db2ucluster,db2uinstance command.

You can also define the HADR services and specific endpoints to use for the HADR databases. If the services and endpoints do not exist, they are created for you.

For example,

primary:
   db2uName: "db2u-wh-primary"
   service:
     name: "db2u-wh-primary-hadr-svc"
     port: 60006
standby:
   db2uName: "db2u-wh-standby"
   service:
     name: "db2u-wh-standby-hadr-svc"
     port: 60007

Configuring etcd

The Governor service that enables automatic failover of the HADR configuration relies on an etcd key-value store to track the HADR state information, such as the current leader (primary node). A single etcd endpoint must be shared between the two HADR deployments. If these fields are not provided, the default etcd setup is the primary deployment's built-in etcd cluster, but this setup is meant for development-only environments. Use this setting to define your own etcd cluster.

For example,

etcd: 
   name: "cloud-etc-svc"
   port: 3056

Configuring HADR database configuration parameters

When you configure HADR, you can specify the hadr_timeout, hadr_syncmode, and hadr_peer_window configuration parameters. See HADR configuration parameters for more information.

For example:

dbConfig:
   timeOut: 90
   syncMode: "NEARSYNC"
   peerWindow: 120

Configuring HADR features

Db2 Warehouse on IBM Software Hub 5.2 introduces a role-aware service feature when you configure HADR by using the Db2uHadr custom resource. When this feature is enabled, an extra Kubernetes service is created when the Db2 Warehouse operator configures HADR. This service will always redirect traffic to the current HADR primary deployment by a label on the pod hadr_role=primary. The Db2 Warehouse operator monitors the HADR role of both deployments in the HADR configuration and updates the label.

Applications can use the role-aware service c-<Db2uHADR_CR_name>-hadr-primary-svc for Db2 Warehouse connections instead of enabling ACR.

Restriction:
  • Only one of either the ACR or role-aware service feature can be enabled.
  • This service can be enabled only after you create the Db2uHadr CR.
  • When the primary role switches deployments, applications must reconnect to the database with the same service to establish a connection to the new primary.
To enable the service, enable the new feature and define the Kubernetes service type that you require. If not defined, the type defaults to ClusterIP. Refer to the following example:
  features:
    routeToPrimaryService:
      enable: true
      service:
        type: "NodePort"
        name: "my-hadr-svc"
  • spec.features.routeToPrimaryService.service.type: A Kubernetes service type. Possible options are ClusterIP, NodePort, and LoadBalancer. The default value is ClusterIP.
  • spec.features.routeToPrimaryService.service.name: The name for the role-aware Kubernetes service. The default value is c-<Db2uHadr_CR_name>-primary-svc.

When you configure HADR, you can optionally disable automatic client reroute or enable reads on standby. You cannot use automatic client reroute if you enable reads on standby.

Note: Client reroute does not differentiate between writable databases (primary and standard databases) and read-only databases (standby databases). Configuring client reroute between the primary and standby might route applications to the database on which they are not intended to be run.

For example, the following example shows client reroute disabled and reads on standby enabled:

features:
   enableAutomaticClientReroute: false
   enableReadsOnStandby: true

HADR advanced options

The hostNameResolutionUsingPodFQDN advanced option allows you to configure HADR with the FQDN pod instead of Kubernetes services.

When you configure HADR with the Db2uHadr custom resource, the Db2 Warehouse operator creates Kubernetes services for HADR communication between the primary and standby deployments. In some cloud environments, you might have additional networking layers that require the use of the FQDN pod instead of services to ensure successful Db2 Warehouse validation of hostnames and IP addresses.

Important: This technique is only recommended for IBM Cloud environments.
Add the following to your custom resource to enable the FQDN pod:
advancedOptions:
    hostNameResolutionUsingPodFQDN: "True"

Example of a complete Db2uHadr custom resource

The following example shows a complete Db2uHadr HADR custom resource:

apiVersion: db2u.databases.ibm.com/v1alpha1
kind: Db2uHadr
metadata:
  name: db2u-wh-hadr
spec:
  primary:
    db2uName: "db2u-wh-primary"
  standby:
    db2uName: "db2u-wh-standby"
  etcd:
    name: "cloud-etc-svc"
    port: 3056
  dbConfig:
    timeOut: 90
    syncMode: "NEARSYNC"
    peerWindow: 120
  features:
    enableAutomaticClientReroute: false
    enableReadsOnStandby: false
    routeToPrimaryService:
      enable: true
      service:
        type: "NodePort"
        name: "my-hadr-svc"