Skip to content

Instantly share code, notes, and snippets.

@wriglz
Last active January 9, 2020 14:41
Show Gist options
  • Save wriglz/15ea018f4124546d9d1b9863443051d2 to your computer and use it in GitHub Desktop.
Save wriglz/15ea018f4124546d9d1b9863443051d2 to your computer and use it in GitHub Desktop.
Drop all connections to a Postgres database so you can drop the DB. Make sure you are not currently connected to the database that you wish to drop!
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB' -- ← change this to your DB
AND pid <> pg_backend_pid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment