Skip to content

Instantly share code, notes, and snippets.

@prosoftwaredev
Last active May 9, 2018 19:44
Show Gist options
  • Save prosoftwaredev/ae2050f464693b94c6f36e27b962423f to your computer and use it in GitHub Desktop.
Save prosoftwaredev/ae2050f464693b94c6f36e27b962423f to your computer and use it in GitHub Desktop.
How to drop a PostgreSQL database if there are active connections to it?
sudo -u postgres psql postgres
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'DB NAME' AND pid <> pg_backend_pid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment