Skip to content

Instantly share code, notes, and snippets.

@ichux
Created September 18, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichux/b882a9cccf0eb21bbf6b87c8fc7c2913 to your computer and use it in GitHub Desktop.
Save ichux/b882a9cccf0eb21bbf6b87c8fc7c2913 to your computer and use it in GitHub Desktop.
Drop DB in Postgres
-- Terminate any existing connections to `thedb`
SELECT
pg_terminate_backend(pg_stat_activity.pid)
FROM
pg_stat_activity
WHERE
pg_stat_activity.datname = 'thedb'
AND pid <> pg_backend_pid();
-- Now go ahead and drop the database, `thedb`
DROP DATABASE thedb;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment