pub struct PoolOptions {
pub max_connections: u32,
pub min_connections: u32,
pub acquire_timeout: Duration,
pub idle_timeout: Duration,
pub max_lifetime: Duration,
pub is_lazy: bool,
pub statement_cache_capacity: usize,
}Expand description
Configures the behavior of the database connection pool.
These settings control the lifecycle and allocation of database connections,
which is critical for application performance and stability. The options
map directly to the underlying sqlx::PoolOptions.
§Examples
An example of how this might be represented in a TOML configuration file:
maxConnections = 20
minConnections = 5
acquireTimeout = "30s"
idleTimeout = "5m"
maxLifetime = "30m"
isLazy = false
statementCacheCapacity = 200Fields§
§max_connections: u32The maximum number of connections the pool should maintain.
This value should be set carefully based on the database server’s capacity and the expected application load.
Default: 10
min_connections: u32The minimum number of idle connections the pool should maintain.
When the pool is created, this many connections will be established. If the number of idle connections drops below this value, the pool will attempt to create new ones to replenish it.
Default: 1
acquire_timeout: DurationThe maximum time to wait for a connection to become available.
If a connection cannot be acquired from the pool within this duration, the operation will time out and return an error.
Default: 30 seconds
idle_timeout: DurationThe maximum duration a connection can remain idle in the pool.
Any connection that has been idle for longer than this duration will be closed and removed from the pool. This helps release resources on the database server.
Default: 300 seconds (5 minutes)
max_lifetime: DurationThe maximum lifetime of any single connection.
A connection will be gracefully closed once it has been open for this duration. This is a crucial practice for preventing resource leaks and ensuring connections are periodically recycled.
Default: 1800 seconds (30 minutes)
is_lazy: boolIf true, the pool will not establish connections until one is first requested.
If false, the pool will try to establish min_connections immediately
upon creation.
Default: true
statement_cache_capacity: usizeThe capacity of the prepared statement cache for each connection.
Caching is managed using an LRU (Least Recently Used) policy. When the number of cached statements exceeds this capacity, the oldest one is evicted.
Default: 100
Trait Implementations§
Source§impl Clone for PoolOptions
impl Clone for PoolOptions
Source§impl Debug for PoolOptions
impl Debug for PoolOptions
Source§impl Default for PoolOptions
impl Default for PoolOptions
Source§impl<'de> Deserialize<'de> for PoolOptions
impl<'de> Deserialize<'de> for PoolOptions
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for PoolOptions
Source§impl PartialEq for PoolOptions
impl PartialEq for PoolOptions
Source§impl Serialize for PoolOptions
impl Serialize for PoolOptions
impl StructuralPartialEq for PoolOptions
Auto Trait Implementations§
impl Freeze for PoolOptions
impl RefUnwindSafe for PoolOptions
impl Send for PoolOptions
impl Sync for PoolOptions
impl Unpin for PoolOptions
impl UnsafeUnpin for PoolOptions
impl UnwindSafe for PoolOptions
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
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> ⓘ
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 more