Skip to content

Instantly share code, notes, and snippets.

@mladenp
Created January 18, 2018 01:16
Show Gist options
  • Save mladenp/091b6c90a13d14f0217f72fe5cc1ed6a to your computer and use it in GitHub Desktop.
Save mladenp/091b6c90a13d14f0217f72fe5cc1ed6a to your computer and use it in GitHub Desktop.
Postgres DROP db - right way
/* Disable connection to Database */
UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'mydb';
/* Get postgres process id */
SELECT pg_backend_pid();
/* Force Disconnect all clients ( use pid from previous step) */
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'mydb';
/* Finaly Drop database */
DROP DATABASE mydb;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment