@@ -13,7 +13,9 @@ use std::sync::Arc;
13
13
use std:: time:: Duration ;
14
14
use tokio:: runtime;
15
15
#[ doc( inline) ]
16
- pub use tokio_postgres:: config:: { ChannelBinding , Host , SslMode , TargetSessionAttrs } ;
16
+ pub use tokio_postgres:: config:: {
17
+ ChannelBinding , Host , LoadBalanceHosts , SslMode , TargetSessionAttrs ,
18
+ } ;
17
19
use tokio_postgres:: error:: DbError ;
18
20
use tokio_postgres:: tls:: { MakeTlsConnect , TlsConnect } ;
19
21
use tokio_postgres:: { Error , Socket } ;
@@ -43,9 +45,9 @@ use tokio_postgres::{Error, Socket};
43
45
/// * `hostaddr` - Numeric IP address of host to connect to. This should be in the standard IPv4 address format,
44
46
/// e.g., 172.28.40.9. If your machine supports IPv6, you can also use those addresses.
45
47
/// If this parameter is not specified, the value of `host` will be looked up to find the corresponding IP address,
46
- /// - or if host specifies an IP address, that value will be used directly.
48
+ /// or if host specifies an IP address, that value will be used directly.
47
49
/// Using `hostaddr` allows the application to avoid a host name look-up, which might be important in applications
48
- /// with time constraints. However, a host name is required for verify-full SSL certificate verification.
50
+ /// with time constraints. However, a host name is required for TLS certificate verification.
49
51
/// Specifically:
50
52
/// * If `hostaddr` is specified without `host`, the value for `hostaddr` gives the server network address.
51
53
/// The connection attempt will fail if the authentication method requires a host name;
@@ -72,6 +74,15 @@ use tokio_postgres::{Error, Socket};
72
74
/// * `target_session_attrs` - Specifies requirements of the session. If set to `read-write`, the client will check that
73
75
/// the `transaction_read_write` session parameter is set to `on`. This can be used to connect to the primary server
74
76
/// in a database cluster as opposed to the secondary read-only mirrors. Defaults to `all`.
77
+ /// * `channel_binding` - Controls usage of channel binding in the authentication process. If set to `disable`, channel
78
+ /// binding will not be used. If set to `prefer`, channel binding will be used if available, but not used otherwise.
79
+ /// If set to `require`, the authentication process will fail if channel binding is not used. Defaults to `prefer`.
80
+ /// * `load_balance_hosts` - Controls the order in which the client tries to connect to the available hosts and
81
+ /// addresses. Once a connection attempt is successful no other hosts and addresses will be tried. This parameter
82
+ /// is typically used in combination with multiple host names or a DNS record that returns multiple IPs. If set to
83
+ /// `disable`, hosts and addresses will be tried in the order provided. If set to `random`, hosts will be tried
84
+ /// in a random order, and the IP addresses resolved from a hostname will also be tried in a random order. Defaults
85
+ /// to `disable`.
75
86
///
76
87
/// ## Examples
77
88
///
@@ -80,7 +91,7 @@ use tokio_postgres::{Error, Socket};
80
91
/// ```
81
92
///
82
93
/// ```not_rust
83
- /// host=/var/run /postgresql,localhost port=1234 user=postgres password='password with spaces'
94
+ /// host=/var/lib /postgresql,localhost port=1234 user=postgres password='password with spaces'
84
95
/// ```
85
96
///
86
97
/// ```not_rust
@@ -94,7 +105,7 @@ use tokio_postgres::{Error, Socket};
94
105
/// # Url
95
106
///
96
107
/// This format resembles a URL with a scheme of either `postgres://` or `postgresql://`. All components are optional,
97
- /// and the format accept query parameters for all of the key-value pairs described in the section above. Multiple
108
+ /// and the format accepts query parameters for all of the key-value pairs described in the section above. Multiple
98
109
/// host/port pairs can be comma-separated. Unix socket paths in the host section of the URL should be percent-encoded,
99
110
/// as the path component of the URL specifies the database name.
100
111
///
@@ -105,15 +116,15 @@ use tokio_postgres::{Error, Socket};
105
116
/// ```
106
117
///
107
118
/// ```not_rust
108
- /// postgresql://user:password@%2Fvar%2Frun %2Fpostgresql/mydb?connect_timeout=10
119
+ /// postgresql://user:password@%2Fvar%2Flib %2Fpostgresql/mydb?connect_timeout=10
109
120
/// ```
110
121
///
111
122
/// ```not_rust
112
123
/// postgresql://user@host1:1234,host2,host3:5678?target_session_attrs=read-write
113
124
/// ```
114
125
///
115
126
/// ```not_rust
116
- /// postgresql:///mydb?user=user&host=/var/run /postgresql
127
+ /// postgresql:///mydb?user=user&host=/var/lib /postgresql
117
128
/// ```
118
129
#[ derive( Clone ) ]
119
130
pub struct Config {
@@ -396,6 +407,19 @@ impl Config {
396
407
self . config . get_channel_binding ( )
397
408
}
398
409
410
+ /// Sets the host load balancing behavior.
411
+ ///
412
+ /// Defaults to `disable`.
413
+ pub fn load_balance_hosts ( & mut self , load_balance_hosts : LoadBalanceHosts ) -> & mut Config {
414
+ self . config . load_balance_hosts ( load_balance_hosts) ;
415
+ self
416
+ }
417
+
418
+ /// Gets the host load balancing behavior.
419
+ pub fn get_load_balance_hosts ( & self ) -> LoadBalanceHosts {
420
+ self . config . get_load_balance_hosts ( )
421
+ }
422
+
399
423
/// Sets the notice callback.
400
424
///
401
425
/// This callback will be invoked with the contents of every
0 commit comments