@@ -57,6 +57,13 @@ impl TimelineHistory {
57
57
}
58
58
}
59
59
60
+ #[ derive( Debug ) ]
61
+ pub enum SnapshotMode {
62
+ ExportSnapshot ,
63
+ NoExportSnapshot ,
64
+ UseSnapshot ,
65
+ }
66
+
60
67
/// Replication client connection.
61
68
///
62
69
/// A replication client is used to issue replication commands, begin
@@ -204,6 +211,62 @@ impl ReplicationClient {
204
211
} )
205
212
}
206
213
214
+ /// Create physical replication slot
215
+ pub async fn create_physical_replication_slot (
216
+ & self ,
217
+ slot_name : & str ,
218
+ temporary : bool ,
219
+ reserve_wal : bool
220
+ ) -> Result < ( ) , Error > {
221
+ let iclient = self . 0 . inner ( ) ;
222
+ let temporary_str = if temporary { " TEMPORARY" } else { "" } ;
223
+ let reserve_wal_str = if reserve_wal { " RESERVE_WAL" } else { "" } ;
224
+ let command = format ! ( "CREATE_REPLICATION_SLOT {}{} PHYSICAL{}" ,
225
+ escape_identifier( slot_name) ,
226
+ temporary_str,
227
+ reserve_wal_str) ;
228
+ let buf = simple_query:: encode ( iclient, & command) ?;
229
+ let _responses = iclient. send ( RequestMessages :: Single ( FrontendMessage :: Raw ( buf) ) ) ?;
230
+ Ok ( ( ) )
231
+ }
232
+
233
+ /// Create logical replication slot.
234
+ pub async fn create_logical_replication_slot (
235
+ & self ,
236
+ slot_name : & str ,
237
+ temporary : bool ,
238
+ plugin_name : & str ,
239
+ snapshot_mode : Option < SnapshotMode > ,
240
+ ) -> Result < ( ) , Error > {
241
+ let iclient = self . 0 . inner ( ) ;
242
+ let temporary_str = if temporary { " TEMPORARY" } else { "" } ;
243
+ let snapshot_str = snapshot_mode. map_or ( "" , |mode| {
244
+ match mode {
245
+ SnapshotMode :: ExportSnapshot => " EXPORT_SNAPSHOT" ,
246
+ SnapshotMode :: NoExportSnapshot => " NOEXPORT_SNAPSHOT" ,
247
+ SnapshotMode :: UseSnapshot => " USE_SNAPSHOT" ,
248
+ }
249
+ } ) ;
250
+ let command = format ! ( "CREATE_REPLICATION_SLOT {}{} LOGICAL {}{}" ,
251
+ escape_identifier( slot_name) ,
252
+ temporary_str,
253
+ escape_identifier( plugin_name) ,
254
+ snapshot_str) ;
255
+ let buf = simple_query:: encode ( iclient, & command) ?;
256
+ let _responses = iclient. send ( RequestMessages :: Single ( FrontendMessage :: Raw ( buf) ) ) ?;
257
+ Ok ( ( ) )
258
+ }
259
+
260
+ /// Drop replication slot
261
+ pub async fn drop_replication_slot ( & self , slot_name : & str , wait : bool ) -> Result < ( ) , Error > {
262
+ let iclient = self . 0 . inner ( ) ;
263
+ let wait_str = if wait { " WAIT" } else { "" } ;
264
+ let command = format ! ( "DROP_REPLICATION_SLOT {}{}" , escape_identifier( slot_name) , wait_str) ;
265
+ let buf = simple_query:: encode ( iclient, & command) ?;
266
+ let _responses = iclient. send ( RequestMessages :: Single ( FrontendMessage :: Raw ( buf) ) ) ?;
267
+ Ok ( ( ) )
268
+ }
269
+
207
270
/// Begin physical replication, consuming the replication client and producing a replication stream.
208
271
///
209
272
/// Replication begins starting with the given Log Sequence Number
0 commit comments