Manually initiating an HADR takeover in Db2

To initiate a takeover of the standby database, use the --manage_hadr command with the -takeover option in the Db2 engine pod. To switch to an auxiliary database, use the optional aux and force parameters with the -takeover option.

Use the -takeover option to perform a forced takeover to switch roles of the primary and standby databases when performing scheduled maintenance of the primary database or worker node on which the primary database is running. This option can be used when the primary and standby databases are connected and in PEER state.

Failover, or forced takeover, can be performed when the primary is not available. Governor will automatically fail over from primary to principal standby if a primary failure occurs. If multiple standbys are set up, a manual failover can be performed to the auxiliary standby in the event that the primary and principal standby are unavailable.

The following example shows the use of the --manage_hadr command with the -takeover option:

oc exec -it c-db2oltp-1616469166354348-db2u-0 -- manage_hadr -takeover

The command output shows the current primary database and then the new primary database (leader). The following example shows the output when issuing the takeover from the principal standby:

#######################################################################
###           Db2 Advanced Edition high availability and               ###
###             disaster recovery (HADR) management                 ###
#######################################################################


Running HADR action -takeover on the database BLUDB ...
################################################################################
###                     Running takeover HADR on BLUDB                       ###
################################################################################
Executing HADR role-switch via Db2 Governor ...
current leader is c-db2oltp-1616468282925295-db2u-0
new leader is c-db2oltp-1616469166354348-db2u-0


################################################################################
###            The manage_hadr command completed an HADR takeover.           ###
################################################################################


The HADR action -takeover was successful

To validate that the takeover was successful, use the --manage_hadr command with the -status option to verify that the standby database now has the primary HADR role, and that the two databases are connected.

Graceful takeover to auxiliary standby

A graceful takeover (role-switch) to the auxiliary standby might be required if the primary and principal standby clusters are undergoing maintenance.

The following example shows the use of the --manage_hadr command with the -takeover aux option:

oc exec -it c-aux-db2u-0 -- manage_hadr -takeover aux

This command ensures that Governor does not try to automatically failover back to the primary or principal standby, and then executes a takeover to the auxiliary standby database. The following example shows the output when issuing a takeover from the auxiliary standby:

#######################################################################
###           Db2 Advanced Edition high availability and               ###
###             disaster recovery (HADR) management                 ###
#######################################################################


Running HADR action -takeover on the database BLUDB ...
################################################################################
###        Running auxiliary standby takeover HADR on BLUDB                  ###
################################################################################
Executing HADR takeover to auxiliary standby ...
2021-05-28 03:52:36,203 INFO: using etcd3 as truth_manager
2021-05-28 03:52:36,247 INFO: Attempt connect to: 172.30.139.33:2379
2021-05-28 03:52:36,250 INFO: Established new connection to: 172.30.139.33:2379
status: <etcd3.client.Status object at 0x1513ee625c10>
2021-05-28 03:52:36,250 INFO: verify endpoint success
2021-05-28 03:52:36,250 INFO: Using force_etcd ip: dummy
################################################################################
###                     Running takeover HADR on BLUDB                       ###
################################################################################
takeover hadr on db BLUDB
DB20000I  The TAKEOVER HADR ON DATABASE command completed successfully.

################################################################################
###            The manage_hadr command completed an HADR takeover.           ###
################################################################################

The HADR action -takeover was successful

Forced takeover (failover) to auxiliary standby

A forced takeover (failover) to the auxiliary standby might be required if both the primary and principal standby clusters are unavailable.

The following example shows the use of the --manage_hadr command with the -takeover aux force option:

oc exec -it c-aux-db2u-0 -- manage_hadr -takeover aux force

This command ensures that Governor does not try to automatically failover back to the primary or principal standby, and then executes a takeover by force to the auxiliary standby database. The following example shows the output when issuing a forced takeover from the auxiliary standby:

#######################################################################
###           Db2 Advanced Edition high availability and               ###
###             disaster recovery (HADR) management                 ###
#######################################################################

Running HADR action -takeover on the database BLUDB ...
################################################################################
###        Running auxiliary standby takeover HADR on BLUDB                  ###
################################################################################
Executing HADR takeover to auxiliary standby ...
2021-05-28 03:55:41,617 INFO: using etcd3 as truth_manager
2021-05-28 03:55:41,665 INFO: Attempt connect to: 172.30.139.33:2379
2021-05-28 03:55:41,669 INFO: Established new connection to: 172.30.139.33:2379
status: <etcd3.client.Status object at 0x1505ab0c6cd0>
2021-05-28 03:55:41,669 INFO: verify endpoint success
2021-05-28 03:55:41,669 INFO: Using force_etcd ip: dummy
################################################################################
###                     Running takeover HADR on BLUDB                       ###
################################################################################
takeover hadr on db BLUDB by force
DB20000I  The TAKEOVER HADR ON DATABASE command completed successfully.

################################################################################
###            The manage_hadr command completed an HADR takeover.           ###
################################################################################

The HADR action -takeover was successful