@@ -57,6 +57,21 @@ pub enum ChannelBinding {
57
57
Require ,
58
58
}
59
59
60
+ /// Replication mode configuration.
61
+ ///
62
+ /// It is recommended that you use a PostgreSQL server patch version
63
+ /// of at least: 14.0, 13.2, 12.6, 11.11, 10.16, 9.6.21, or
64
+ /// 9.5.25. Earlier patch levels have a bug that doesn't properly
65
+ /// handle pipelined requests after streaming has stopped.
66
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
67
+ #[ non_exhaustive]
68
+ pub enum ReplicationMode {
69
+ /// Physical replication.
70
+ Physical ,
71
+ /// Logical replication.
72
+ Logical ,
73
+ }
74
+
60
75
/// A host specification.
61
76
#[ derive( Debug , Clone , PartialEq , Eq ) ]
62
77
pub enum Host {
@@ -164,6 +179,7 @@ pub struct Config {
164
179
pub ( crate ) keepalive_config : KeepaliveConfig ,
165
180
pub ( crate ) target_session_attrs : TargetSessionAttrs ,
166
181
pub ( crate ) channel_binding : ChannelBinding ,
182
+ pub ( crate ) replication_mode : Option < ReplicationMode > ,
167
183
}
168
184
169
185
impl Default for Config {
@@ -194,6 +210,7 @@ impl Config {
194
210
keepalive_config,
195
211
target_session_attrs : TargetSessionAttrs :: Any ,
196
212
channel_binding : ChannelBinding :: Prefer ,
213
+ replication_mode : None ,
197
214
}
198
215
}
199
216
@@ -424,6 +441,22 @@ impl Config {
424
441
self . channel_binding
425
442
}
426
443
444
+ /// Set replication mode.
445
+ ///
446
+ /// It is recommended that you use a PostgreSQL server patch version
447
+ /// of at least: 14.0, 13.2, 12.6, 11.11, 10.16, 9.6.21, or
448
+ /// 9.5.25. Earlier patch levels have a bug that doesn't properly
449
+ /// handle pipelined requests after streaming has stopped.
450
+ pub fn replication_mode ( & mut self , replication_mode : ReplicationMode ) -> & mut Config {
451
+ self . replication_mode = Some ( replication_mode) ;
452
+ self
453
+ }
454
+
455
+ /// Get replication mode.
456
+ pub fn get_replication_mode ( & self ) -> Option < ReplicationMode > {
457
+ self . replication_mode
458
+ }
459
+
427
460
fn param ( & mut self , key : & str , value : & str ) -> Result < ( ) , Error > {
428
461
match key {
429
462
"user" => {
@@ -527,6 +560,17 @@ impl Config {
527
560
} ;
528
561
self . channel_binding ( channel_binding) ;
529
562
}
563
+ "replication" => {
564
+ let mode = match value {
565
+ "off" => None ,
566
+ "true" => Some ( ReplicationMode :: Physical ) ,
567
+ "database" => Some ( ReplicationMode :: Logical ) ,
568
+ _ => return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "replication" ) ) ) ) ,
569
+ } ;
570
+ if let Some ( mode) = mode {
571
+ self . replication_mode ( mode) ;
572
+ }
573
+ }
530
574
key => {
531
575
return Err ( Error :: config_parse ( Box :: new ( UnknownOption (
532
576
key. to_string ( ) ,
@@ -601,6 +645,7 @@ impl fmt::Debug for Config {
601
645
. field ( "keepalives_retries" , & self . keepalive_config . retries )
602
646
. field ( "target_session_attrs" , & self . target_session_attrs )
603
647
. field ( "channel_binding" , & self . channel_binding )
648
+ . field ( "replication" , & self . replication_mode )
604
649
. finish ( )
605
650
}
606
651
}
0 commit comments