#[non_exhaustive]pub struct PgConfig {Show 17 fields
pub url: String,
pub host: String,
pub port: u16,
pub database: String,
pub user: String,
pub password: Option<String>,
pub ssl_mode: SslMode,
pub ssl_root_cert: Option<PathBuf>,
pub connect_timeout: Duration,
pub statement_timeout: Option<Duration>,
pub application_name: Option<String>,
pub keepalives: bool,
pub keepalives_idle: Option<Duration>,
pub keepalives_interval: Option<Duration>,
pub keepalives_retries: Option<u32>,
pub tcp_user_timeout: Option<Duration>,
pub options: Vec<(String, String)>,
}Expand description
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.url: StringDatabase URL.
host: StringHost (extracted from URL or explicit).
port: u16Port (default: 5432).
database: StringDatabase name.
user: StringUsername.
password: Option<String>Password.
ssl_mode: SslModeSSL mode.
With the default tls cargo feature, TLS connections are established
via rustls with certificates verified against the Mozilla root store
(chain + hostname). Without the feature, any TLS-requiring mode fails
at pool build time with a clear error — it is never silently
downgraded to plaintext.
ssl_root_cert: Option<PathBuf>Path to a PEM file of root certificates to verify the server against,
from the libpq-compatible sslrootcert URL parameter.
When set, these certificates replace the Mozilla root store rather than adding to it, matching libpq: a pool talks to one server, and “trust exactly this bundle” is both the stricter and the more predictable reading.
The case this exists for is a server whose CA is deliberately not
publicly trusted — Amazon RDS being the common one, since its
rds-ca-* authorities are Amazon-operated and absent from the Mozilla
store, so the default configuration cannot verify them at all.
connect_timeout: DurationConnection timeout.
statement_timeout: Option<Duration>Statement timeout.
application_name: Option<String>Application name (shown in pg_stat_activity).
keepalives: boolWhether TCP keepalives are enabled on the client socket (default:
true, the tokio-postgres default). From the libpq-compatible
keepalives URL parameter (0 disables, any other integer enables).
keepalives_idle: Option<Duration>Idle time before the first TCP keepalive probe is sent. None keeps
the driver default (2 hours). From the keepalives_idle URL parameter
(seconds; 0 keeps the default, as in libpq).
Together with keepalives_interval and
keepalives_retries this bounds how long
an idle connection whose peer vanished (failover, network
black-hole) goes undetected.
keepalives_interval: Option<Duration>Interval between unanswered TCP keepalive probes. None keeps the
OS default. From the keepalives_interval URL parameter (seconds;
0 keeps the default).
keepalives_retries: Option<u32>Number of unanswered TCP keepalive probes before the connection is
dropped. None keeps the OS default. From the libpq
keepalives_count URL parameter (also accepted as tokio-postgres’s
keepalives_retries; 0 keeps the default).
tcp_user_timeout: Option<Duration>TCP_USER_TIMEOUT: how long transmitted data may stay unacknowledged
before the OS closes the connection (Linux only; ignored elsewhere).
None keeps the OS default (~15 minutes of retransmissions on
Linux). From the tcp_user_timeout URL parameter (milliseconds;
0 keeps the default, as in libpq).
This bounds how long a query sent on a connection whose peer vanished hangs, which keepalives alone do not.
options: Vec<(String, String)>Additional options.
Implementations§
Source§impl PgConfig
impl PgConfig
Sourcepub fn from_url(url: impl Into<String>) -> PgResult<Self>
pub fn from_url(url: impl Into<String>) -> PgResult<Self>
Create a new configuration from a database URL.
The user name, password and database name are percent-decoded, as
libpq does: write reserved characters in them (@, /, ?, #,
:) percent-encoded. A URL whose password evidently contains them
unencoded (an @ after the host) is rejected with a configuration
error rather than parsed into the wrong host, port or database.
As with libpq, user and password query parameters set the
credentials (overriding the user info). The libpq client-side TCP
parameters keepalives, keepalives_idle (seconds),
keepalives_interval (seconds), keepalives_count (alias
keepalives_retries) and tcp_user_timeout (milliseconds) configure
the client socket; an invalid value is a configuration error. Other
unrecognised parameters become options (server
GUCs).
Sourcepub fn builder() -> PgConfigBuilder
pub fn builder() -> PgConfigBuilder
Create a builder for configuration.
Sourcepub fn to_pg_config(&self) -> Config
pub fn to_pg_config(&self) -> Config
Convert to tokio-postgres config.
Applies everything tokio_postgres::Config can express without a TLS
connector: host/port/dbname/user/password, application_name,
connect_timeout, the driver’s tokio_postgres::config::SslMode,
the client TCP settings (keepalives, keepalives_idle,
keepalives_interval, keepalives_retries, tcp_user_timeout;
unset or zero values keep the driver/OS defaults), plus statement_timeout and any extra options (passed via the
libpq-style options startup parameter as space-separated
-c key=value pairs).
Option pairs whose key is not a valid GUC name, or whose value
contains whitespace / \ / ', are dropped with a warning:
percent-decoded values could otherwise smuggle extra -c
assignments into the space-joined string.
Require/VerifyCa/VerifyFull all map to the driver’s
SslMode::Require; the pool supplies the rustls connector (with
webpki certificate verification) that makes the mode satisfiable.