【发布时间】:2020-06-17 12:04:59
【问题描述】:
我是 PostgreSQL 逻辑复制的新手。 我做了测试,在将新表添加到发布后,我发现复制不起作用,直到我重新创建订阅,我确信重新创建订阅不是最佳做法,请您告知如何制作订阅者为新表申请事务?
测试如下:
-
在主端和复制端创建第一个表:
create table rep_test (a int primary key, b int); -
在主端创建发布:
CREATE PUBLICATION rep_test_pub FOR table public.rep_test; -
在复制端创建订阅:
CREATE SUBSCRIPTION rep_test_sub CONNECTION 'host=XXX port=5432 dbname=rocket user=XXX password=XXX' PUBLICATION rep_test_pub WITH (copy_data = false); -
测试复制,复制有效。 初级:
insert into rep_test values (1, 1); insert into rep_test values (2, 1);复制:
select * from rep_test; *---*---* | a | b | *---*---* | 1 | 1 | | 2 | 1 | *---*---* -
在主端和复制端都创建一个新表
create table rep_test (a int primary key, b text); -
将新表添加到主端的发布
alter publication rep_test_pub add table public.rep_test2; -
测试复制,复制不工作。 主要:
insert into rep_test values (3, 1); insert into rep_test2 values (1,'text');
复制:
select * from rep_test;
*---*---*
| a | b |
*---*---*
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
*---*---*
select * from rep_test2;
注意:rep_test2 中没有数据,复制没有复制rep_test2。
-
重新启动复制 postgres,复制仍然无法正常工作。
-
删除并重新创建订阅,复制工作。
初级:
truncate table rep_test; truncate table rep_test2;
复制:
drop subscription rep_test_sub;
CREATE SUBSCRIPTION rep_test_sub CONNECTION 'host=XXX port=5432 dbname=rocket user=XXX password=XXX' PUBLICATION rep_test_pub WITH (copy_data = false);
初级:
insert into rep_test values (1, 1); insert into rep_test2 values (1, 'text');
复制:
select * from rep_test;select * from rep_test2;
*---*---*
| a | b |
*---*---*
| 1 | 1 |
*---*---*
(1 row)
*---*-----*
| a | b |
*---*-----*
| 1 | text|
*---*-----*
(1 row)
重新创建订阅后复制工作。
您能否告知是否有另一种方法可以让订阅者将事务应用到新表?
顺便说一句,我的版本:
x86_64-pc-linux-gnu 上的 PostgreSQL 12.2,由 gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39) 编译,64 位
谢谢
【问题讨论】:
标签: postgresql subscription logical-replication