DB2 High Availability Data Replication - Setup
PRIMARY NODE
1. Identify or create database for HADR
db2 create database <DBNAME> ... or db2sampl
2. Configure DB for log archiving
db2 update db cfg for <DBNAME> using LOGARCHMETH1 LOGRETAIN
Above command will enable to database for log archiving and keep the logs in the same active log directory. This will also place the db in backup pending state.
3. Configure HADR DB parameters on Primary database
db2 update db cfg for <DBNAME> using HADR_LOCAL_HOST <IP ADDRESS OF PRIM> db2 update db cfg for <DBNAME> using HADR_LOCAL_SVC <PORT # on PRIM> db2 update db cfg for <DBNAME> using HADR_REMOTE_HOST <IP ADDRESS OF STNDBY> db2 update db cfg for <DBNAME> using HADR_REMOTE_SVC <PORT # on STNDBY> db2 update db cfg for <DBNAME> using HADR_REMOTE_INST <INSTNAME OF STNDBY> db2 update db cfg for <DBNAME> using LOGINDEXBUILD ON
4. Take an offline backup to be used for HADR configuration
db2 "backup database <DBNAME> [to '/path/to/backup'|use TSM]"
5. Transfer the backup image to the Standby node or grant access to Standby TSM node
STANDBY NODE
Ensure both the servers are on the same db2level so that a mismatch situation does not occur. Run “db2level” command on both the servers to check whether they are on the same DB2 Version and Fix Pack.
6. Restore the database from backup image (disk or TSM)
db2 "restore database DBNAME [from '/path/to/backup'|use TSM] taken at <TIMESTAMP>"
7. Configure HADR DB parameters on Standby DB
db2 update db cfg for <DBNAME> using HADR_LOCAL_HOST <IP ADDRESS ON STANDBY> db2 update db cfg for <DBNAME> using HADR_LOCAL_SVC <PORT #/SERVICE NAME ON STANDBY> db2 update db cfg for <DBNAME> using HADR_REMOTE_HOST <IP ADDRESS ON PRIM> db2 update db cfg for <DBNAME> using HADR_REMOTE_SVC <PORT # ON PRIM> db2 update db cfg for <DBNAME> using HADR_REMOTE_INST <INSTNAME ON PRIM>
8. Start HADR on Standby DB
db2 start hadr on database <DBNAME> as standby
PRIMARY NODE
9. Start HADR on Primary DB
db2 start hadr on database <DBNAME> as primary
10. Check HADR is up and running
db2pd -db <DBNAME> -hadr
Hostname of the HADR pair cannot be the same on both the servers. The instance name and the underlying userid on UNIX systems can be different. Make sure to update the correct name of the instance for the db cfg parameter HADR_REMOTE_INST to the correct value.