Skip to content

Instantly share code, notes, and snippets.

@DFrenkel
Last active December 19, 2015 03:18
Show Gist options
  • Save DFrenkel/5888776 to your computer and use it in GitHub Desktop.
Save DFrenkel/5888776 to your computer and use it in GitHub Desktop.
Kill Postgres Connections
-- see http://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
SELECT
pg_terminate_backend(procpid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
procpid <> pg_backend_pid()
-- don't kill the connections to other databases
AND datname = 'database_name';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment