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.
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.
Similar Modules
MySQL Replication Status Check
Script to check MySQL/MariaDB replication lag and alert if it exceeds threshold.
sql
·
Intermediate
Cursor-based Pagination Query
Implement cursor-based (keyset) pagination in SQL — faster than OFFSET for large tables.
sql
·
Intermediate
Deadlock Detection and Prevention
Query Postgres lock waiters and identify deadlock candidates before they occur.
sql
·
Advanced