加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql异步流复制搭建

发布时间:2020-12-13 17:02:07 所属栏目:百科 来源:网络整理
导读:节点 IP 角色 citus-master 10.10.100.1 master citus-standby 10.10.100.2 standby master上创建流复制所需要的用户。 CREATEROLEreplicationWITHREPLICATIONPASSWORD'replication'LOGIN; 修改master的pg_hba.conf文件,设置replication用户远程访问权限 ##
节点 IP 角色
citus-master 10.10.100.1 master
citus-standby 10.10.100.2 standby

master上创建流复制所需要的用户。

CREATEROLEreplicationWITHREPLICATIONPASSWORD'replication'LOGIN;

修改master的pg_hba.conf文件,设置replication用户远程访问权限

##vim/data/pgsql/data/pg_hba.conf,追加下面一行
hostreplicationreplication10.10.0.0/16md5

master上设置与复制相关的参数

wal_level=hot_standby
max_wal_senders=5
wal_keep_segments=32

master上重启pgsql

/etc/init.d/postgresql-9.5restart

standby上使用pg_basebackup对master做一次全备并将备份拉到standby上来

pg_basebackup-h10.10.100.1-D/var/lib/pgsql/9.5/data/-P-Ureplication-R--xlog-method=stream

修改standby节点上的postgresql.conf文件,设置备库为standby的状态

##vim/data/pgsql/data/postgresql.conf
hot_standby=on

修改standby的recovery.conf文件,设置master节点的同步信息及trigger文件

standby_mode='on'
primary_conninfo='user=replicationpassword=replicationhost=10.10.100.1port=5432sslmode=prefersslcompression=1krbsrvname=postgres'
trigger_file='/data/pgsql/data/postgresql.trigger.1973'

standby上重启pgsql

/etc/init.d/postgresql-9.5restart

可以在master上创建一张测试表并插入数据,来验证standby上是否同步过来数据。当master挂掉之后,在standby上创建trigger_file参数声明的文件,就会触发standby的激活,会自动把standby提升为master。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读