从逻辑复制切换到流复制后无法从 table 中删除

Can't delete from table after switch from logical to streaming replication

在我的 DEV 服务器上,我测试了逻辑复制,然后 return 进行了流式传输。

现在wal_level = replica并且我有两个slave:

pid  |state     |application_name    |client_addr|write_lag      |flush_lag      |replay_lag     |sync_priority|sync_state|
-----|----------|--------------------|-----------|---------------|---------------|---------------|-------------|----------|
12811|streaming |db-slave1           |*.*.*.*    |00:00:00.000569|00:00:00.001914|00:00:00.001932|            0|async     |
25978|streaming |db-slave2           |*.*.*.*    |00:00:00.000568|00:00:00.001913|00:00:00.001931|            0|async     |

现在我创建了新的 table 并插入了一条记录。例如:

create table test_delete (
    id int
);

insert into test_delete values (1);

delete from test_delete where id = 1;

table 创建并复制到两个从站,但删除查询失败并出现错误:

SQL Error [55000]: ERROR: cannot delete from table "test_delete" because it does not have a replica identity and publishes deletes Hint: To enable deleting from the table, set REPLICA IDENTITY using ALTER TABLE.

所以,我需要帮助在切换逻辑复制之前恢复状态并能够从 tables

中删除

经过一番调查,我找到了解决方案。尽管 wal_level 在 postgres.conf 中发生了变化,所有表格仍然出现在 pg_publication_tables 中。 因此,要检查发布状态,请使用:

select * from pg_publication_tables;

并删除记录:

drop publication <publication_name>;