Skip to content

Instantly share code, notes, and snippets.

@andreyshuster
Created July 27, 2022 16:36
Show Gist options
  • Save andreyshuster/05062aa5a31c05b70b7994074e24a50e to your computer and use it in GitHub Desktop.
Save andreyshuster/05062aa5a31c05b70b7994074e24a50e to your computer and use it in GitHub Desktop.
Select long running queries
SELECT
  pid,
  now() - pg_stat_activity.query_start AS duration,
  query,
  state
FROM pg_stat_activity
WHERE query like '%<condition>%' AND (now() - pg_stat_activity.query_start) > interval '5 minutes';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment