Availability ‐ HADR switch over - andyoolala/DB2 GitHub Wiki

Verify HADR status

  • Check HADR status , ** SyncMode must be Nearsync **
db2pd -d $DB_NAME -hadr

Database Partition 0 -- Database XXDB -- Active -- Up 100 days 17:45:43 -- Date 2022-03-22-13.43.16.676993

HADR Information:
Role    State                SyncMode   HeartBeatsMissed   LogGapRunAvg (bytes)
- Primary Peer                 Nearsync 0                  6795

ConnectStatus ConnectTime                           Timeout
Connected     Sat Dec 11 20:01:41 2021 (1639224101) 60

LocalHost                                LocalService
- 10.18.1.2                                69902

RemoteHost                               RemoteService      RemoteInstance
- 10.18.1.1                                69901              istcent

PrimaryFile  PrimaryPg  PrimaryLSN
S0274955.LOG 420        0x00000D1C67CCC5F7

StandByFile  StandByPg  StandByLSN
S0274955.LOG 417        0x00000D1C67CC95C8

we've known that the role on this host is primary and HADR sync status are fine.

in this case, produce HADR switch over between 10.18.1.1 (standby) and 10.18.1.2 (primary)

Switch over

  • logon primary db server , and remove service IP
su - root
ip a del 10.18.1.3/21 dev bond0:1

downtime start

  • logon standby db server (In this case , 10.18.1.1)
  • issue takeover command
su - $instance_name
db2 "takeover hadr on db $DB_NAME"
  • check HADR status again
  • add service IP
su - root
ip a add 10.18.1.3/21 dev bond0:1

downtime end

failover

  • assume primary node are failed ( verify service ip not owned by primary node )
  • logon standby db node
  • if standby node is not running
db2start
db2 start hadr on db ${DB_NAME} as standby
  • check tablespace status
db2pd -d ${DB_NAME} -tablespaces
  • issue takeover by force command
db2 "takeover hadr on db $DB_NAME by force"