Skip to content

Instantly share code, notes, and snippets.

@marcosgz
Created August 3, 2023 12:25
Show Gist options
  • Save marcosgz/26fb67857fe3da35748044a2f940f08f to your computer and use it in GitHub Desktop.
Save marcosgz/26fb67857fe3da35748044a2f940f08f to your computer and use it in GitHub Desktop.
View active queries in Postgres
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '1 minutes' and state<>'idle'
order by pg_stat_activity.query_start desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment