DB2 LUW HADR

The main purpose of this video-tutorial is to show you how to implement DB2 HADR technology. In this example we have two servers: db2hadr1@hadr1 (primary) & db2hadr2@hadr2 (standby) both runing linux with DB2 LUW installed and network properly configured.

Step 1: Create instances on the primary and standby servers

On both primary and standby servers, we proceed to create the required instances with the following command:

hadr1:/opt/ibm/db2/V9.7/instance#./db2icrt -s wse -a SERVER -p 444444 -u db2fenc1 db2hadr1

If the user db2hadr1 doesn't exist on the Operating System, we must create it.

Step 2: Create sample database

On both primary and standby servers, we proceed to create sample databases:

# su – db2hadr1

db2hadr1@hadr1:~$ db2sampl

Step 3: Enable LOGRETAIN

We set LOGRETAIN to RECOVERY, to indicate that the logs are retained (archived) and can be used for forward recovery:

db2hadr1@hadr1:~$ db2 update database configuration for sample using LOGRETAIN recovery

db2hadr1@hadr1:~$ db2 update database configuration for sample using LOGINDEXBUILD ON

Step 4: Backup primary database

db2hadr1@hadr1:~$ mkdir backup

db2hadr1@hadr1:~$ db2 backup db sample to $PWD/backup

# copy DB backup file to standby server.

db2hadr1@hadr1:~$ scp -r backup db2hadr2@hadr2

Step 5: Restore backup on the standby

# Restore DB on standby from backup file

db2hadr2@hadr2:~$ db2 restore db sample from $PWD/backup taken at 20110519161326 replace history file

Step 6: Configure HADR peers IPs & Ports on primary db2

Step 7: Configure HADR peers IPs & Ports on standby db2

Step 8: Configure HADR parameters on both primary & standby

Issue the following commands on both systems in order to configure HADR Cluster in Synchronous mode:

db2 update db cfg for sample using HADR_REMOTE_INST db2inst1

db2 update db cfg for sample using HADR_SYNCMODE SYNC

db2 update db cfg for sample using HADR_TIMEOUT 3

db2 update db cfg for sample using HADR_PEER_WINDOW 120

db2 connect to sample

db2 quiesce database immediate force connections

db2 unquiesce database

db2 connect reset



Step 9: Activate HADR on standby

Step 10: Activate HADR on primary

Step 11: Check that it works!

Check that there is not gap between the primary Log sequence number (LSN) and the standby log LSN. As we can see, after inserting some rows over primary database, LSN remains equal.