Skip to content

Instantly share code, notes, and snippets.

@skeptrunedev
Created January 24, 2025 06:14
Show Gist options
  • Select an option

  • Save skeptrunedev/c1a7507fc326cfbd7a76fdcec62d9cc5 to your computer and use it in GitHub Desktop.

Select an option

Save skeptrunedev/c1a7507fc326cfbd7a76fdcec62d9cc5 to your computer and use it in GitHub Desktop.
kill long running pg locks
WITH active_long_connections AS (
SELECT pid, now() - backend_start AS duration
FROM pg_stat_activity
WHERE state = 'active'
AND pid <> pg_backend_pid()
)
SELECT
pid,
duration,
pg_terminate_backend(pid) AS terminated
FROM active_long_connections
WHERE duration > interval '5 minutes';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment