docker下centos7安装postgresql搭建主从同步

2017-11-21  本文已影响538人  只有香如故

docker下创建centos7 容器

install postgresql

postgresl install
yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm -- 下载rpm
yum install postgresql96 -- install client
yum install postgresql96-server postgresqyl96-contrib -- install sderver和第三方插件
/usr/pgsql-9.6/bin/postgresql96-setup initdb -- 初始化数据库
systemctl enable postgresql-9.6 --开机自启
systemctl start postgresql-9.6 -- 启动服务
passwd postgres -- 修改postgres password
create database testduliyan;--create database
create user super2 with superuser password '34567';
\c testduliyan --切换数据库
create table duliyan(id int primary key , name varchar(50));

install pglogical

下载地址
yum install pglogical-rhel-1.0-3.noarch.rpm
yum install postgresql96-pglogical

修改配置文件postgresql.conf

listen_addresses ='*'
port=5432
password_encryption = on
wal_level = 'logical'
max_worker_processes = 10 # one per database needed on provider 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'

修改pg_hba.conf

host all all 0.0.0.0/0 md5.
local replication super1 trust
host replication super1 127.0.0.1/32 trust
host replication super1 ::1/128 trust
host replication super1 0.0.0.0/0 trust

创建节点

参考网站
psql -U super1 -h 127.0.0.1 -d testduliyan -W -- login db
CREATE EXTENSION pglogical; -- create 扩展工具
select extname, extowner from pg_extension;

测试

provider
insert into duliyan values(1,'aa') ;
subscriber
select * from duliyan;
subscriber 有数据,同步成功

注意: pglogical设置的表必须包含主键或者unique key。

上一篇 下一篇

猜你喜欢

热点阅读