注意:
1、9.5以上版本才支持
2、编译安装参考https://www.2ndquadrant.com/en/resources/pglogical/pglogical-installation-instructions/
3、如何使用参考https://www.2ndquadrant.com/en/resources/pglogical/pglogical-docs/,
中文参考https://my.oschina.net/innovation/blog/748227
4、本教程支持pg自身的流复制主备模式,pglogical是hotstanby的流复制高级模式
5、订阅服务器版本要和提供者版本一样,且都要安装pglogical
一、安装pglogical
由于我们pg都是源码安装,那么pglogical也是源码安装
去官网https://www.2ndquadrant.com下载源码包,比较难找,慢慢找
安装需要pg_config,由于我们pg安装完环境变量是配置在postgres用户根目录下的.bash_profile里面,在root用户下需要source /home/postgres/.bash_profile加载下环境变量
解压后执行
make USE_PGXS=1
make USE_PGXS=1 install
二、配置pglogical
1、PG配置
如果是主备模式,两个都得修改,记得重启服务
wal_level = 'logical'
max_worker_processes = 10 # one per database needed on provider node
# one per node needed on subscriber node
max_replication_slots = 10 # one per node needed on provider node
max_wal_senders = 10 # one per node needed on provider node
shared_preload_libraries = 'pglogical'
track_commit_timestamp = on # needed for last/first update wins conflict resolution
# property available in PostgreSQL 9.5+
2、配置逻辑复制
提供者执行以下命令,当然首先要确认数据库和用户,命令\c dbname user
CREATE EXTENSION pglogical;
SELECT pglogical.create_node('provider1','host=192.168.180.222 port=5433 dbname=elink');
SELECT pglogical.replication_set_add_table('default','company','true',NULL,NULL);
#default是复制表的所有操作,company是表名
订阅者执行以下命令
select pglogical.create_node('sub_node_1','host=192.168.180.222 port=5433 dbname=elink');
select pglogical.create_subscription('sub1','host=192.168.180.222 port=5433 dbname=elink user=elink password=elink');
三、评估结果
刚刚从bdr改过来,各种BUG、报错很多,用的人也少暂时不考虑了