DROP_SUBSCRIPTION(7pg13)

πŸ“¦ version 13.23, in opensuse-leap 16.0

πŸ’… DROP_SUBSCRIPTION β€” bestie's guide to yeeting a subscription ✨

okay so real talk, this is the DROP_SUBSCRIPTION page from the PostgreSQL 13.23 docs, and it's literally about removing a subscription from the database cluster. iconic, lowkey destructive, we love a clean exit πŸŽ€


✨ SYNOPSIS ✨

DROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ]

that's it. that's the whole vibe check πŸ¦‹


πŸ’– DESCRIPTION πŸ’–

DROP SUBSCRIPTION removes a subscription from the database cluster. bye bestie πŸ‘‹

not everyone can do this, though β€” a subscription can only be dropped by a superuser. so if you're not one, this is not your main character moment, sorry 😭

also, important: DROP SUBSCRIPTION cannot be executed inside a transaction block if the subscription is associated with a replication slot. ngl that's a whole thing. (good news though β€” you can use ALTER SUBSCRIPTION to unset the slot.) πŸ™ˆ


🌸 PARAMETERS 🌸

  • name β€” the name of the subscription you're dropping. the one getting yeeted. πŸ’€
  • CASCADE, RESTRICT β€” okay so these key words literally do not have any effect, because there are no dependencies on subscriptions. they're just... there. decorative. furniture. πŸ›‹οΈβœ¨

🧚 NOTES 🧚

okay this part is the important one, pay attention πŸ’…

when you drop a subscription that's associated with a replication slot on the remote host (which is the normal state, iykyk), DROP SUBSCRIPTION will connect to the remote host and try to drop the replication slot as part of its operation. why? because the resources allocated for the subscription on the remote host need to be released. slay, responsible queen πŸ”₯

but here's the catch β€” if that fails, DROP SUBSCRIPTION will fail too. and it can fail for a few reasons:

  • the remote host is not reachable 😭
  • the remote replication slot cannot be dropped
  • the remote replication slot does not exist
  • the remote replication slot never existed
to proceed in this situation, first disable the subscription by executing ALTER SUBSCRIPTION ... DISABLE, and then disassociate it from the replication slot by executing ALTER SUBSCRIPTION ... SET (slot_name = NONE). after that, DROP SUBSCRIPTION will no longer attempt any actions on a remote host. 🫢

and β€” huge caveat, do not skip this β€” note that if the remote replication slot still exists, it should then be dropped manually; otherwise it will continue to reserve WAL and might eventually cause the disk to fill up. like, disk full. the worst kind of plot twist πŸ’€ see also Section 30.2.1.

also, 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. ⭐


πŸŽ€ EXAMPLES πŸŽ€

drop a subscription, simple as:

DROP SUBSCRIPTION mysub;

and that's the whole flex ✨


πŸ‘‘ COMPATIBILITY πŸ‘‘

DROP SUBSCRIPTION is a PostgreSQL extension. not standard SQL, it's our thing πŸ’œ


🌈 SEE ALSO 🌈


and that's the page!! go forth and drop responsibly, bestie πŸ¦‹πŸ“

PostgreSQL 13.23 Β· 2025 Β· DROP SUBSCRIPTION(7) β€” mwah, love u, see u in the next manpage πŸ’–

πŸ“¦ where this page comes from