PostgreSQL:基本的pglogical配置有困难

时间:2016-10-31 15:55:20

标签: postgresql replication

我发现official pglogical documentation非常混乱。有太多东西不清楚。也许之前配置过pglogical的人可以解释如何设置基本的逻辑复制。

有两个PostgreSQL 9.5实例--10.128.0.8(archlinux1)和10.128.0.9(archlinux2)。扩展已安装,CREATE EXTENSION成功。每个实例都有一个表格:

create table test (k text primary key, v text);

我想将它从archlinux1复制到archlinux2。

根据文档,我应该创建一个提供者节点:

SELECT pglogical.create_node(
    node_name := 'provider1',
    dsn := 'host=providerhost port=5432 dbname=db'
);

它应该在主人身上执行吗? providerhost应该是127.0.0.1还是10.128.0.8?只允许从localhost(相应于文档)进行Currenlty复制 - 是否应该更改?我最好的猜测 - 它应该像这样在主人身上执行:

SELECT pglogical.create_node(
    node_name := 'provider1',
    dsn := 'host=127.0.0.1 port=5432 dbname=eax'
);
 create_node 
-------------
  2976894835
(1 row)

下一步:

SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);

是应该在master,replica还是两者上执行?我最好的猜测 - 只有主人:

SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);
 replication_set_add_all_tables 
--------------------------------
 t
(1 row)

下一步:

SELECT pglogical.create_node(
    node_name := 'subscriber1',
    dsn := 'host=thishost port=5432 dbname=db'
);

显然它应该在副本上执行:

SELECT pglogical.create_node(
    node_name := 'subscriber1',
    dsn := 'host=127.0.0.1 port=5432 dbname=eax'
);
 create_node 
-------------
   330520249
(1 row)

下一步:

SELECT pglogical.create_subscription(
    subscription_name := 'subscription1',
    provider_dsn := 'host=providerhost port=5432 dbname=db'
);

最佳猜测 - 在副本上执行它:

SELECT pglogical.create_subscription(
    subscription_name := 'subscription1',
    provider_dsn := 'host=10.128.0.8 port=5432 dbname=eax'
);
ERROR:  could not connect to the postgresql server: could not connect to server: Connection refused
    Is the server running on host "10.128.0.8" and accepting
    TCP/IP connections on port 5432?

DETAIL:  dsn was:  host=10.128.0.8 port=5432 dbname=eax

糟糕。好的,在master上正确修改pg_hba.conf和postgresql.conf:

# pg_hba.conf
host    all    all    10.128.0.0/16    md5
# postgresql.conf
listen_addresses = 'localhost,10.128.0.8

仍然没有运气:

# SELECT pglogical.create_subscription(
    subscription_name := 'subscription1',
    provider_dsn := 'host=10.128.0.8 port=5432 dbname=eax user=eax password=qwerty'
);
ERROR:  could not connect to the postgresql server in replication mode: FATAL:  no pg_hba.conf entry for replication connection from host "10.128.0.9", user "eax", SSL off

DETAIL:  dsn was:  host=10.128.0.8 port=5432 dbname=eax user=eax password=qwerty

在master上添加到pg_hba.conf:

host    replication     eax        10.128.0.0/16            md5

复制品(成功!):

SELECT pglogical.create_subscription(
    subscription_name := 'subscription1',
    provider_dsn := 'host=10.128.0.8 port=5432 dbname=eax user=eax password=qwerty'
);
 create_subscription 
---------------------
          1763399739
(1 row)

现在主人:

eax=# insert into test values ('aaa', 'bbb');
INSERT 0 1
eax=# select * from test;
  k  |  v  
-----+-----
 aaa | bbb
(1 row)

在副本上:

eax=# select * from test;
 k | v 
---+---
(0 rows)

当然它不起作用。在日志中没有任何帮助。有什么建议吗?

UPD:我还在pglogical问题跟踪器中创建了corresponding issue

3 个答案:

答案 0 :(得分:1)

也许这是一个更好的指南:http://bonesmoses.org/2016/10/14/pg-phriday-perfectly-logical/ - 至少它会告诉你执行每个命令的节点。

答案 1 :(得分:0)

Depesz发表了一篇关于pglogical配置https://www.depesz.com/2016/11/08/major-version-upgrading-with-minimal-downtime/

的优秀博客文章

答案 2 :(得分:0)

创建节点时,您需要指定一个外部IP(不是本地主机)

提供者

SELECT pglogical.create_node(
node_name := 'provider1',
dsn := 'host=subscriberhost port=5432 dbname=db'
);

订户

SELECT pglogical.create_node(
node_name := 'subscriber1',
dsn := 'host=providerhost port=5432 dbname=eax'
);