[−][src]Struct tokio_postgres::config::Config
Connection configuration.
Configuration can be parsed from libpq-style connection strings. These strings come in two formats:
Key-Value
This format consists of space-separated key-value pairs. Values which are either the empty string or contain
whitespace should be wrapped in '
. '
and \
characters should be backslash-escaped.
Keys
user
- The username to authenticate with. Required.password
- The password to authenticate with.dbname
- The name of the database to connect to. Defaults to the username.options
- Command line options used to configure the server.application_name
- Sets theapplication_name
parameter on the server.sslmode
- Controls usage of TLS. If set todisable
, TLS will not be used. If set toprefer
, TLS will be used if available, but not used otherwise. If set torequire
, TLS will be forced to be used. Defaults toprefer
.host
- The host to connect to. On Unix platforms, if the host starts with a/
character it is treated as the path to the directory containing Unix domain sockets. Otherwise, it is treated as a hostname. Multiple hosts can be specified, separated by commas. Each host will be tried in turn when connecting. Required if connecting with theconnect
method.port
- The port to connect to. Multiple ports can be specified, separated by commas. The number of ports must be either 1, in which case it will be used for all hosts, or the same as the number of hosts. Defaults to 5432 if omitted or the empty string.connect_timeout
- The time limit in seconds applied to each socket-level connection attempt. Note that hostnames can resolve to multiple IP addresses, and this limit is applied to each address. Defaults to no timeout.keepalives
- Controls the use of TCP keepalive. A value of 0 disables keepalive and nonzero integers enable it. This option is ignored when connecting with Unix sockets. Defaults to on.keepalives_idle
- The number of seconds of inactivity after which a keepalive message is sent to the server. This option is ignored when connecting with Unix sockets. Defaults to 2 hours.target_session_attrs
- Specifies requirements of the session. If set toread-write
, the client will check that thetransaction_read_write
session parameter is set toon
. This can be used to connect to the primary server in a database cluster as opposed to the secondary read-only mirrors. Defaults toall
.channel_binding
- Controls usage of channel binding in the authentication process. If set todisable
, channel binding will not be used. If set toprefer
, channel binding will be used if available, but not used otherwise. If set torequire
, the authentication process will fail if channel binding is not used. Defaults toprefer
.
Examples
host=localhost user=postgres connect_timeout=10 keepalives=0
host=/var/lib/postgresql,localhost port=1234 user=postgres password='password with spaces'
host=host1,host2,host3 port=1234,,5678 user=postgres target_session_attrs=read-write
Url
This format resembles a URL with a scheme of either postgres://
or postgresql://
. All components are optional,
and the format accept query parameters for all of the key-value pairs described in the section above. Multiple
host/port pairs can be comma-separated. Unix socket paths in the host section of the URL should be percent-encoded,
as the path component of the URL specifies the database name.
Examples
postgresql://user@localhost
postgresql://user:password@%2Fvar%2Flib%2Fpostgresql/mydb?connect_timeout=10
postgresql://user@host1:1234,host2,host3:5678?target_session_attrs=read-write
postgresql:///mydb?user=user&host=/var/lib/postgresql
Methods
impl Config
[src]
pub fn new() -> Config
[src]
Creates a new configuration.
pub fn user(&mut self, user: &str) -> &mut Config
[src]
Sets the user to authenticate with.
Required.
pub fn password<T>(&mut self, password: T) -> &mut Config where
T: AsRef<[u8]>,
[src]
T: AsRef<[u8]>,
Sets the password to authenticate with.
pub fn dbname(&mut self, dbname: &str) -> &mut Config
[src]
Sets the name of the database to connect to.
Defaults to the user.
pub fn options(&mut self, options: &str) -> &mut Config
[src]
Sets command line options used to configure the server.
pub fn application_name(&mut self, application_name: &str) -> &mut Config
[src]
Sets the value of the application_name
runtime parameter.
pub fn ssl_mode(&mut self, ssl_mode: SslMode) -> &mut Config
[src]
Sets the SSL configuration.
Defaults to prefer
.
pub fn host(&mut self, host: &str) -> &mut Config
[src]
Adds a host to the configuration.
Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unix
systems, a host starting with a /
is interpreted as a path to a directory containing Unix domain sockets.
pub fn port(&mut self, port: u16) -> &mut Config
[src]
Adds a port to the configuration.
Multiple ports can be specified by calling this method multiple times. There must either be no ports, in which case the default of 5432 is used, a single port, in which it is used for all hosts, or the same number of ports as hosts.
pub fn connect_timeout(&mut self, connect_timeout: Duration) -> &mut Config
[src]
Sets the timeout applied to socket-level connection attempts.
Note that hostnames can resolve to multiple IP addresses, and this timeout will apply to each address of each host separately. Defaults to no limit.
pub fn keepalives(&mut self, keepalives: bool) -> &mut Config
[src]
Controls the use of TCP keepalive.
This is ignored for Unix domain socket connections. Defaults to true
.
pub fn keepalives_idle(&mut self, keepalives_idle: Duration) -> &mut Config
[src]
Sets the amount of idle time before a keepalive packet is sent on the connection.
This is ignored for Unix domain sockets, or if the keepalives
option is disabled. Defaults to 2 hours.
pub fn target_session_attrs(
&mut self,
target_session_attrs: TargetSessionAttrs
) -> &mut Config
[src]
&mut self,
target_session_attrs: TargetSessionAttrs
) -> &mut Config
Sets the requirements of the session.
This can be used to connect to the primary server in a clustered database rather than one of the read-only
secondary servers. Defaults to Any
.
pub fn channel_binding(
&mut self,
channel_binding: ChannelBinding
) -> &mut Config
[src]
&mut self,
channel_binding: ChannelBinding
) -> &mut Config
Sets the channel binding behavior.
Defaults to prefer
.
pub async fn connect<'_, T>(
&'_ self,
tls: T
) -> Result<(Client, Connection<Socket, T::Stream>), Error> where
T: MakeTlsConnect<Socket>,
[src]
&'_ self,
tls: T
) -> Result<(Client, Connection<Socket, T::Stream>), Error> where
T: MakeTlsConnect<Socket>,
Opens a connection to a PostgreSQL database.
Requires the runtime
Cargo feature (enabled by default).
pub async fn connect_raw<'_, S, T>(
&'_ self,
stream: S,
tls: T
) -> Result<(Client, Connection<S, T::Stream>), Error> where
S: AsyncRead + AsyncWrite + Unpin,
T: TlsConnect<S>,
[src]
&'_ self,
stream: S,
tls: T
) -> Result<(Client, Connection<S, T::Stream>), Error> where
S: AsyncRead + AsyncWrite + Unpin,
T: TlsConnect<S>,
Connects to a PostgreSQL database over an arbitrary stream.
All of the settings other than user
, password
, dbname
, options
, and application
name are ignored.
Trait Implementations
impl Clone for Config
[src]
impl Default for Config
[src]
impl PartialEq<Config> for Config
[src]
impl Debug for Config
[src]
impl FromStr for Config
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Config, Error>
[src]
impl StructuralPartialEq for Config
[src]
Auto Trait Implementations
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
impl RefUnwindSafe for Config
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,