Skip to content

Instantly share code, notes, and snippets.

@danishabdullah
Created December 5, 2014 09:48
Show Gist options
  • Save danishabdullah/315c74101f3d10283599 to your computer and use it in GitHub Desktop.
Save danishabdullah/315c74101f3d10283599 to your computer and use it in GitHub Desktop.
Kill Idle Connections in Postgresql
SELECT pg_terminate_backend(pid)
    FROM pg_stat_activity
    WHERE pid <> pg_backend_pid()
      AND state = 'idle'
      AND state_change < current_timestamp - INTERVAL '5' MINUTE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment