pub struct PostgresPoolConfig {
pub max_connections: u32,
pub min_connections: u32,
pub idle_timeout: Duration,
pub max_lifetime: Duration,
pub acquire_timeout: Duration,
pub statement_timeout: Duration,
}Expand description
Configuration for PostgreSQL connection pool tuning.
These parameters control how sqlx manages the underlying connection pool. All fields have sensible defaults suitable for moderate production load.
§Recommended PostgreSQL server settings
For production workloads, tune these postgresql.conf knobs alongside the
pool parameters:
| PostgreSQL setting | Recommended value | Notes |
|---|---|---|
max_connections | 100 - 200 | Must exceed pool max_connections |
shared_buffers | 25% of RAM | Main query cache |
work_mem | 4 - 16 MB | Per-sort/hash memory |
idle_in_transaction_session_timeout | 30s | Kill idle-in-transaction sessions |
statement_timeout | 30s | Server-side query timeout |
tcp_keepalives_idle | 60 | Seconds before TCP keepalive probes |
tcp_keepalives_interval | 10 | Seconds between probes |
tcp_keepalives_count | 6 | Failed probes before disconnect |
Fields§
§max_connections: u32Maximum number of connections in the pool (default: 10).
min_connections: u32Minimum number of idle connections to maintain (default: 2).
idle_timeout: DurationTime a connection may sit idle before being closed (default: 300s).
max_lifetime: DurationMaximum lifetime of a connection before it is recycled (default: 1800s).
acquire_timeout: DurationHow long to wait when acquiring a connection from the pool (default: 5s).
statement_timeout: DurationStatement timeout set on each new connection via SET statement_timeout
(default: 30s). Prevents runaway queries.
Trait Implementations§
Source§impl Clone for PostgresPoolConfig
impl Clone for PostgresPoolConfig
Source§fn clone(&self) -> PostgresPoolConfig
fn clone(&self) -> PostgresPoolConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PostgresPoolConfig
impl Debug for PostgresPoolConfig
Auto Trait Implementations§
impl Freeze for PostgresPoolConfig
impl RefUnwindSafe for PostgresPoolConfig
impl Send for PostgresPoolConfig
impl Sync for PostgresPoolConfig
impl Unpin for PostgresPoolConfig
impl UnsafeUnpin for PostgresPoolConfig
impl UnwindSafe for PostgresPoolConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.