Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Last active July 27, 2021 06:12
Show Gist options
  • Save StevenJL/1c62d1a3679aa017f66d64606fd6c148 to your computer and use it in GitHub Desktop.
Save StevenJL/1c62d1a3679aa017f66d64606fd6c148 to your computer and use it in GitHub Desktop.
See postgres connections
SELECT state, COUNT(*) FROM pg_stat_activity
WHERE pid <> pg_backend_pid()
GROUP BY 1;
# state | count
# ---------------------+-------
# active | 7
# idle | 569
# idle in transaction | 2
# | 9
# (4 rows)
SELECT application_name, COUNT(*) FROM pg_stat_activity
WHERE pid <> pg_backend_pid()
GROUP BY 1 ORDER BY 1;
# application_name | count
# ------------------------------------------------------------+-------
# web_server | 63
# cron_job | 1
# psql | 4
# background_job | 15
# (4 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment