Steps to configure HADR Environment in DB2


DB2 high availability disaster recovery (HADR) is a data replication feature that provides a high availability solution for both partial and complete site failures. HADR protects against data loss by replicating data changes from a source database, called the primary, to a target database, called the standby.

 

Step 1:

Create 2 DB2 Instances(db2inst1,db2inst2)
Create Instance 1 by typing "db2icrt  -u db2fenc1 db2inst1"
Create Instance 2 by typing "db2icrt -u db2fenc2 db2inst2"

Note: The parameter logarchmeth1 should be enabled on these 2 instances, because the backup supports archival logging.

 

Step 2:

Configure Instance 1
Type the following commands:

db2set DB2COMM=TCPIP
db2 update dbm cfg using SVCENAME 50000
db2start

 

Step 3:

Configure Instance 2

Type the following commands:
db2set DB2COMM=TCPIP
db2 update dbm cfg using SVCENAME 50004
db2start

Step 4: Create the Primary DB in Instance 1
Type the following commands:

SET DB2INSTANCE=DB2INST1
db2 create db SAMPLE
db2 update db cfg for SAMPLE using LOGINDEXBUILD on
db2 update db cfg for SAMPLE using INDEXREC RESTART
Note: This step will turn the DB into archival logging mode

Step 5: Create a backup of Primary DB
Type the following commands:
db2 BACKUP DB SAMPLE (It will store in your present directory)

Step 6: Restore the backup SAMPLE as Standby database

Type the following commands:
SET DB2INSTANCE=DB2INST2
db2 RESTORE DB SAMPLE

Note: This step will restore the database as SAMPLE in the second DB2 instance and place it into roll forward pending state.

Note: If you roll forward the SAMPLE now, you will not be able to initialize it as the standby database.

Step 7: Configure the HADR settings for the Primary DB in DB2INST1

Type the following commands in the first instance:

db2 update db cfg for SAMPLE using hadr_local_host localhost

db2 update db cfg for SAMPLE using hadr_local_svc 50000
db2 update db cfg for SAMPLE using hadr_remote_host remotehost
db2 update db cfg for SAMPLE using hadr_remote_svc 50004
db2 update db cfg for SAMPLE using hadr_remote_inst DB2INST2

 

Type the following commands in the second instance:

 

db2 update db cfg for SAMPLE using hadr_local_host localhost
db2 update db cfg for SAMPLE using hadr_local_svc 50004
db2 update db cfg for SAMPLE using hadr_remote_host remotehost
db2 update db cfg for SAMPLE using hadr_remote_svc 50000
db2 update db cfg for SAMPLE using hadr_remote_inst DB2INST1

Note: Primary SAMPLE HADR service port will be 50000.
Note: Standby SAMPLE HADR service port will be 50004.


Warning: You cannot use the Instance TCPIP port (SVCENAME) or next port number (SVCENAME+1) as the HADR service port. This is by design.
Now, you are ready to test the configuration.


Step 8: Start HADR on Standby DB IN DB2INST2
SET DB2INSTANCE=DB2INST2
db2 START HADR ON DB SAMPLE AS STANDBY
Step 9: Start HADR on Primary DB IN DB2INST1

SET DB2INSTANCE=DB2INST1
db2 START HADR ON DB SAMPLE AS PRIMARY

Step 10: Take over the Primary Role to Standby Instance
SET DB2INSTANCE=DB2INST2
db2 TAKEOVER HADR ON DB SAMPLE

Step 11: Take back the Primary Role from Standby Instance
SET DB2INSTANCE=DB2INST1
db2 TAKEOVER HADR ON DB SAMPLE

Step 12: Stop the HADR service on Primary DB
SET DB2INSTANCE=DB2INST1
db2 deactivate db SAMPLE
db2 STOP HADR ON DB SAMPLE
Step 13: Stop the HADR service on Standby DB

SET DB2INSTANCE=DB2INST2
db2 deactivate db SAMPLE
db2 STOP HADR ON DB SAMPLE

Comments

Popular posts from this blog

Db2 export command example using file format (del , ixf)

How to fix DB2 Tablespace OFFLINE state issue?

How to determine fenced User-ID of a DB2 instance