我正在尝试使用两个本地 postgresql 服务器(node1:端口 5434,node2:端口 5435)创建逻辑复制。
我可以成功地在 node1 和 node2 上为公共模式中的表创建发布和订阅。
节点1:
CREATE PUBLICATION my_pub FOR TABLE t1;
GRANT SELECT ON t1 TO repuser;
节点2:
CREATE SUBSCRIPTION my_sub CONNECTION 'host=localhost port=5434 dbname=pub user=repuser password=password' PUBLICATION my_pub;
Node2 public.t1 复制 node1 public.t1 中的所有数据。
但是,我的问题是当我使用相同的代码但在不同的模式中创建发布和订阅时,node2 无法复制。
下面是一些 pg_catalog 查询的输出:
节点1:
pub=# select * from pg_catalog.pg_publication_tables;
pubname | schemaname | tablename
----------+------------+-----------
my_pub | public | t1
cdl_test | cdl | t1
pub_test | test | t1
节点2:
sub=# \dRs
List of subscriptions
Name | Owner | Enabled | Publication
--------------+----------+---------+-------------
cdl_sub_test | postgres | t | {cdl_test}
my_sub | postgres | t | {my_pub}
sub_test | postgres | t | {pub_test}
sub=# select * from pg_catalog.pg_replication_origin;
roident | roname
---------+----------
2 | pg_18460
1 | pg_18461
3 | pg_18466
sub=# select * from pg_catalog.pg_subscription_rel ;
srsubid | srrelid | srsubstate | srsublsn
---------+---------+------------+------------
18461 | 16386 | r | 0/3811C810
18466 | 18463 | d |
18460 | 18456 | d |
如图所示select * from pg_catalog.pg_subscription_rel
,两个订阅 test 和 cdl schema 处于d(data is being copied)
状态。
关于如何解决此问题或诊断问题发生原因的任何建议?
正如 jjanes 所建议的,日志文件的片段如下所示:
2022-01-17 16:05:25.165 PST [622] WARNING: out of logical replication worker slots
2022-01-17 16:05:25.165 PST [622] HINT: You might need to increase max_logical_replication_workers.
2022-01-17 16:05:25.168 PST [970] LOG: logical replication table synchronization worker for subscription "cdl_sub_test", table "t1" has started
2022-01-17 16:05:25.245 PST [970] ERROR: could not start initial contents copy for table "cdl.t1": ERROR: permission denied for schema cdl
2022-01-17 16:05:25.247 PST [471] LOG: background worker "logical replication worker" (PID 970) exited with exit code 12022-01-17 16:05:25.797 PST [488] postgres@sub LOG: statement: /*pga4dash*/
即使在我授予SELECT ON cdl.t1 TO repuser;
.