Skip to content

Instantly share code, notes, and snippets.

@ffeast
Created December 27, 2017 08:00
Show Gist options
  • Save ffeast/7ed36b0c405bab163f592bb424724903 to your computer and use it in GitHub Desktop.
Save ffeast/7ed36b0c405bab163f592bb424724903 to your computer and use it in GitHub Desktop.
Postgresql kill connections
# https://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
pid <> 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