Databases sql Intermediate

DB Connection Pool Monitor

Query to check active connections, idle connections and pool usage in PostgreSQL.

sql
SELECT state, count(*) AS count,
       max(now() - query_start)::text AS longest_running
FROM pg_stat_activity
WHERE datname = current_database()
GROUP BY state
ORDER BY count DESC;

SELECT setting::int AS max_conn,
       (SELECT count(*) FROM pg_stat_activity) AS current_conn
FROM pg_settings WHERE name = 'max_connections';

Prerequisites

  • PostgreSQL >= 13

Pro Tips

  • → Use PgBouncer to reduce connection overhead.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
sql
Level
Intermediate
Read time
3 min
Published
Sep 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.