温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

DB2_PureScale环境HADR如何搭建

发布时间:2021-11-16 15:47:30 来源:亿速云 阅读:163 作者:小新 栏目:数据库

这篇文章主要为大家展示了“DB2_PureScale环境HADR如何搭建”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“DB2_PureScale环境HADR如何搭建”这篇文章吧。

#####HADR搭建######
1、创建主库的备份
db2 BACKUP DB sampledb to /gpfs1nsd/backup

-- db2 backup db sampledb online to /gpfs1nsd/backup include logs

2、restore初始化备库
db2 RESTORE DB sampledb from /gpfs1nsd/backup
-- db2 restore db sampledb from "/gpfs1nsd/backup" taken at 20170124085238 to "/gpfs1nsd/SAMPLEDB" logtarget "/gpfs1nsd/backup" with 2 buffers buffer 12800 replace history file parallelism 4

3、在主数据库上,DBA 设置集群级别的 HADR 参数,这些参数指定备用集群和同步方式。
db2 "UPDATE DB CFG FOR sampledb USING\
HADR_TARGET_LIST  {psnode1-standby:4000|psnode2-standby:4000}\
HADR_REMOTE_HOST  {psnode1-standby:4000|psnode2-standby:4000}\
HADR_REMOTE_INST  db2sdin1\
HADR_SYNCMODE     async"
(参数需要重启生效)
   
4、DBA 在主数据库上设置成员级别 HADR 参数,这些参数标识每个成员的地址和端口
对于成员 0:
db2 "UPDATE DB CFG FOR sampledb MEMBER 0 USING HADR_LOCAL_HOST psnode1-primay HADR_LOCAL_SVC 4000"
对于成员 1:
db2 "UPDATE DB CFG FOR sampledb MEMBER 1 USING HADR_LOCAL_HOST psnode2-primay HADR_LOCAL_SVC 4000"

5、在备用数据库上,DBA 设置集群级别的 HADR 参数,这些参数指定主集群和同步方式
db2 "UPDATE DB CFG FOR sampledb USING\
HADR_TARGET_LIST  {psnode1-primay:4000|psnode2-primay:4000}\
HADR_REMOTE_HOST  {psnode1-primay:4000|psnode2-primay:4000}\
HADR_REMOTE_INST  db2inst1\
HADR_SYNCMODE     async"

6、DBA 在备用数据库上设置成员级别 HADR 参数,这些参数标识每个成员的地址和端口:
对于成员 0:
db2 "UPDATE DB CFG FOR sampledb MEMBER 0 USING HADR_LOCAL_HOST psnode1-standby HADR_LOCAL_SVC 4000"
对于成员 1:
db2 "UPDATE DB CFG FOR sampledb MEMBER 1 USING HADR_LOCAL_HOST psnode2-standby HADR_LOCAL_SVC 4000"
       
7、启动备库
db2 START HADR ON DB sampledb AS STANDBY

db2sdin1@psnode1:/gpfs1nsd/backup> db2 START HADR ON DB sampledb AS STANDBY
SQL1766W  The command completed successfully. However, LOGINDEXBUILD was not
enabled before HADR was started.

8、启动主库
db2 START HADR ON DB sampledb AS PRIMARY

db2inst1@psnode2:/gpfs1nsd/backup> db2 START HADR ON DB sampledb AS PRIMARY
SQL1766W  The command completed successfully. However, LOGINDEXBUILD was not
enabled before HADR was started.

9、检查HADR

db2 "select LOG_STREAM_ID, PRIMARY_MEMBER, STANDBY_MEMBER, HADR_STATE from table (mon_get_hadr(-2))"
LOG_STREAM_ID PRIMARY_MEMBER STANDBY_MEMBER HADR_STATE            
------------- -------------- -------------- -----------------------
           1              1              0 PEER                  
           0              0              0 PEER                  

 2 record(s) selected.

db2pd -d sampledb -hadr
db2 get db cfg for sampledb | grep -i hadr

#####角色切换####



1、DBA 确保主项上成员均不处于异常状态:

db2inst1@psnode1:~> db2 "SELECT ID,varchar(STATE,21) AS STATE,varchar(HOME_HOST,10) AS HOME_HOST, varchar(CURRENT_HOST,10) AS CUR_HOST, ALERT FROM SYSIBMADM.DB2_MEMBER"

ID     STATE                 HOME_HOST  CUR_HOST   ALERT  
------ --------------------- ---------- ---------- --------
    0 STARTED               psnode1    psnode1    NO    
    1 STARTED               psnode2    psnode2    NO    

 2 record(s) selected.

2、DBA 确保所有日志流处于 PEER 状态:
db2inst1@psnode1:~> db2 "select LOG_STREAM_ID, PRIMARY_MEMBER, STANDBY_MEMBER, HADR_STATE from table (mon_get_hadr(-2))"

LOG_STREAM_ID PRIMARY_MEMBER STANDBY_MEMBER HADR_STATE            
------------- -------------- -------------- -----------------------
           1              1              0 PEER                  
           0              0              0 PEER                  

 2 record(s) selected.


3、在standby,DBA 对成员 0 发出 TAKEOVER HADR 命令:
db2sdin1@psnode1:~> db2 TAKEOVER HADR ON DB sampledb
DB20000I  The TAKEOVER HADR ON DATABASE command completed successfully.

4、在primary,DBA 在备用项上停用数据库(这使数据库保持处于 HADR 备用项的角色):
db2 DEACTIVATE DATABASE sampledb
db2stop
执行维护操作
db2start
db2 activate database sampledb


5、在primary,执行切换命令
db2 TAKEOVER HADR ON DB sampledb

以上是“DB2_PureScale环境HADR如何搭建”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI