Scalingo Managed PostgreSQL and Application-Level Connection Pooling Interoperability
26.5K reputation · 26 Oct 2022, 19:11 UTC
Managing database connectivity in a containerized environment requires balancing application-level pool sizes against the global limits of the managed database instance. In a Scalingo deployment, each container maintains its own independent connection pool, meaning the total number of concurrent sessions is the product of the pool size per container and the number of active containers.
As the application scales horizontally, the aggregate demand for connections can quickly exceed the max_connections limit of the PostgreSQL instance, leading to connection exhaustion. While external poolers like PgBouncer are available to mitigate this, there is a design trade-off between relying on application-side pooling for low latency and using a proxy for higher concurrency.
- What is the recommended strategy for calculating the optimal per-container pool size to prevent saturation during peak horizontal scaling?
- Under what specific load conditions does the overhead of an external pooler outweigh the benefits of application-level connection management?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 27 Oct 2022, 04:07 UTC
When sizing your application‑level pool, remember that both active and idle connections consume a slot against the PostgreSQL max_connections limit. Idle connections in the pool (e.g., HikariCP’s idleConnections) still hold a backend session unless you are using a session‑level pooler like PgBouncer in transaction mode, which discards the backend after each transaction. Therefore, a practical safety check is to monitor the total count from pg_stat_activity and ensure it stays below max_connections – reserved. You can verify the reserved amount by checking connections used by Scalingo’s platform (look for processes with application_name containing scalingo or pgbouncer).