如何在 postgres 9.4 中删除复制槽

Posted

技术标签:

【中文标题】如何在 postgres 9.4 中删除复制槽【英文标题】:How to delete replication slot in postgres 9.4 【发布时间】:2015-08-31 12:38:29 【问题描述】:

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

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(slot_name name) postgresql.org/docs/9.4/static/… 但是当我做 postgres=# select * from pg_drop_replication_slot('bottledwater');我得到了错误:复制槽“瓶装水”已经处于活动状态 【参考方案1】:

使用pg_drop_replication_slot:

select pg_drop_replication_slot('bottledwater');

参见the docs 和this blog。

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

【讨论】:

嗯...博客的链接似乎没有了。 博客文章现在可以在这里找到:paquier.xyz/postgresql-2/… 我也不能放在主服务器上...错误是错误:复制槽不存在 select * from pg_replication_slots 什么都不返回。【参考方案2】:

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

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

【讨论】:

以上是关于如何在 postgres 9.4 中删除复制槽的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Postgres 9.4 中对 JSONB 类型的列执行更新操作

如何从 Postgres 9.4 中转储大对象数据,然后将其导入 Postgres8.x?

在 Postgres 9.4+ 中索引 JSONB 嵌入式 Ecto2 模型

Postgres 使用 debezium 创建复制槽失败

从 Mac 中删除旧的 Postgres 版本 [重复]

Postgres如何创建一个在查询中使用的函数