DB2 High Availability Disaster Recovery(HADR) is similar like oracle DataGurd.It's easy to configure and maintenance.You can learn how to configure it from this article.I have two nodes:syb02 and syb05.They are running redhat linux 6.3 and syb02 as the primary node,syb05 as the standby node.The DB2 version is V97fp7 for linux x86_64.I just show you using command-line to setup HADR.Also you can use the DB2 control center to configure it.Following table is my environment:
1.Set the required database configuration parameters
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using logretain on
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using trackmod on
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using logindexbuild on
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using indexrec restart
2.Back up abcdb on the primary by running the following command
- [abcinst@syb02 ~]$ db2 backup db abcdb to /share/db2/backup/
- Backup successful. The timestamp for this backup p_w_picpath is : 20130409194052
3.Move a copy of the backup to the standby server
4.Restore the database on standby server
- [abcinst@syb05 ~]$ db2 restore db abcdb from /share/db2/backup taken at 20130409194052 replace history file
Notice:After restore to standby server,you mustn't run rollforward command.
5.Configure databases for ACR(optional)
- On primary server:
- [abcinst@syb02 ~]$ db2 update alternate server for db abcdb using hostname 172.16.255.35 port 50000
- On standby server:
- [abcinst@syb05 ~]$ db2 update alternate server for db abcdb using hostname 172.16.255.32 port 50000
6.Append following line into /etc/services
- [root@syb02 ~]# tail -2 /etc/services
- DB2_HADR_1 55001/tcp
- DB2_HADR_2 55002/tcp
7.Update the HADR database configuration parameters on the primary database
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using HADR_LOCAL_HOST 172.16.255.32
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using HADR_LOCAL_SVC DB2_HADR_1
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using HADR_REMOTE_HOST 172.16.255.35
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using HADR_REMOTE_SVC DB2_HADR_2
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using HADR_REMOTE_INST abcinst
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using HADR_SYNCMODE SYNC
- [abcinst@syb02 ~]$ db2 update db cfg for abcdb using HADR_TIMEOUT 120
- [abcinst@syb02 ~]$ db2 connect to abcdb
- [abcinst@syb02 ~]$ db2 quiesce db immediate force connections
- [abcinst@syb02 ~]$ db2 unquiesce db
- [abcinst@syb02 ~]$ db2 connect reset
8.Update the HADR database configuration parameters on the standby database
- [abcinst@syb05 ~]$ db2 update db cfg for abcdb using HADR_LOCAL_HOST 172.16.255.35
- [abcinst@syb05 ~]$ db2 update db cfg for abcdb using HADR_LOCAL_SVC DB2_HADR_2
- [abcinst@syb05 ~]$ db2 update db cfg for abcdb using HADR_REMOTE_HOST 172.16.255.32
- [abcinst@syb05 ~]$ db2 update db cfg for abcdb using HADR_REMOTE_SVC DB2_HADR_1
- [abcinst@syb05 ~]$ db2 update db cfg for abcdb using HADR_REMOTE_INST abcinst
- [abcinst@syb05 ~]$ db2 update db cfg for abcdb using HADR_SYNCMODE SYNC
- [abcinst@syb05 ~]$ db2 update db cfg for abcdb using HADR_TIMEOUT 120
9.Optional
If you want to use the reads on standby feature, you must set the corresponding registry variables on the standby server by running the following commands:
- [abcinst@syb05 ~]$ db2set DB2_HADR_ROS=ON
- [abcinst@syb05 ~]$ db2set DB2_STANDBY_ISO=UR
10.Start the standby database first by the following commands on SYB05
- [abcinst@syb05 ~]$ db2 deactivate db abcdb
- [abcinst@syb05 ~]$ db2 start hadr on db abcdb as standby
- SQL1766W The command completed successfully. However, LOGINDEXBUILD was not enabled before HADR was started.
11.Start HADR on the primary database on SYB02
- [abcinst@syb02 ~]$ db2 deactivate db abcdb
- [abcinst@syb02 ~]$ db2 start hadr on db abcdb as primary
Testing the HADR
1.Connect to primary database do following steps
Create a table:SYB_DATABASEINF
- [abcinst@syb02 ~]$ db2 connect to abcdb
- [abcinst@syb02 ~]$ db2 "create table SYB_DATABASEINF (
- hostname char(18) not null ,
- accesstime char(20) not null ,
- dbname char(20) not null ,
- dbsize float(16) not null ,
- datafree float(16) not null ,
- logsize float(16) not null ,
- logfree float(16) not null
- )
- in tbs01"
Import data into SYB_DATABASEINF from textfile:
- [abcinst@syb02 ~]$ db2 "import from /mnt/iq2/SYB_DATABASEINF.txt of del insert into SYB_DATABASEINF"
- [abcinst@syb02 ~]$ db2 "select count(*) from SYB_DATABASEINF"
- 1
- -----------
- 1973065
2.Switch roles of the databases
On standby server,running takeover command:
- [abcinst@syb05 ~]$ db2 takeover hadr on db abcdb
After switch,the syb02 become to standby role and the syb05 become to primary role.
3.Checking all of the roles status
On new primary server:
- [abcinst@syb05 ~]$ db2 get snapshot for db on abcdb |grep -B 15 "Log gap running average(bytes)"
- HADR Status
- Role = Primary
- State = Peer
- Synchronization mode = Sync
- Connection status = Connected, 04/10/2013 15:08:57.689470
- Heartbeats missed = 0
- Local host = 172.16.255.35
- Local service = DB2_HADR_2
- Remote host = 172.16.255.32
- Remote service = DB2_HADR_1
- Remote instance = abcinst
- timeout(seconds) = 120
- Primary log position(file, page, LSN) = S0000048.LOG, 8448, 000000004F8289F1
- Standby log position(file, page, LSN) = S0000048.LOG, 8448, 000000004F8289F1
- Log gap running average(bytes) = 0
On new standby server:
- [abcinst@syb02 ~]$ db2 get snapshot for db on abcdb |grep -B 15 "Log gap running average(bytes)"
- HADR Status
- Role = Standby
- State = Peer
- Synchronization mode = Sync
- Connection status = Connected, 04/09/2013 23:08:45.964717
- Heartbeats missed = 0
- Local host = 172.16.255.32
- Local service = DB2_HADR_1
- Remote host = 172.16.255.35
- Remote service = DB2_HADR_2
- Remote instance = abcinst
- timeout(seconds) = 120
- Primary log position(file, page, LSN) = S0000048.LOG, 8448, 000000004F8289F1
- Standby log position(file, page, LSN) = S0000048.LOG, 8448, 000000004F8289F1
- Log gap running average(bytes) = 0
4.Connect to the new primary server and query the total number of SYB_DATABASEINF table
- [abcinst@syb05 ~]$ connect to abcdb
- Database Connection Information
- Database server = DB2/LINUXX8664 9.7.7
- SQL authorization ID = ABCINST
- Local database alias = ABCDB
- [abcinst@syb05 ~]$ db2 "select count(*) from SYB_DATABASEINF"
- 1
- -----------
- 1973065
That's all for Fast Track To DB2 High Availability Disaster Recovery,for more information from here.