DB2 HADR for dummies – Part 2
Okay, so here we go …. setting up an hadr environment…. HADR in it’s lowest form is very straight forward to set up. Here are the steps to start HADR
- You need to have either a second machine with DB2 installed, or alternately you can use a second instance. I’m sure I don’t have to tell you that using a second instance of DB2 on the same machine defeats the whole purpose of this, but it is fine for testing
- Make sure you have Log Retain set on either explicitly or implicitly
- Make sure you have db cfg LOGINDEXBUILD set to On
you need to set the following db config parameters –
HADR_LOCAL_HOST set to the IP address or host name of the local host
HADR_LOCAL_SVC set to the port you are going to assign
HADR_REMOTE_HOST set to the IP address of standby instance – same as LOCAL if using an alternate instance
HADR_REMOTE_SVC set to the standby port should be at least LOCAL +2
HADR_REMOTE_INST set to standby instance name - Make a backup of your database – can be either online or offline
- Send the backup to the standby machine. If you are using two instances, then you can skip this
- restore from the backup on the standby instance — I’m assuming you are using the IBM SAMPLE database for this excerise.
- On the standby database, you need to set the same db config values except you need to flip them around so they are correct – LOCAL values become REMOTE values.
- On the standby machine/instance “db2 start hadr on database sample as standby”
- On the primary machine/instance “db2 start hadr on database sample as primary”
- Check if HADR is working – Do “db2 get snapshot for database on sample” — in the output look for:
HADR Status
Role = Primary
State = Peer
Synchronization mode = Nearsync
Connection status = Connected , 11/26/2009 17:47:40.447523
Heartbeats missed = 0
Local host = 192.168.0.105
Local service = 10000
Remote host = 192.168.0.101
Remote service = 11000
Remote instance = DB2
timeout(seconds) = 120
Primary log position(file, page, LSN) = S0000036.LOG, 0, 000000000B3B0000
Standby log position(file, page, LSN) = S0000036.LOG, 0, 000000000B3B0000
Log gap running average(bytes) = 0 if it says anything other than ‘peer’ then there is a problem. One common problem is a firewall… if you are doing this on a windows box with a firewall, then you will have to open up the HADR ports both ways.
You now have a HADR pair up and running — anything you do on the primary will be done on the standby as well. Be sure to review things that don’t work.
Standby for Part 3 where we will go over how to switch back and forth from primary to standby.
