Step by Step Procedure to set up HADR replication between DB2 databases

Technote (FAQ)


Question

You plan to setup High Availability Data Replication between two DB2 databases and need step by step instructions

Answer

These instructions allow you to setup HADR for DB2 on a Windows environment. However the same commands can be used for Linux and UNIX by simply changing the "D:\" to a valid path.


ON THE PRIMARY:
                                                                         
1. Create sample db using the db2sampl command.

  db2sampl

2. Enable it for log archiving.

   1.  For db2 version 9.5 and 9.7
  db2 update db cfg for <DBNAME> using LOGARCHMETH1 LOGRETAIN
 

Above command will enable to database for log archiving and keep the logs in the same active log directory. This will also place the db in backup pending state.

3. Take an offline backup.
   db2 "backup database <DBNAME>"

4. Setting up HADR cfg parameters on Primary database.

   db2 update db cfg for <DBNAME> using HADR_LOCAL_HOST <IP ADDRESS OF PRIM>
   db2 update db cfg for <DBNAME> using HADR_LOCAL_SVC <PORT # on PRIM>
   db2 update db cfg for <DBNAME> using HADR_REMOTE_HOST <IP ADDRESS OF STNDBY>
   db2 update db cfg for <DBNAME> using HADR_REMOTE_SVC <PORT # on STNDBY>
   db2 update db cfg for <DBNAME> using HADR_REMOTE_INST <INSTNAME OF STNDBY>
   db2 update db cfg for <DBNAME> using LOGINDEXBUILD ON

5. Take an offline backup to be used for setting HADR.

   db2 "backup database <DBNAME>"



ON THE STANDBY MACHINE:

Ensure both the servers are on the same db2level so that a mismatch situation does not occur. Run "db2level" command on both the servers to check whether they are on the same DB2 Version and Fix Pack.

6. FTP the backup image (from the primary machine) to the STANDBY MACHINE

7. db2 "restore database DBNAME"

8. Setting up HADR cfg parameters on standby database"

   db2 update db cfg for <DBNAME> using HADR_LOCAL_HOST <IP ADDRESS ON STANDBY>
   db2 update db cfg for <DBNAME> using HADR_LOCAL_SVC <PORT # ON STANDBY>
   db2 update db cfg for <DBNAME> using HADR_REMOTE_HOST <IP ADDRESS ON PRIM>
   db2 update db cfg for <DBNAME> using HADR_REMOTE_SVC <PORT # ON PRIM>
   db2 update db cfg for <DBNAME> using HADR_REMOTE_INST <INSTNAME ON PRIM>
   

9. db2 start hadr on database <DBNAME> as standby

 

ON THE PRIMARY MACHINE:

10. Starting up HADR on the primary server

   db2 start hadr on database <DBNAME> as primary

   --Verifing HADR is up and running"
   db2pd -db <DBNAME> -hadr

==================================================================

Here's the steps on switching roles (PRIMARY/STANDBY) between the two    
machine (CM01 and CM11).

1. ON PRIMARY (CM01): db2 connect to <dbname>
2. ON PRIMARY (CM01) db2 "create table tab1 (col1 int)
3. ON PRIMARY (CM01): db2 "insert into tab1 values (1) -insert 20 rows
4. ON PRIMARY (CM01): powered down the Primary --> db2stop force
5. on the standby (CM11) -> db2 takeover hadr on database <dbname> by force
6. The STANDBY instance on CM11 (DB2) is now the primary
7. ON CM11: db2pd -db <dbname> -hadr (the ROLE should state: PRIMARY)
8. ON CM11: db2 connect to <dbname>
9. ON CM11: db2 "select * from tab1" -You should see the 20 rows inserted
10. ON CM11: db2 "create table tab2 (col1 int)"
11. ON CM11 db2 "insert into tab2 values (1) -insert about 20 rows
12. ON CM01: db2 start hadr on database <dbname> as standby
13. ON CM01: db2pd -db <dbname> -hadr (the ROLE should state: STANDBY)
14. on CM01: db2 takeover hadr on database <dbname>
15. on CM01: db2pd -db <dbname> -hadr (the ROLE should state: PRIMARY)
16. ON CM01: db2 "select * from tab2" -you should be able to see the 20 rows inserted
17. on CM11: db2pd -db <dbname> -hadr (the ROLE should state; STANDBY)  

Note: Hostname of the HADR pair cannot be the same on both the servers.

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

DB2 for Linux, UNIX and Windows

Software version:

9.1, 9.5, 9.7

Operating system(s):

AIX, HP-UX, Linux, Solaris, Windows

Reference #:

1410648

Modified date:

2013-01-31

Translate my page

Machine Translation

Content navigation