Question
You plan to setup High Availability Data Replication between two DB2 databases and need step by step instructions
Answer
These instructions allow you to setup HADR for DB2 on a Windows environment. However the same commands can be used for Linux and UNIX by simply changing the "D:\" to a valid path.
ON THE PRIMARY:
1. Create sample db using the db2sampl command.
db2sampl
2. Enable it for log archiving.
1. For db2 version 9.5 and 9.7
db2 update db cfg for
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.
db2 "backup database
4. Setting up HADR cfg parameters on Primary database.
db2 update db cfg for
db2 update db cfg for
db2 update db cfg for
db2 update db cfg for
db2 update db cfg for
db2 update db cfg for
5. Take an offline backup to be used for setting HADR.
db2 "backup database
ON THE STANDBY MACHINE:
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
7. db2 "restore database DBNAME"
8. Setting up HADR cfg parameters on standby database.
db2 update db cfg for
db2 update db cfg for
db2 update db cfg for
db2 update db cfg for
db2 update db cfg for
9. db2 start hadr on database
ON THE PRIMARY MACHINE:
10. Starting up HADR on the primary server
db2 start hadr on database
--Verifing HADR is up and running
db2pd -db
==================================================================
Here's the steps on switching roles (PRIMARY/STANDBY) between the two
machine (CM01 and CM11).
1. ON PRIMARY (CM01): db2 connect to
2. ON PRIMARY (CM01): db2 "create table tab1 (col1 int)"
3. ON PRIMARY (CM01): db2 "insert into tab1 values (1)" -insert 20 rows
4. ON PRIMARY (CM01): power down the Primary --> db2stop force
5. ON STANDBY (CM11): db2 takeover hadr on database
6. The STANDBY instance on CM11 (DB2) is now the primary
7. ON CM11: db2pd -db
8. ON CM11: db2 connect to
9. ON CM11: db2 "select * from tab1" -You should see the 20 rows inserted
10. ON CM11: db2 "create table tab2 (col1 int)"
11. ON CM11 db2 "insert into tab2 values (1)" -insert about 20 rows
12. ON CM01: db2 start hadr on database
13. ON CM01: db2pd -db
14. on CM01: db2 takeover hadr on database
15. on CM01: db2pd -db
16. ON CM01: db2 "select * from tab2" -you should be able to see the 20 rows inserted
17. on CM11: db2pd -db
Note:
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.