#[non_exhaustive]pub struct PoolConfig {
pub max_connections: usize,
pub min_connections: usize,
pub connection_timeout: Option<Duration>,
pub idle_timeout: Option<Duration>,
pub recycle_timeout: Option<Duration>,
pub max_lifetime: Option<Duration>,
pub recycling: PgRecycling,
pub statement_cache_size: usize,
}Expand description
Configuration for the connection pool.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_connections: usizeMaximum number of connections in the pool.
min_connections: usizeMinimum number of connections to pre-establish and keep alive.
deadpool exposes no minimum-size knob, so these are established by a best-effort background warmup when the pool is created; the released connections are then retained by the pool.
connection_timeout: Option<Duration>Maximum time to wait for a connection.
idle_timeout: Option<Duration>Idle timeout: a connection that was not handed out for longer than this is discarded and replaced at its next checkout instead of being reused (so a connection a server, proxy or NAT may have dropped while idle is not handed out).
Enforced at checkout, like max_lifetime:
idle connections are not reaped in the background. The idle time is
measured from when the connection was last handed out (deadpool
does not record when it is returned), so a connection held for
longer than this is also replaced at its next checkout.
Duration::ZERO replaces every reused connection; None disables
the limit. It does not bound the recycle check; use
PoolConfig::recycle_timeout for that. Default: 10 minutes.
recycle_timeout: Option<Duration>Upper bound on the recycle check run when a connection is checked out
again (the Verified / Clean round trip).
Mapped to deadpool’s recycle_timeout. A recycle that exceeds it
discards the connection and a fresh one is created. None disables
the bound. Default: 5 seconds.
max_lifetime: Option<Duration>Maximum lifetime of a connection.
Enforced at checkout: a connection older than this is discarded and
replaced instead of being handed out. Connections are not reaped
while idle. Each connection’s limit is shortened by a stable jitter of
up to ~10% so connections created together do not all expire at once.
Duration::ZERO replaces the connection on every checkout, which
effectively disables pooling.
recycling: PgRecyclingRecycling method applied when a connection is checked out again.
Defaults to PgRecycling::Fast, which does not reset session state
(SET, SET ROLE, tenant GUCs persist across checkouts). Use
PgRecycling::Clean for RLS / tenant-scoped workloads.
statement_cache_size: usizeNumber of SQL strings tracked for prepared-statement cache metrics.
PreparedStatementCache records only which SQL strings have been
seen (hit/miss tracing); actual statement caching is per-connection
inside tokio-postgres and is not bounded by this value.