如何在Postgres 9.4中删除复制插槽

58

我有一个复制插槽,想要删除它,但是当我尝试删除时,却收到了一个错误提示,说我不能从视图中删除。有什么想法吗?

postgres=# SELECT * FROM pg_replication_slots ;
  slot_name   |    plugin    | slot_type | datoid | database | active | xmin | catalog_xmin | restart_lsn
--------------+--------------+-----------+--------+----------+--------+------+--------------+-------------
 bottledwater | bottledwater | logical   |  12141 | postgres | t      |      |       374036 | E/FE8D9010
(1 row)

postgres=# delete from pg_replication_slots;
ERROR:  cannot delete from view "pg_replication_slots"
DETAIL:  Views that do not select from a single table or view are not automatically updatable.
HINT:  To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.
postgres=#

2
我发现了命令pg_drop_replication_slot(slot_name name) http://www.postgresql.org/docs/9.4/static/functions-admin.html#FUNCTIONS-REPLICATION,但是当我执行postgres=# select * from pg_drop_replication_slot('bottledwater');时,我得到了错误:复制槽“bottledwater”已经处于活动状态。 - Igor Barinov
2个回答

112

使用pg_drop_replication_slot

select pg_drop_replication_slot('bottledwater');

请参阅文档此博客

复制插槽必须处于非活动状态,即没有活动连接。因此,如果有一个使用插槽的流式复制副本,您必须停止流式复制副本。或者您可以更改其recovery.conf,使其不再使用插槽并重新启动它。


嗯...博客的链接似乎已经失效了。 - neouser99
博客文章现在可以在这里找到:http://paquier.xyz/postgresql-2/postgres-9-4-feature-highlight-replication-phydical-slots/ - Drew Bloechl
我也无法在主服务器上删除...错误提示为“ERROR: replication slot does not exist”,执行“select * from pg_replication_slots”命令返回空值。 - Luciano Andress Martini

31

作为对已接受的答案的补充,我想提醒一下,以下命令如果该插槽不存在不会失败(这对我很有用,因为我正在编写脚本)。

select pg_drop_replication_slot(slot_name) from pg_replication_slots where slot_name = 'bottledwater';

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接