Pcornel
Databases · Database Fundamentals

Database Connections and Pooling

Cheat sheet · https://pcornel.dk/topic.php?topic=6163

Back to the Topic

Answer

Database connections are expensive server resources; pooling (application pools, PgBouncer, ProxySQL) reuses a smaller number of connections for many clients.

Remember

Size pools so all app instances together stay under max_connections. PgBouncer transaction mode breaks session features (prepared statements, temp tables) unless supported.

First checks

  • SELECT count(*) FROM pg_stat_activity; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Commands

SHOW STATUS LIKE 'Threads_connected';

Verify in this order

app → pool → limited server connections → queries

Where it usually breaks

Raising max_connections without memory planning can make the server swap.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6163

Confirmation

Confirm action

Continue?