Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete replication slot in postgres 9.4

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=# 
like image 764
Igor Barinov Avatar asked Jun 15 '15 21:06

Igor Barinov


People also ask

How do I drop active replication slot?

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.

What is PostgreSQL replication slot?

A replication slot is a feature in PostgreSQL that ensures that the master server will retain the WAL logs that are needed by the replicas even when they are disconnected from the master.

Why is replication slot inactive?

Inactive Replication Slots Often inactive replication slots are the result of a backup client that was removed, a slave that was taken down, promotions, failovers and the like.


1 Answers

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.

like image 198
Craig Ringer Avatar answered Oct 01 '22 17:10

Craig Ringer