Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Configuration

Generated rustdoc: https://docs.rs/babar/latest/babar/struct.Config.html

See also: Book Chapter 1 — Connecting, Chapter 6 — Pooling, Chapter 12 — TLS & security.

babar::Config

Config holds everything Session::connect needs. Required fields are positional in the constructor; optional fields are chained methods. Build it from any source — env vars, a config file, a clap::Parser. babar deliberately doesn’t ship a DSN parser.

Constructors

MethodRequired arguments
Config::new(host, port, user, dbname)impl Into<String> for host/user/dbname, u16 for port. Resolves host via DNS at connect time.
Config::with_addr(addr, port, user, dbname)addr: IpAddr, port: u16, user/dbname as impl Into<String>. Skips DNS — useful for IP-direct deployments.

Optional fields (chained, value-returning)

MethodTypeDefaultNotes
.password(p)impl Into<String>noneSent to the server only as part of the auth handshake.
.application_name(n)impl Into<String>noneSurfaces in pg_stat_activity.application_name. Cheapest observability win.
.connect_timeout(d)DurationnoneWall-clock cap on Session::connect.
.tls_mode(m)TlsModeDisableDisable / Prefer / Require. Opt in to Prefer or Require explicitly. See ch12.
.require_tls()Sugar for .tls_mode(TlsMode::Require).
.tls_backend(b)TlsBackendRustls (with rustls feature)Rustls or NativeTls.
.tls_server_name(n)impl Into<String>hostOverride SNI / certificate-name match.
.tls_root_cert_path(p)impl Into<PathBuf>system roots / webpki-rootsPEM bundle of additional root CAs.

TLS-mode and backend enums

EnumVariantsRe-exported as
TlsModeDisable, Prefer, Requirebabar::config::TlsMode
TlsBackendRustls, NativeTlsbabar::config::TlsBackend

babar::PoolConfig

PoolConfig is everything Pool::new needs that isn’t a Config.

Constructor

PoolConfig::new() — conservative defaults. All knobs are chained, value-returning methods.

Knobs

MethodTypeDefaultNotes
.min_idle(n)usize0Keep at least n warm connections when traffic permits.
.max_size(n)usize16Hard cap on total connections in the pool.
.acquire_timeout(d)Duration30 secondsHow long pool.acquire() waits before returning PoolError::Timeout.
.idle_timeout(d)Durationunset (no idle timeout)Close idle connections older than this.
.max_lifetime(d)Durationunset (no lifetime cap)Recycle connections after this age regardless of idle state.
.health_check(h)HealthCheckHealthCheck::NonePer-acquire validation policy (off by default).

PoolError

VariantWhen
PoolError::Timeoutacquire_timeout elapsed before a slot freed up.
PoolError::AcquireFailed(babar::Error)The pool tried to open a fresh connection and the underlying Session::connect failed.
PoolError::PoolClosedThe pool itself has been closed.

Picking values

Some tested starting points:

Service shapemax_sizeacquire_timeoutmin_idle
HTTP service, low/medium traffic8165–10s0
HTTP service, high traffic≈ #worker threads × 21–3s≥ 2
Long-running batch / ETL1430s+0

Beyond that, watch:

  • pg_stat_activity for connection count vs server’s max_connections.
  • Pool acquire latency (you wrap it yourself; see Chapter 13).
  • p99 query latency vs pool size — if increasing max_size doesn’t move p99, the pool isn’t the bottleneck.

Next

For the cargo features that gate TLS backends and codec types, see feature-flags.md. For the errors these knobs can produce, see errors.md.