Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Last active January 23, 2021 07:53
Show Gist options
  • Save StevenJL/9fad854f29c7a3868670bc5b69580c36 to your computer and use it in GitHub Desktop.
Save StevenJL/9fad854f29c7a3868670bc5b69580c36 to your computer and use it in GitHub Desktop.
Psql Oldest Running Query
SELECT application_name,
pid,
state,
age(clock_timestamp(), query_start), /* How long has the query has been running in h:m:s */
usename,
query /* The query text */
FROM pg_stat_activity
WHERE state != 'idle'
AND query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start asc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment