pub struct PoolConfig {
pub max_connections: u32,
pub min_connections: u32,
pub acquire_timeout: Duration,
pub idle_timeout: Option<Duration>,
pub max_lifetime: Option<Duration>,
pub test_before_acquire: bool,
}Expand description
Tuning for the connection pool a native executor opens. The defaults suit a
long-running server; use PoolConfig::serverless for per-instance
serverless environments.
Fields§
§max_connections: u32Hard ceiling on open connections. On serverless this should be tiny (the proxy does the real pooling); on a server, size it to the database’s connection budget divided by the number of app processes.
min_connections: u32Connections kept open even while idle. 0 lets the pool drain fully
between bursts.
acquire_timeout: DurationHow long acquire waits for a free connection before erroring.
idle_timeout: Option<Duration>Close a connection idle for longer than this. None keeps idle
connections indefinitely.
max_lifetime: Option<Duration>Recycle a connection older than this regardless of use — guards against
server-side timeouts and load-balancer connection caps. None disables.
test_before_acquire: boolPing a connection before handing it out. Costs a round-trip but guarantees liveness — worth it on serverless where sockets get frozen.
Implementations§
Source§impl PoolConfig
impl PoolConfig
Sourcepub fn serverless() -> Self
pub fn serverless() -> Self
A single-connection pool tuned for a serverless instance: max=1,
short idle timeout, and test_before_acquire so a frozen-then-thawed
socket is caught. Pair this with a server-side pooler (RDS Proxy /
PgBouncer / Hyperdrive) that fans many instances onto a bounded set of
real database connections. See the module docs for why.
Sourcepub fn in_memory() -> Self
pub fn in_memory() -> Self
The only configuration an in-memory SQLite database survives.
Such a database exists only as long as the connection holding it, so a pool must keep exactly one and must never reap it:
max_connections: 1, or the second connection is a second, empty database;min_connections: 1and no idle timeout, or the pool closes the connection while nothing is happening and takes the schema with it.
That second half is the one that bites. serverless
looks right — it is a pool of one — and works for the length of a test,
then drops the tables two seconds after the last query. The symptom is
a server that migrates cleanly at boot and answers no such table to
the first request a human makes.
Sourcepub fn with_max_connections(self, n: u32) -> Self
pub fn with_max_connections(self, n: u32) -> Self
Builder-style override of max_connections.