Skip to content

Instantly share code, notes, and snippets.

@joaquinmoreira
Created March 6, 2014 15:54
Show Gist options
  • Save joaquinmoreira/9392764 to your computer and use it in GitHub Desktop.
Save joaquinmoreira/9392764 to your computer and use it in GitHub Desktop.
Close opened connections to postgresql
REVOKE CONNECT ON DATABASE dbname FROM PUBLIC, <username>; -- Prevent from accepting new connections
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid <> pg_backend_pid() -- Don't kill my own connection!
AND datname = <database>; -- Don't kill the connections to other databases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment