Skip to content

Instantly share code, notes, and snippets.

@harshalbhakta
Created June 18, 2014 13:23
Show Gist options
  • Select an option

  • Save harshalbhakta/178563e42c127b28f374 to your computer and use it in GitHub Desktop.

Select an option

Save harshalbhakta/178563e42c127b28f374 to your computer and use it in GitHub Desktop.
Delete open Postgresql connections
-- http://stackoverflow.com/a/5408501
-- PostgreSQL 9.1 and below:
SELECT pg_terminate_backend(pg_stat_activity.procpid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND procpid <> pg_backend_pid();
-- PostgreSQL 9.2 and above:
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