DROP_SUBSCRIPTION(7pg18)
โจ DROP_SUBSCRIPTION โจ
okay bestie, welcome to the DROP_SUBSCRIPTION page of the PostgreSQL 18.6 Documentation ๐ this is the manual for yeeting a subscription and honestly it's giving "cleanup era" ๐
๐ฆ NAME ๐ฆ
DROP_SUBSCRIPTION โ remove a subscription ๐๏ธโจ
๐ SYNOPSIS ๐
DROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ]
that's it, that's the whole vibe check ๐ซถ
๐ DESCRIPTION ๐
So DROP_SUBSCRIPTION removes a subscription from the database cluster. bye girl ๐๐
To actually run this command, you must be the owner of the subscription. no borrowing, no sneaking in, it's yours or it's not happening ๐
๐จ Important:DROP_SUBSCRIPTIONcannot be executed inside a transaction block if the subscription is associated with a replication slot. (You can useALTER SUBSCRIPTIONto unset the slot โ more on that below bestie ๐ซถ)
๐ธ PARAMETERS ๐ธ
IF EXISTSโ do not throw an error if the subscription does not exist. A notice is issued in this case. so like, no dramatic meltdown if it's already gone ๐โจnameโ the name of a subscription to be dropped. literally just tell it which one, bestie ๐ฏCASCADEandRESTRICTโ these key words do not have any effect, since there are no dependencies on subscriptions. iconic behaviour honestly, they just sit there looking pretty ๐ no cap, zero effect fr fr.
๐ฅ NOTES ๐ฅ
okay this is the part you actually need to read, don't scroll past it ๐
When you drop a subscription that's associated with a replication slot on the remote host (the normal state), DROP_SUBSCRIPTION will connect to the remote host and try to drop the replication slot (and any remaining table synchronization slots) as part of its operation. this is necessary so that the resources allocated for the subscription on the remote host are released. it's giving "responsible adult" energy, we love to see it ๐ซถ
If this fails โ either because the remote host is not reachable, or because the remote replication slot cannot be dropped, or does not exist, or never existed โ the DROP_SUBSCRIPTION command will fail. ๐ญ
To proceed in this situation, do this lil two-step:
- first disable the subscription by executing
ALTER SUBSCRIPTION ... DISABLE - then disassociate it from the replication slot by executing
ALTER SUBSCRIPTION ... SET (slot_name = NONE)
After that, DROP_SUBSCRIPTION will not attempt to drop the subscription's own replication slot. It may still connect to the publisher to drop internally-created table synchronization slots if some table synchronization is left unfinished; if the publisher is unreachable, those slots (and the main slot, if it still exists) must be dropped manually.
๐ Otherwise it/they will continue to reserve WAL and might eventually cause the disk to fill up. bestie. BESTIE. do not let your disk fill up. that is not the vibe. ๐ญ๐ฅ
See also Section 29.2.1. ๐
And one more time for the people in the back:
๐จ If a subscription is associated with a replication slot, then DROP_SUBSCRIPTION cannot be executed inside a transaction block. periodt. ๐
๐ EXAMPLES ๐
Drop a subscription:
DROP SUBSCRIPTION mysub;
slay, gone, deleted, no more, we stan a clean exit โจ
๐ซ COMPATIBILITY ๐ซ
DROP_SUBSCRIPTION is a PostgreSQL extension. it's our thing, iykyk ๐
๐ SEE ALSO ๐
CREATE SUBSCRIPTION(CREATE_SUBSCRIPTION(7)) โ the origin story ๐ฃALTER SUBSCRIPTION(ALTER_SUBSCRIPTION(7)) โ your bestie when you need to disable or unset the slot ๐ซถ
and that's the whole page!! mwah ๐ this was the DROP_SUBSCRIPTION(7) man page from PostgreSQL 18.6, dated 2026. go forth and drop responsibly bestie, and remember: the replication slot does NOT drop itself ๐ธ๐ฆ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms