#[non_exhaustive]pub struct PgConfig {
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 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).
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). Other unrecognised
parameters become options.
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,
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.