postgresql 如何删除 postgres 9.4 中的复制槽

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30854961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:00:40  来源:igfitidea点击:

How to delete replication slot in postgres 9.4

postgresqlreplicationpostgresql-9.4

提问by Igor Barinov

I have replication slot which I want to delete but when I do delete I got an error that I can't delete from view. Any ideas?

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

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

回答by Craig Ringer

Use pg_drop_replication_slot:

使用pg_drop_replication_slot

select pg_drop_replication_slot('bottledwater');

See the docsand this blog.

请参阅文档此博客

The replication slot must be inactive, i.e. no active connections. So if there's a streaming replica using the slot you must stop the streaming replica. Or you can change its recovery.confso it doesn't use a slot anymore and restart it.

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

回答by Yann Vo

As a complement to the accepted answer, I'd like to mention that following command will not fail in case the slot does not exist (this was useful for me because I scripted that).

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

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