我是PostgreSQL逻辑复制的新手。
我进行了测试,当我向发布中添加一个新表后,我发现复制不起作用,直到我重新创建订阅,我确定重新创建订阅不是最佳实践,请问如何使订阅者应用新表的事务?
以下是测试内容:
Create the first table on primary and replicate side:
create table rep_test (a int primary key, b int);
Create publication on primary side:
CREATE PUBLICATION rep_test_pub FOR table public.rep_test;
Create subscription on replicate side:
CREATE SUBSCRIPTION rep_test_sub CONNECTION 'host=XXX port=5432 dbname=rocket user=XXX password=XXX' PUBLICATION rep_test_pub WITH (copy_data = false);
Test the replication, the replication works. Primary side:
insert into rep_test values (1, 1); insert into rep_test values (2, 1);
Replicate:
select * from rep_test; *---*---* | a | b | *---*---* | 1 | 1 | | 2 | 1 | *---*---*
Create a new table on both primary and replicate side
create table rep_test (a int primary key, b text);
Add new table to publication on primary side
alter publication rep_test_pub add table public.rep_test2;
Test the replication, the replication is not working. Primary:
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)
重新创建订阅后,复制功能将正常工作。
请问是否有其他方法可以使订阅者将事务应用于新表?
顺便提一下,我的版本是:
PostgreSQL 12.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
谢谢!