Step by Step Procedure to set up HADR replication between DB2 databases

DB2 provides database clustering as well as high availability and disaster recovery capabilities designed to maximize data availability during both planned and unplanned events. It also allows you to quickly and easily adapt to changing workloads with minimal involvement from database administrators, and frees application developers from the underlying complexities of database design and architecture.

DB2 high availability disaster recovery (HADR) feature provides a high availability solution for both partial and complete site failures. HADR protects against data loss by replicating data changes from a source or the primary server, to one or more standby servers.

This is step by step Procedure to set up HADR replication between DB2 databases.


1. Create sample db using the db2sampl command.

2. Enable it for log archiving.

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. Take an offline backup.

4. Setting up HADR cfg parameters on Primary database.

5. Take an offline backup to be used for setting HADR.



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. FTP the backup image (from the primary machine) to the STANDBY MACHINE, you can using scp if you using Linux/Unix Machine

7. Restore the database

8. Setting up HADR cfg parameters on standby database.

9. Starting up HADR on the standby server “as standby”



10. Starting up HADR on the primary server

11. Verifing HADR is up and running

Or you can use “db2top” command and then press “A” (capital)


Howto switch the database?

On the standby machine:

1. Hostname of the HADR pair cannot be the same on both the servers.
2. 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.

Reference :