Skip to content

Instantly share code, notes, and snippets.

@bradurani
Last active February 19, 2018 17:51
Show Gist options
  • Save bradurani/49c727b7dd997ce62009d0fb972b0229 to your computer and use it in GitHub Desktop.
Save bradurani/49c727b7dd997ce62009d0fb972b0229 to your computer and use it in GitHub Desktop.
cancel old queries
SELECT
pg_cancel_backend(pid),
now()-pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now()-pg_stat_activity.query_start) > interval '1 day';
SELECT pg_sleep(30);
SELECT
pg_terminate_backend(pid),
now()-pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now()-pg_stat_activity.query_start) > interval '1 day';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment