DB2 HADR and HACMP Commands

xample script for setting up HADR
Update configuration parameters on primary database -
UPDATE DB CFG FOR DB SAMPLE USING LOGINDEXBUILD ON
UPDATE DB CFG FOR DB SAMPLE USING INDEXREC RESTART
Copy backup image from primary to standby system.

Restore database on standby system
RESTORE DATABASE SAMPLE REPLACE HISTORY FILE WITHOUT PROMPTING
Configure databases for client reroute - Primary
UPDATE ALTERNATE SERVER FOR DATABASE SAMPLE USING HOSTNAME  PORT

Configure databases for client reroute -Standby
UPDATE ALTERNATE SERVER FOR DATABASE SAMPLE USING HOSTNAME PORT
Edit /etc/services file and create an HADR port on both systems.   On Windows:
notepad %SystemRoot%\system32\drivers\etc\services
Add HADR line on both primary and standby system.  Same port number. ie.   DB2_HADR1     55005
Update HADR configuration parameters on primary database -
UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_HOST
UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_SVC DB2_HADR1
UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_HOST
UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_SVC DB2_HADR1
UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_INST DB2
UPDATE DB CFG FOR SAMPLE USING HADR_SYNCMODE NEARSYNC
UPDATE DB CFG FOR SAMPLE USING HADR_TIMEOUT 120
Enable cfg changes by forcing off all connections
CONNECT TO SAMPLE
QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS
UNQUIESCE DATABASE
CONNECT RESET
Update HADR configuration parameters on standby database - --
UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_HOST
UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_SVC DB2_HADR_14
UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_HOST COL27VM
UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_SVC DB2_HADR_13
UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_INST DB2
UPDATE DB CFG FOR SAMPLE USING HADR_SYNCMODE NEARSYNC
UPDATE DB CFG FOR SAMPLE USING HADR_TIMEOUT 120
Start HADR on standby database
DEACTIVATE DATABASE SAMPLE
START HADR ON DATABASE SAMPLE AS STANDBY
Start HADR on primary database

DEACTIVATE DATABASE SAMPLE
START HADR ON DATABASE SAMPLE AS PRIMARY
View status of HADR
=>db2pd -db -hadr
Swap roles of Primary and Standby
=>db2 takeover hadr on db
Takeover Primary operation on the standby db when the original primary is down
=>db2 takeover hadr on db  by force
Steps for setting up HACMP active/passive
HACMP Active server
1. First create the file .db2nodes.cfg. in the /etc directory which is local to each server and will NOT be failed over to another server, on both servers.
2. Use the local hostname in the /etc/.db2nodes.cfg files on both servers.
3. Make sure permissions for file /etc/.db2nodes.cfg are set to 444 on both servers. 
4. As Instance owner, create a link named db2nodes.cfg from the instance sqllib to this new /etc/.db2nodes.cfg file.
=>ln -fs /etc/.db2nodes.cfg /db2home//sqllib/db2nodes.cfg
5. Make sure you create the .db2nodes.cfg on the same path on both servers, so that link will still work after failover.
6. Also make sure same TCP port is being used/reserved on both servers for the instance service port.
7. Remove db2 startup line from inittabs and provide your own db2 startup and stop scripts.......as root =>rmitab db2start
HACMP Standby server
1.  as root.  vi /etc/.db2nodes.cfg .    chmod 444
permissions on /db2home directory should be 775 and owned by db2as:db2asgrp
Copy /etc/services db2 ports from Active server to /etc/services in Standby server.
Make a file called /var/db2/v81/profiles.reg and add instance names on seperate lines
Copy instance id's .profiles over to standby server.

Popular posts from this blog

Jython Script Examples

Skip fields during duplication