How to delete replication slot in postgres 9.4
Asked Answered
C

2

62

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=#
Cockcrow answered 15/6, 2015 at 21:5 Comment(1)
I found command pg_drop_replication_slot(slot_name name) postgresql.org/docs/9.4/static/… but when I do postgres=# select * from pg_drop_replication_slot('bottledwater'); I got ERROR: replication slot "bottledwater" is already activeCockcrow
T
120

Use pg_drop_replication_slot:

select pg_drop_replication_slot('bottledwater');

See the docs and 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.conf so it doesn't use a slot anymore and restart it.

Tulle answered 16/6, 2015 at 0:27 Comment(3)
humm... the link to the blog appears to be no more.Trivalent
The blog post can now be found here: paquier.xyz/postgresql-2/…Bigley
I cant drop on the primary too... the error is that ERROR: replication slot does not exist select * from pg_replication_slots returns nothing.Gammer
A
32

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';
Aide answered 14/6, 2019 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.