2.运行db2licm -l 查看是否支持hadr特性
3.两台机器: serverA 10.10.20.16 255.255.255.0 serverB 10.10.20.110 255.255.255.0
4.两台机器均使用默认实例DB2,服务端口号均为 50000
5.由于安装后注册表参数 db2comm=TCPIP为默认值, 所以下面不再配置,若不是此值,
必须通过命令 db2set db2comm=TCPIP为每个相关实例设置
6.关闭防火墙或打开端口 */
--在serverA上执行 set db2instance=DB2 db2set db2comm=TCPIP--默认即是
db2 terminate db2stop db2start
--创建数据库 db2sampl
--修改数据库参数
db2 update db cfg for sample using logretain=on
db2 update db cfg for sample using trackmod=on
db2 update db cfg for sample using logindexbuild=on
db2 update db cfg for sample using indexrec=restart
--备份数据库 db2 backup db sample to f:/test
--在serverB上: set db2instance=DB2
--因为以下命令导致数据库处于前滚暂挂状态,
db2 restore db sample from f:/test replace history file
db2 update db cfg for sample using HADR_LOCAL_HOST 10.10.20.110
db2 update db cfg for sample using HADR_LOCAL_SVC 44444
db2 update db cfg for sample using HADR_REMOTE_HOST 10.10.20.16
db2 update db cfg for sample using HADR_REMOTE_SVC 33333
db2 update db cfg for sample using HADR_REMOTE_INST DB2
db2 update db cfg for sample using HADR_SYNCMODE nearsync
--在serverA上配置sample数据库参数
set db2instance=DB2 db2 update db cfg for sample using HADR_LOCAL_HOST 10.10.20.16
db2 update db cfg for sample using HADR_LOCAL_SVC 33333
db2 update db cfg for sample using HADR_REMOTE_HOST 10.10.20.110
db2 update db cfg for sample using HADR_REMOTE_SVC 44444
db2 update db cfg for sample using HADR_REMOTE_INST DB2
db2 update db cfg for sample using HADR_SYNCMODE nearsync
--在serverB上以standby方式启动sample数据库
set db2instance=DB2 db2 deactivate database sample
db2 start hadr on database sample as standby
--在serverA上以primary方式启动sample数据库
set db2instance=DB2 db2 start hadr on database sample as primary
--在serverA上查看sample数据库的hadr状态
set db2instance=DB2 db2pd -d sample -hadr
--在serverB上查看sample数据库的hadr状态
set db2instance=DB2 db2pd -d sample -hadr
--测试:
--在serverA上
set db2instance=DB2
db2 connect to sample
db2 create table test(id integer)
db2 insert into test(1)
db2 insert into test(2)
db2 commit
db2 select * from sample
--在serverB上 set db2instance=DB2 --接管hadr,如果不能建立与serverA上DB2实例的连接,
比如serverA服务器或DB2实例已经关闭,则必须用by force选项如下:
db2 takeover hadr on database sample user db2admin using db2admin by force
--正常接管
db2 takeover hadr on database sample user db2admin using db2admin
db2 connect to sample db2 select * from test --显示数据表明serverA上的数据应用到了serverB上了
--查看hadr状态
db2pd -d sample -hadr