@@ -56,6 +56,21 @@ pub enum ChannelBinding {
56
56
Require ,
57
57
}
58
58
59
+ /// Replication mode configuration.
60
+ ///
61
+ /// It is recommended that you use a PostgreSQL server patch version
62
+ /// of at least: 14.0, 13.2, 12.6, 11.11, 10.16, 9.6.21, or
63
+ /// 9.5.25. Earlier patch levels have a bug that doesn't properly
64
+ /// handle pipelined requests after streaming has stopped.
65
+ #[ derive( Debug , Copy , Clone , PartialEq ) ]
66
+ #[ non_exhaustive]
67
+ pub enum ReplicationMode {
68
+ /// Physical replication.
69
+ Physical ,
70
+ /// Logical replication.
71
+ Logical ,
72
+ }
73
+
59
74
/// A host specification.
60
75
#[ derive( Debug , Clone , PartialEq ) ]
61
76
pub enum Host {
@@ -159,6 +174,7 @@ pub struct Config {
159
174
pub ( crate ) keepalives_idle : Duration ,
160
175
pub ( crate ) target_session_attrs : TargetSessionAttrs ,
161
176
pub ( crate ) channel_binding : ChannelBinding ,
177
+ pub ( crate ) replication_mode : Option < ReplicationMode > ,
162
178
}
163
179
164
180
impl Default for Config {
@@ -184,6 +200,7 @@ impl Config {
184
200
keepalives_idle : Duration :: from_secs ( 2 * 60 * 60 ) ,
185
201
target_session_attrs : TargetSessionAttrs :: Any ,
186
202
channel_binding : ChannelBinding :: Prefer ,
203
+ replication_mode : None ,
187
204
}
188
205
}
189
206
@@ -387,6 +404,22 @@ impl Config {
387
404
self . channel_binding
388
405
}
389
406
407
+ /// Set replication mode.
408
+ ///
409
+ /// It is recommended that you use a PostgreSQL server patch version
410
+ /// of at least: 14.0, 13.2, 12.6, 11.11, 10.16, 9.6.21, or
411
+ /// 9.5.25. Earlier patch levels have a bug that doesn't properly
412
+ /// handle pipelined requests after streaming has stopped.
413
+ pub fn replication_mode ( & mut self , replication_mode : ReplicationMode ) -> & mut Config {
414
+ self . replication_mode = Some ( replication_mode) ;
415
+ self
416
+ }
417
+
418
+ /// Get replication mode.
419
+ pub fn get_replication_mode ( & self ) -> Option < ReplicationMode > {
420
+ self . replication_mode
421
+ }
422
+
390
423
fn param ( & mut self , key : & str , value : & str ) -> Result < ( ) , Error > {
391
424
match key {
392
425
"user" => {
@@ -476,6 +509,17 @@ impl Config {
476
509
} ;
477
510
self . channel_binding ( channel_binding) ;
478
511
}
512
+ "replication" => {
513
+ let mode = match value {
514
+ "off" => None ,
515
+ "true" => Some ( ReplicationMode :: Physical ) ,
516
+ "database" => Some ( ReplicationMode :: Logical ) ,
517
+ _ => return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "replication" ) ) ) ) ,
518
+ } ;
519
+ if let Some ( mode) = mode {
520
+ self . replication_mode ( mode) ;
521
+ }
522
+ }
479
523
key => {
480
524
return Err ( Error :: config_parse ( Box :: new ( UnknownOption (
481
525
key. to_string ( ) ,
@@ -548,6 +592,7 @@ impl fmt::Debug for Config {
548
592
. field ( "keepalives_idle" , & self . keepalives_idle )
549
593
. field ( "target_session_attrs" , & self . target_session_attrs )
550
594
. field ( "channel_binding" , & self . channel_binding )
595
+ . field ( "replication" , & self . replication_mode )
551
596
. finish ( )
552
597
}
553
598
}
0 commit comments