postgresql异步流复制搭建

前端之家收集整理的这篇文章主要介绍了postgresql异步流复制搭建前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
节点 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。

原文链接:https://www.f2er.com/postgresql/194306.html

猜你在找的Postgre SQL相关文章