--------------------------------------------ON THE Primary SERVER------------------------------------------------
(01) Turn on TCP/IP communications
db2set DB2COMM=tcpip
(02) db2 update dbm cfg using SVCENAME 60000
(03) create the sample database(if not any databases)
db2sampl
(04) HADR Configuration update
db2 update db cfg for SAMPLE using LOGARCHMETH1 C:/DB_ARCH/sample (if it is not you can create a folder)
(05) After Log method change to affect we have to get a full backup
db2 backup db SAMPLE
(06) HADR Configuration update
db2 update db cfg for SAMPLE using HADR_LOCAL_HOST db2svr1
db2 update db cfg for SAMPLE using HADR_LOCAL_SVC 60002
db2 update db cfg for SAMPLE using HADR_REMOTE_HOST db2svr2
db2 update db cfg for SAMPLE using HADR_REMOTE_SVC 60002
db2 update db cfg for SAMPLE using HADR_REMOTE_INST db2inst1
db2 UPDATE DB CFG FOR SAMPLE USING HADR_TIMEOUT 120
db2 UPDATE DB CFG FOR SAMPLE USING HADR_SYNCMODE NEARSYNC
SYNC : Transactions on primary commits only after relevant logs are written to disk on both primary and standby.
NEARSYNC : Transactions on primary commits only after relevant logs are written to disk on primary and received into memory on standby.
ASYNC : Transactions on primary commits only after relevant logs have been written to local disk and sent to standby.
SUPERASYNC : Transactions on primary does not wait for replication of logs to the standby.
db2 update db cfg for SAMPLE using LOGINDEXBUILD ON
db2 UPDATE DB CFG FOR SAMPLE USING HADR_PEER_WINDOW 300
(07) Need to get a online backup to HADR
db2 backup db SAMPLE online to {location}
-------------------------------------------------ON THE DR SERVER------------------------------------------------
(08) Restore the online backup get from primary
db2 restore db SAMPLE from {location}
(09) HADR Configuration update
db2 update db cfg for SAMPLE using HADR_LOCAL_HOST {hostname}
db2 update db cfg for SAMPLE using HADR_LOCAL_SVC 60002
db2 update db cfg for SAMPLE using HADR_REMOTE_HOST {remote hostname}
db2 update db cfg for SAMPLE using HADR_REMOTE_SVC 60002
db2 update db cfg for SAMPLE using HADR_REMOTE_INST db2inst1
db2 UPDATE DB CFG FOR SAMPLE USING HADR_TIMEOUT 120
db2 UPDATE DB CFG FOR SAMPLE USING HADR_SYNCMODE NEARSYNC
db2 UPDATE DB CFG FOR SAMPLE USING HADR_PEER_WINDOW 300
(10) Start HADR on Standby DB
db2 start hadr on database SAMPLE as standby
--------------------------------------------ON THE Primary SERVER------------------------------------------------
(11) Start HADR on Primary DB
db2 start hadr on database SAMPLE as primary
(12) Check if the HADR active or not
db2pd -db {DBNAME} -hadr
(13) Now can change physical and standby from below command
db2 takeover hadr on database {DBNAME}
-----------------------------------------------------------------------------------------------------------------------------
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): power down the Primary --> db2stop force
5. ON 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 SAMPLE as standby
13. ON CM01: db2pd -db SAMPLE -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)
-----------------------------------------------------------------------------------------------------------------------------