Skip to content

Instantly share code, notes, and snippets.

@biske
Last active August 29, 2015 14:05
Show Gist options
  • Save biske/6bf1e3a02e188850bcd6 to your computer and use it in GitHub Desktop.
Save biske/6bf1e3a02e188850bcd6 to your computer and use it in GitHub Desktop.
-- To mark database 'applogs' as not accepting new connections:
update pg_database set datallowconn = false where datname = 'TARGET_DB';
/* Query pg_stat_activity and get the pid values you want to kill,
then issue SELECT pg_terminate_backend(pid int) to them. */
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND pid <> pg_backend_pid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment