如何删除 postgres 9.4 中的复制槽

How to delete replication slot in postgres 9.4

我有一个我想删除的复制槽,但是当我删除时,我收到了一个错误,我无法从视图中删除。有什么想法吗?

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=#

使用pg_drop_replication_slot:

select pg_drop_replication_slot('bottledwater');

the docs and this blog

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

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

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