Maximum Pool Size vs. Idle Timeout: Which Limits Reduce Connection Pool Exhaustion in DataGrip?
0 reputation · 30 Mar 2022, 21:58 UTC
0 reputation · 30 Mar 2022, 21:58 UTC
DataGrip’s built‑in HikariCP connection pool can occasionally hit exhaustion when traffic surges or long‑running queries keep connections marked as “in use.” The UI exposes two key levers: Maximum pool size and Idle timeout, each documented under Data Sources → Properties → Advanced → Connection pool.
The goal is to determine which configuration change most reliably prevents spikes in active connections while respecting database and OS limits. Increasing Maximum pool size from the default 10 to 30 allows more concurrent sessions but may overwhelm the database or exhaust file descriptors. Conversely, a short Idle timeout (e.g., 30 s) aggressively frees unused connections, keeping the pool lean, yet can trigger reconnection overhead during brief traffic bursts.
Uncertainty remains around the documented behavior: in versions 2023.2‑2023.3, the pool does not always honor the idle timeout when a connection is flagged as “in use” by a long‑running statement (such as a 60‑second SELECT pg_sleep). This can lead to intermittent exhaustion even when limits appear respected.
1) Does DataGrip’s idle timeout correctly evict connections that are idle but still marked as in use by a long‑running query?
2) What measurable impact does raising the maximum pool size from 10 to 30 have on the database server’s resource utilization and OS file‑descriptor count?
3) Are there documented workarounds or additional settings that force eviction of such connections during long‑running statements?
Neither setting alone prevents exhaustion when long-running queries hold connections. Idle timeout only evicts connections that are idle in the pool; a connection executing a statement is "in use" and is not eligible for eviction, regardless of how long it runs. Maximum pool size merely raises the ceiling on concurrent sessions—it does not free anything. The reliable fix is to bound query duration (statement/query timeout) and size the pool to what the database can sustain.
No—this is expected behavior, not a bug, in DataGrip's 2023.2–2023.3 HikariCP-based pool (and HikariCP generally). Idle timeout applies only to connections sitting unused in the pool. A connection checked out and running SELECT pg_sleep(60) is "in use," so the pool cannot reclaim it until the statement finishes and the connection is returned. If many such queries pile up, the pool exhausts even with a 30 s idle timeout configured.
Verify it yourself:
SELECT pg_sleep(60);SELECT pid, state, query_start, query FROM pg_stat_activity WHERE datname = current_database(); — the sleeping session stays active well past 30 s.Raising the cap does not create connections up front, but it permits up to 30 concurrent sessions. The cost scales roughly linearly with active connections:
work_mem can apply per operation per session). 30 busy backends can triple memory/CPU pressure versus 10.lsof -p <datagrip_pid> | grep -c TCP and the server side against max_connections.max_connections headroom or the OS ulimit -n, new connections fail outright.So a larger pool helps only if spikes are short-lived and the database has capacity; it makes exhaustion worse if the underlying cause is slow queries, because more sessions contend for the same server.
SET statement_timeout = '30s'; per session, or configure it on the database role/server. This is the most direct fix.For your symptom—exhaustion driven by long-running queries—tune in this order: (1) add a statement timeout, (2) keep max pool size near the default unless load testing proves the database handles more, (3) use idle timeout only to shrink the pool during quiet periods. One caveat: exact option names and any forced-eviction behavior may vary by DataGrip release, so confirm against your version's release notes before deploying changes.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.