Wednesday 17 April 2013

Configuring an HADR Environment




For the intent of all purposes, I installed a fresh copy of DB2 ESE version 9 and chooose NOT to create the default DB2 instance. 

Step 1: Create 2 DB2 Instances
                 Open up an instance of DB2 Command Window by typing "db2cmd" in Run dialog.
                 Create Instance 1 by typing "db2icrt DB2INST1"
                 Create Instance 1 by typing "db2icrt DB2INST2"
Step 2: Configure Instance 1  ::   "db2inst1"   Type the following commands:

                 
db2set DB2COMM=tcpip
                  db2set DB2_RESTORE_GRANT_ADMIN_AUTHORITIES = on
                  db2 update dbm cfg using SVCENAME 61001
                  db2start
                  Note: The TCPIP service port for this instance is 61001
Step 3: Configure Instance 2  ::     "db2inst2"    Type the following commands:

                 db2set DB2COMM=tcpip
                 db2 update dbm cfg using SVCENAME 62001
                 db2start
                 Note: The TCPIP service port for this instance is 62001

Step 4: Create the Primary DB in Instance 1  : :

                 db2 create db BANKARS on /data/home/dbpath
                 db2 update db cfg for BANKARS using LOGINDEXBUILD on
                 db2 update db cfg for BANKARS using INDEXREC RESTART
                 db2 update db cfg for BANKARS using LOGRETAIN on            
                 Note: This step will turn the DB into archival logging mode

Step 5: Create a backup of Primary DB

                db2 BACKUP DB BANKARS TO /data/home/backups
            Backup successful. The timestamp for this backup image is : 20121010141139
               Note: This step will backup the BANKARS db into /data/home/backups

Step 6: Restore the backup BANKARS as Standby database

          db2 RESTORE DB BANKARS FROM /data/home/backups taken at 20121010141139 redirect generated script bankars_script.sql
          db2 -tvf  bankars_script.sql

Note: This step will restore the database as BANKARS in the second DB2 instance and place it into roll forward pending state.
Note: If you roll forward the BANKARS 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

       db2 update alternate server for database BANKARS using hostname localhost port 62001
       db2 update db cfg for BANKARS using hadr_local_host localhost
       db2 update db cfg for BANKARS using hadr_local_svc 21001
       db2 update db cfg for BANKARS using hadr_remote_host localhost
       db2 update db cfg for BANKARS using hadr_remote_svc 22001
       db2 update db cfg for BANKARS using hadr_remote_inst DB2INST2
       db2 update db cfg for BANKARS using hadr_syncmode SYNC
       db2 update db cfg for BANKARS using hadr_timeout 120

       Note: Primary BANKARS HADR service port will be 21001.
       Note: Standby BANKARS HADR service port will be 22001.
Warning: You cannot use the Instance TCPIP port (SVCENAME) or next port number (SVCENAME+1) as the HADR service port. This is by design.

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

        db2 update alternate server for database BANKARS using hostname localhost port 61001
        db2 update db cfg for BANKARS using hadr_local_host localhost
        db2 update db cfg for BANKARS using hadr_local_svc 22001
        db2 update db cfg for BANKARS using hadr_remote_host localhost
        db2 update db cfg for BANKARS using hadr_remote_svc 21001
        db2 update db cfg for BANKARS using hadr_remote_inst DB2INST1
        db2 update db cfg for BANKARS using hadr_syncmode SYNC
        db2 update db cfg for vusing hadr_timeout 120

        Note: Primary BANKARS HADR service port will be 41005.
        Note: Standby BANKARS HADR service port will be 42005.
 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

                 db2 START HADR ON DB BANKARS AS STANDBY

Step 9: Start HADR on Primary DB IN DB2INST1

                 db2 START HADR ON DB BANKARS AS PRIMARY

Step 10: Take over the Primary Role to Standby Instance


                 db2 TAKEOVER HADR ON DB BANKARS

Step 11: Take back the Primary Role from Standby Instance

                 db2 TAKEOVER HADR ON DB BANKARS

Step 12: Stop the HADR service on Primary DB

               db2 STOP HADR ON DB BANKARS

Step 13: Stop the HADR service on Standby DB

                 db2 deactivate db BANKARS
                 db2 STOP HADR ON DN BANKARS







No comments:

Post a Comment