postgresql 订阅不适用于 public 以外的模式
postgresql subscription not working for schemas other than public
我正在尝试使用两个本地 postgresql 服务器(节点 1:端口 5434,节点 2:端口 5435)创建逻辑复制。
我可以在 node1 和 node2 上为 public 模式中的 table 成功创建 publication 和订阅。
节点 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.
中的所有数据
但是,我的问题是当我使用相同的代码但在不同的模式中创建 publication 和订阅时,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模式的两个订阅处于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*/
订阅者似乎没有权限读取发布者中的 cdl 架构,即使在我授予 SELECT ON cdl.t1 TO repuser;
权限后也是如此。
您必须授予用户 repuser
读取应复制的 table 的权限。这还需要对包含 table.
的架构的 USAGE
权限
我正在尝试使用两个本地 postgresql 服务器(节点 1:端口 5434,节点 2:端口 5435)创建逻辑复制。
我可以在 node1 和 node2 上为 public 模式中的 table 成功创建 publication 和订阅。
节点 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.
中的所有数据但是,我的问题是当我使用相同的代码但在不同的模式中创建 publication 和订阅时,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模式的两个订阅处于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*/
订阅者似乎没有权限读取发布者中的 cdl 架构,即使在我授予 SELECT ON cdl.t1 TO repuser;
权限后也是如此。
您必须授予用户 repuser
读取应复制的 table 的权限。这还需要对包含 table.
USAGE
权限