Skip to main content

PoolConfig

Struct PoolConfig 

Source
pub struct PoolConfig {
Show 24 fields pub host: String, pub port: u16, pub user: String, pub database: String, pub password: Option<String>, pub max_connections: usize, pub min_connections: usize, pub idle_timeout: Duration, pub acquire_timeout: Duration, pub connect_timeout: Duration, pub max_lifetime: Option<Duration>, pub test_on_acquire: bool, pub tls_mode: TlsMode, pub tls_ca_cert_pem: Option<Vec<u8>>, pub mtls: Option<TlsConfig>, pub gss_token_provider: Option<GssTokenProvider>, pub gss_token_provider_ex: Option<GssTokenProviderEx>, pub gss_connect_retries: usize, pub gss_retry_base_delay: Duration, pub gss_circuit_breaker_threshold: usize, pub gss_circuit_breaker_window: Duration, pub gss_circuit_breaker_cooldown: Duration, pub auth_settings: AuthSettings, pub gss_enc_mode: GssEncMode,
}
Expand description

Configuration for a PostgreSQL connection pool.

Use the builder pattern to customise settings:

use std::time::Duration;
use qail_pg::driver::pool::PoolConfig;
let config = PoolConfig::new("localhost", 5432, "app", "mydb")
    .password("secret")
    .max_connections(20)
    .acquire_timeout(Duration::from_secs(5));

Fields§

§host: String

PostgreSQL server hostname or IP address.

§port: u16

PostgreSQL server port (default: 5432).

§user: String

Database role / user name.

§database: String

Target database name.

§password: Option<String>

Optional password for authentication.

§max_connections: usize

Hard upper limit on simultaneous connections (default: 10).

§min_connections: usize

Minimum idle connections kept warm in the pool (default: 1).

§idle_timeout: Duration

Close idle connections after this duration (default: 10 min).

§acquire_timeout: Duration

Maximum time to wait when acquiring a connection (default: 30s).

§connect_timeout: Duration

TCP connect timeout for new connections (default: 10s).

§max_lifetime: Option<Duration>

Optional maximum lifetime of any connection in the pool.

§test_on_acquire: bool

When true, run a health check (SELECT 1) before handing out a connection.

§tls_mode: TlsMode

TLS mode for new connections.

§tls_ca_cert_pem: Option<Vec<u8>>

Optional custom CA bundle (PEM) for server certificate validation.

§mtls: Option<TlsConfig>

Optional mTLS client certificate/key configuration.

§gss_token_provider: Option<GssTokenProvider>

Optional callback for Kerberos/GSS/SSPI token generation.

§gss_token_provider_ex: Option<GssTokenProviderEx>

Optional stateful callback for Kerberos/GSS/SSPI token generation.

§gss_connect_retries: usize

Number of retries for transient GSS/Kerberos connection failures.

§gss_retry_base_delay: Duration

Base delay for GSS/Kerberos connect retry backoff.

§gss_circuit_breaker_threshold: usize

Transient GSS failures in one window before opening the local circuit.

§gss_circuit_breaker_window: Duration

Rolling window used to count transient GSS failures.

§gss_circuit_breaker_cooldown: Duration

Cooldown duration while the local GSS circuit stays open.

§auth_settings: AuthSettings

Password-auth policy.

§gss_enc_mode: GssEncMode

GSSAPI session encryption mode (gssencmode URL parameter).

Implementations§

Source§

impl PoolConfig

Source

pub fn new(host: &str, port: u16, user: &str, database: &str) -> Self

Create a new pool configuration with production-safe defaults.

Defaults: tls_mode = Require, auth_settings = scram_only(). For local development without TLS, use PoolConfig::new_dev.

§Arguments
  • host — PostgreSQL server hostname or IP.
  • port — TCP port (typically 5432).
  • user — PostgreSQL role name.
  • database — Target database name.
Source

pub fn new_dev(host: &str, port: u16, user: &str, database: &str) -> Self

Create a pool configuration with permissive defaults for local development.

Defaults: tls_mode = Disable, auth_settings = default() (accepts any auth). Do NOT use in production.

Source

pub fn password(self, password: &str) -> Self

Set password for authentication.

Source

pub fn max_connections(self, max: usize) -> Self

Set maximum simultaneous connections.

Source

pub fn min_connections(self, min: usize) -> Self

Set minimum idle connections.

Source

pub fn idle_timeout(self, timeout: Duration) -> Self

Set idle timeout (connections idle longer than this are closed).

Source

pub fn acquire_timeout(self, timeout: Duration) -> Self

Set acquire timeout (max wait time when getting a connection).

Source

pub fn connect_timeout(self, timeout: Duration) -> Self

Set connect timeout (max time to establish new connection).

Source

pub fn max_lifetime(self, lifetime: Duration) -> Self

Set maximum lifetime of a connection before recycling.

Source

pub fn test_on_acquire(self, enabled: bool) -> Self

Enable connection validation on acquire.

Source

pub fn tls_mode(self, mode: TlsMode) -> Self

Set TLS mode for pool connections.

Source

pub fn tls_ca_cert_pem(self, ca_cert_pem: Vec<u8>) -> Self

Set custom CA bundle (PEM) for TLS validation.

Source

pub fn mtls(self, config: TlsConfig) -> Self

Enable mTLS for pool connections.

Source

pub fn gss_token_provider(self, provider: GssTokenProvider) -> Self

Set Kerberos/GSS/SSPI token provider callback.

Source

pub fn gss_token_provider_ex(self, provider: GssTokenProviderEx) -> Self

Set a stateful Kerberos/GSS/SSPI token provider.

Source

pub fn gss_connect_retries(self, retries: usize) -> Self

Set retry count for transient GSS/Kerberos connection failures.

Source

pub fn gss_retry_base_delay(self, delay: Duration) -> Self

Set base backoff delay for GSS/Kerberos connection retry.

Source

pub fn gss_circuit_breaker_threshold(self, threshold: usize) -> Self

Set failure threshold for opening local GSS circuit breaker.

Source

pub fn gss_circuit_breaker_window(self, window: Duration) -> Self

Set rolling failure window for GSS circuit breaker.

Source

pub fn gss_circuit_breaker_cooldown(self, cooldown: Duration) -> Self

Set cooldown duration for open GSS circuit breaker.

Source

pub fn auth_settings(self, settings: AuthSettings) -> Self

Set authentication policy.

Source

pub fn from_qail_config(qail: &QailConfig) -> PgResult<Self>

Create a PoolConfig from a centralized QailConfig.

Parses postgres.url for host/port/user/database/password and applies pool tuning from [postgres] section.

Trait Implementations§

Source§

impl Clone for PoolConfig

Source§

fn clone(&self) -> PoolConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ColumnValue<Value> for T