Skip to content

Instantly share code, notes, and snippets.

@khaliqgant
Created June 7, 2022 12:21
Show Gist options
  • Save khaliqgant/1f137278d3b5b8fbe22dcb952d186288 to your computer and use it in GitHub Desktop.
Save khaliqgant/1f137278d3b5b8fbe22dcb952d186288 to your computer and use it in GitHub Desktop.
[Postgres Query Duration] Find long running postgres tasks #postgres #database
select now() - xact_start as duration, * from pg_stat_activity WHERE state = 'active';
SELECT max(now() - xact_start) FROM pg_stat_activity
WHERE state IN ('idle in transaction', 'active');
--- https://dba.stackexchange.com/questions/44084/troubleshooting-high-cpu-usage-from-postgres-and-postmaster-services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment