db2

Setting up DB2 HADR

These days databases are an important part of running the business, hence the availability of the database is astronomicallycritical.  Its really important that critical database needs to have high availability at all times.IBM added HADR to DB2 few years back, it stands for High Availability Disaster Recovery. HADR provides failover capability should the primary database server fails.  If the primary server fails, the workload is transferred over to the secondary server. HADR is not automatic failover, so don’t get confused with DB2 on Cluster Server .

In a HADR setup there is a primary server which is online and can accept connections from applications and then there is a secondary server which plays the log and keep the data in sync with the primary server.

Below are the tasks I did to setup DB2 HADR :

Tasks

Server

Server names

Tom

Jerry

 

 

 

OS

Redhat Linux

Redhat Linux

DB2 edition

V9.7 ESE

V9.7 ESE

IP address

192.168.110.10

192.168.110.11

Instance

db2inst1

db2inst1

Database

CARTOON

 

 

 

 

Backup database

BACKUP DATABASE CARTOON TO /bkup

 

ftp/sftp

ftp the backup file from Tom to Jerry

 

Update primary database for automatic client reroute;

UPDATE ALTERNATE SERVER FOR DATABASE cartoons USING HOSTNAME jerry PORT 60000;

 

Update HADR configuration parameters for primary database

UPDATE DB CFG FOR cartoons USING LOGINDEXBUILD ON ;
UPDATE DB CFG FOR cartoons USING INDEXREC RESTART ;
UPDATE DB CFG FOR cartoons USING HADR_LOCAL_HOST tom;
UPDATE DB CFG FOR cartoons USING HADR_LOCAL_SVC 60006;
UPDATE DB CFG FOR cartoons USING HADR_REMOTE_HOST jerry;
UPDATE DB CFG FOR cartoons USING HADR_REMOTE_SVC 60007;
UPDATE DB CFG FOR cartoons USING HADR_REMOTE_INST db2inst1;
UPDATE DB CFG FOR cartoons USING HADR_SYNCMODE NEARSYNC;
UPDATE DB CFG FOR cartoons USING HADR_TIMEOUT 120;
UPDATE DB CFG FOR cartoons USING HADR_PEER_WINDOW 0;
QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS;
DEACTIVATE DATABASE cartoons;
UNQUIESCE DATABASE;
CONNECT RESET;

 

Restore database

 

RESTORE DATABASE cartoons FROM /db2bkup TAKEN AT 20110411090137 REPLACE HISTORY FILE WITHOUT PROMPTING;

Update standby database for automatic client reroute;

 

UPDATE ALTERNATE SERVER FOR DATABASE cartoons USING HOSTNAME tom PORT 60000;

Update HADR configuration parameters for standby database;

 

UPDATE DB CFG FOR cartoons USING LOGINDEXBUILD ON ;
UPDATE DB CFG FOR cartoons USING INDEXREC RESTART ;
UPDATE DB CFG FOR cartoons USING HADR_LOCAL_HOST jerry;
UPDATE DB CFG FOR cartoons USING HADR_LOCAL_SVC 60007;
UPDATE DB CFG FOR cartoons USING HADR_REMOTE_HOST tom;
UPDATE DB CFG FOR cartoons USING HADR_REMOTE_SVC 60006;
UPDATE DB CFG FOR cartoons USING HADR_REMOTE_INST db2inst1;
UPDATE DB CFG FOR cartoons USING HADR_SYNCMODE NEARSYNC;
UPDATE DB CFG FOR cartoons USING HADR_TIMEOUT 120;
UPDATE DB CFG FOR cartoons USING HADR_PEER_WINDOW 0;

Start HADR on standby database

 

START HADR ON DATABASE cartoons AS STANDBY;

Start HADR on primary database

ATTACH TO “db2inst1”;
DEACTIVATE DATABASE cartoons;
START HADR ON DATABASE cartoons AS PRIMARY;
CONNECT TO “cartoons”;

 

 

 

 

Verify HADR status

db2pd -hadr -d     >>> should say Primary  Peer

db2pd -hadr -d     >>> should say Standby Peer

Manual takeover

 

takeover hadr on database cartoons

Verify HADR status

db2pd -hadr -d     >>> should say Standby Peer

db2pd -hadr -d     >>> should say Primary  Peer

 

Try it out and let me know how it goes ?  As always use your best judgement when you try this on your system.