High Availability Series: Part 1 - DB2 HADR Setup

I am planning to post a set of articles covering various DR options provided by Oracle, DB2 and Progress OpenEdge database. This will include setup guides for Oracle DataGuard, DB2 HADR and OpenEdge Fathom Replication.

Series will be started with basic setup of each of these technologies, and then these will be reconfigured, changed as per the requirements to demonstrate different recovery scenarios.

First I will setup a simple HADR system using Virtualbox. At the start only basic setup will be configured and will be changed/ reconfigured when testing different DR situations.

Virtualbox Setup

Install OS and db2 (I am using Oracle linux 5.6 (32) and db2 10.1 (32)) into single VM.

Clone or manually create another duplicate server. 

Make sure to configure network connectivity between two machines. Use different hosts names. In this example my primary would be "db21" and standby is "db22"

DB2 Setup

step 1 – Create two db2 instances
Primary – 
 db2icrt –u db2fenc 1 db2inst1  
Standby – 
 db2icrt –u db2fenc2 db2inst2  

Step 2 - Create sample database on primary server
I have created SAMPLE database by just running - ./db2sampl

Step 3 –Setup database for remote connectivity,
set DB2COMM registry variable to tcpip.
 db2set DB2COMM=tcpip  
Update database manager configuration “SVCENAME” using the service defined in /etc/services.
 db2 "update dbm cfg using SVCENAME DB2_db2inst1"  
After setting these OS and DB parameter my primary and secondary databases are configured as follows.

Primary
Secondary
IP address
192.168.0.184
192.168.0.106
Hostname
db21
db22
Port/service
DB2_db2inst1/60004
DB2_db2inst2/60008
Instance name/user
db2inst1
db2inst2
Database
Sample
-

Step 4 - Enable primary database for archive logging.
Set LOGRETAIN to on.
 db2 "update dbm cgg using logretain on"  
Step 5 -  Enable logged index rebuild and rebuild to happen at HADR log apply.
Set LOGINDEXBUILD to on.
 db2 "update db cfg for SAMPLE using LOGINDEXBUILD ON"  
Set INDEXREC to RESTART.
 db2 "update db cfg for SAMPLE using INDEXREC RESTART"  
Step 6 - Backup primary database and restore it in standby server
You can use either online or offline backup. I ll be using an online backup. As db2inst1 user on Primary server,
 db2 "backup database sample online to /home/db2inst1"  
Since I have created standby server as a clone of the primary my restoration is straight forward as well.
SCP the backup file from 0.184:/home/db2inst1 to 0.106:/home/db2inst2. On Standby as db2inst2 run,
 db2 "restore database sample from /home/db2inst2"  
If there are any difference between the servers it is required to address them during the restoration (redirected restore - example http://dbtechno.blogspot.com/2012/12/part1-db2-restorerecover-online-backup.html ). Also it should only be the restore, no roll-forwarding is done for standby db.

Step 7 - Add HADR configuration on Pimary and Standby

On primary add below parameters,
   db2 update alternate server for database sample using hostname db22 port 60008  
   db2 update db cfg for SAMPLE using HADR_LOCAL_HOST 192.168.0.184  
   db2 update db cfg for SAMPLE using HADR_LOCAL_SVC 60001  
   db2 update db cfg for SAMPLE using HADR_REMOTE_HOST 192.168.0.106  
   db2 update db cfg for SAMPLE using HADR_REMOTE_SVC 60002  
   db2 update db cfg for SAMPLE using HADR_REMOTE_INST db2inst2  

Here HADR remote/local ports must be different from instance ports. Also there are many more HADR related parameters which are defaulted for this basic setup guide.

On Standby add below parameters,
   db2 update alternate server for database sample using hostname db21 port 60004  
   db2 update db cfg for SAMPLE using HADR_LOCAL_HOST 192.168.0.106  
   db2 update db cfg for SAMPLE using HADR_LOCAL_SVC 60002  
   db2 update db cfg for SAMPLE using HADR_REMOTE_HOST 192.168.0.184  
   db2 update db cfg for SAMPLE using HADR_REMOTE_SVC 60001  
   db2 update db cfg for SAMPLE using HADR_REMOTE_INST db2inst1  

That is it, Now your HADR setup is complete, and when you start HADR on both sides standby database should get synced from the production database.

Step 8 - Start/Monitor HADR on both sides.

First start HADR on standby side, as db2inst2 user on standby
 db2 "start hadr on database sample as standby"  
Then as db2inst1 user on primary,
 db2 "start hadr on database sample as primary"  
To monitor the HADR status use,
 db2pd -d sample -hadr  

Ok. So our basic HADR setup is completed. We will discuss more options, configurations and different failover scenarios later by using this base setup.


Comments

Popular posts from this blog

ORA-16433: The database or pluggable database must be opened in read/write

Wait for unread message on broadcast channel - Blocking Sessions

ORA-14126 - While splitting max value partition