pgoutput-client 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -2
- data/LICENSE.txt +6 -6
- data/README.md +312 -19
- data/lib/pgoutput/client/commands.rb +62 -0
- data/lib/pgoutput/client/configuration.rb +194 -0
- data/lib/pgoutput/client/connection.rb +120 -0
- data/lib/pgoutput/client/errors.rb +41 -0
- data/lib/pgoutput/client/feedback.rb +62 -0
- data/lib/pgoutput/client/keepalive.rb +64 -0
- data/lib/pgoutput/client/lsn.rb +54 -0
- data/lib/pgoutput/client/stream.rb +102 -0
- data/lib/pgoutput/client/version.rb +4 -1
- data/lib/pgoutput/client/xlog_data.rb +71 -0
- data/lib/pgoutput/client.rb +117 -2
- data/lib/pgoutput_client.rb +12 -0
- data/sig/pg.rbs +12 -0
- data/sig/pgoutput/client/commands.rbs +42 -0
- data/sig/pgoutput/client/configuration.rbs +504 -0
- data/sig/pgoutput/client/connection.rbs +91 -0
- data/sig/pgoutput/client/errors.rbs +43 -0
- data/sig/pgoutput/client/feedback.rbs +71 -0
- data/sig/pgoutput/client/keepalive.rbs +55 -0
- data/sig/pgoutput/client/lsn.rbs +36 -0
- data/sig/pgoutput/client/stream.rbs +68 -0
- data/sig/pgoutput/client/version.rbs +8 -0
- data/sig/pgoutput/client/xlog_data.rbs +63 -0
- data/sig/pgoutput/client.rbs +93 -2
- metadata +46 -10
- data/CODE_OF_CONDUCT.md +0 -10
- data/Rakefile +0 -12
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Pgoutput
|
|
2
|
+
module Client
|
|
3
|
+
# SQL command builders for PostgreSQL replication-mode commands.
|
|
4
|
+
#
|
|
5
|
+
# PostgreSQL replication commands are issued on a connection opened with the
|
|
6
|
+
# replication parameter enabled. The methods in this module render the small
|
|
7
|
+
# command subset needed by `pgoutput-client` and rely on {Configuration} to
|
|
8
|
+
# validate identifier-like values before interpolation.
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
module Commands
|
|
12
|
+
# Render a `CREATE_REPLICATION_SLOT` command.
|
|
13
|
+
#
|
|
14
|
+
# Temporary slots are requested only when
|
|
15
|
+
# {Configuration#temporary_slot} is true.
|
|
16
|
+
#
|
|
17
|
+
# @example Permanent slot
|
|
18
|
+
# Commands.create_replication_slot(config)
|
|
19
|
+
# # => "CREATE_REPLICATION_SLOT cdc_slot LOGICAL pgoutput"
|
|
20
|
+
#
|
|
21
|
+
# @param configuration [Configuration] replication configuration
|
|
22
|
+
# @return [String] SQL command suitable for `PG::Connection#exec`
|
|
23
|
+
def self?.create_replication_slot: (untyped configuration) -> ::String
|
|
24
|
+
|
|
25
|
+
# Render a `DROP_REPLICATION_SLOT` command.
|
|
26
|
+
#
|
|
27
|
+
# @param configuration [Configuration] replication configuration
|
|
28
|
+
# @return [String] SQL command suitable for `PG::Connection#exec`
|
|
29
|
+
def self?.drop_replication_slot: (untyped configuration) -> ::String
|
|
30
|
+
|
|
31
|
+
# Render a `START_REPLICATION SLOT ... LOGICAL ...` command.
|
|
32
|
+
#
|
|
33
|
+
# The command includes the pgoutput options required by PostgreSQL:
|
|
34
|
+
# `proto_version` and `publication_names`. Optional pgoutput switches such
|
|
35
|
+
# as `binary` and `messages` are emitted only when enabled.
|
|
36
|
+
#
|
|
37
|
+
# @param configuration [Configuration] replication configuration
|
|
38
|
+
# @return [String] SQL command suitable for `PG::Connection#exec`
|
|
39
|
+
def self?.start_replication: (untyped configuration) -> ::String
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
module Pgoutput
|
|
2
|
+
module Client
|
|
3
|
+
# Immutable configuration for a PostgreSQL logical replication stream.
|
|
4
|
+
#
|
|
5
|
+
# A configuration describes how `pgoutput-client` should connect to
|
|
6
|
+
# PostgreSQL and how it should request logical replication from the server.
|
|
7
|
+
# It deliberately contains transport-level settings only; parsing pgoutput
|
|
8
|
+
# records and decoding PostgreSQL values belong to downstream layers.
|
|
9
|
+
#
|
|
10
|
+
# The object freezes itself and its string/array attributes during
|
|
11
|
+
# initialization so it can be safely shared by transport components without
|
|
12
|
+
# defensive copying.
|
|
13
|
+
#
|
|
14
|
+
# @example Minimal configuration
|
|
15
|
+
# config = Pgoutput::Client::Configuration.new(
|
|
16
|
+
# database_url: "postgres://localhost/app",
|
|
17
|
+
# slot_name: "cdc_slot",
|
|
18
|
+
# publication_names: "app_publication"
|
|
19
|
+
# )
|
|
20
|
+
#
|
|
21
|
+
# @example Start from a known LSN and request binary values from pgoutput
|
|
22
|
+
# config = Pgoutput::Client::Configuration.new(
|
|
23
|
+
# database_url: ENV.fetch("DATABASE_URL"),
|
|
24
|
+
# slot_name: "cdc_slot",
|
|
25
|
+
# publication_names: %w[app_publication],
|
|
26
|
+
# start_lsn: "0/16B6C50",
|
|
27
|
+
# binary: true
|
|
28
|
+
# )
|
|
29
|
+
#
|
|
30
|
+
# @api public
|
|
31
|
+
class Configuration
|
|
32
|
+
@database_url: untyped
|
|
33
|
+
|
|
34
|
+
@slot_name: untyped
|
|
35
|
+
|
|
36
|
+
@publication_names: untyped
|
|
37
|
+
|
|
38
|
+
@start_lsn: untyped
|
|
39
|
+
|
|
40
|
+
@plugin: untyped
|
|
41
|
+
|
|
42
|
+
@proto_version: untyped
|
|
43
|
+
|
|
44
|
+
@binary: untyped
|
|
45
|
+
|
|
46
|
+
@messages: untyped
|
|
47
|
+
|
|
48
|
+
@auto_create_slot: untyped
|
|
49
|
+
|
|
50
|
+
@temporary_slot: untyped
|
|
51
|
+
|
|
52
|
+
@feedback_interval: untyped
|
|
53
|
+
|
|
54
|
+
# Default logical decoding output plugin.
|
|
55
|
+
#
|
|
56
|
+
# @return [String]
|
|
57
|
+
DEFAULT_PLUGIN: "pgoutput"
|
|
58
|
+
|
|
59
|
+
# Default pgoutput protocol version.
|
|
60
|
+
#
|
|
61
|
+
# @return [Integer]
|
|
62
|
+
DEFAULT_PROTO_VERSION: 1
|
|
63
|
+
|
|
64
|
+
# Default interval, in seconds, between standby status feedback messages.
|
|
65
|
+
#
|
|
66
|
+
# @return [Float]
|
|
67
|
+
DEFAULT_FEEDBACK_INTERVAL: ::Float
|
|
68
|
+
|
|
69
|
+
# @!attribute [r] database_url
|
|
70
|
+
# PostgreSQL connection URL.
|
|
71
|
+
# @return [String]
|
|
72
|
+
# @!attribute [r] slot_name
|
|
73
|
+
# Logical replication slot name.
|
|
74
|
+
# @return [String]
|
|
75
|
+
# @!attribute [r] publication_names
|
|
76
|
+
# Publication names requested from pgoutput.
|
|
77
|
+
# @return [Array<String>]
|
|
78
|
+
# @!attribute [r] start_lsn
|
|
79
|
+
# Optional normalized starting LSN.
|
|
80
|
+
# @return [String, nil]
|
|
81
|
+
# @!attribute [r] plugin
|
|
82
|
+
# Logical decoding output plugin name.
|
|
83
|
+
# @return [String]
|
|
84
|
+
# @!attribute [r] proto_version
|
|
85
|
+
# pgoutput protocol version.
|
|
86
|
+
# @return [Integer]
|
|
87
|
+
# @!attribute [r] binary
|
|
88
|
+
# Whether to request binary column values from pgoutput.
|
|
89
|
+
# @return [Boolean]
|
|
90
|
+
# @!attribute [r] messages
|
|
91
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
92
|
+
# @return [Boolean]
|
|
93
|
+
# @!attribute [r] auto_create_slot
|
|
94
|
+
# Whether the client should create the slot before streaming.
|
|
95
|
+
# @return [Boolean]
|
|
96
|
+
# @!attribute [r] temporary_slot
|
|
97
|
+
# Whether a newly created slot should be temporary.
|
|
98
|
+
# @return [Boolean]
|
|
99
|
+
# @!attribute [r] feedback_interval
|
|
100
|
+
# Standby feedback interval in seconds.
|
|
101
|
+
# @return [Float]
|
|
102
|
+
attr_reader database_url: untyped
|
|
103
|
+
|
|
104
|
+
# @!attribute [r] database_url
|
|
105
|
+
# PostgreSQL connection URL.
|
|
106
|
+
# @return [String]
|
|
107
|
+
# @!attribute [r] slot_name
|
|
108
|
+
# Logical replication slot name.
|
|
109
|
+
# @return [String]
|
|
110
|
+
# @!attribute [r] publication_names
|
|
111
|
+
# Publication names requested from pgoutput.
|
|
112
|
+
# @return [Array<String>]
|
|
113
|
+
# @!attribute [r] start_lsn
|
|
114
|
+
# Optional normalized starting LSN.
|
|
115
|
+
# @return [String, nil]
|
|
116
|
+
# @!attribute [r] plugin
|
|
117
|
+
# Logical decoding output plugin name.
|
|
118
|
+
# @return [String]
|
|
119
|
+
# @!attribute [r] proto_version
|
|
120
|
+
# pgoutput protocol version.
|
|
121
|
+
# @return [Integer]
|
|
122
|
+
# @!attribute [r] binary
|
|
123
|
+
# Whether to request binary column values from pgoutput.
|
|
124
|
+
# @return [Boolean]
|
|
125
|
+
# @!attribute [r] messages
|
|
126
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
127
|
+
# @return [Boolean]
|
|
128
|
+
# @!attribute [r] auto_create_slot
|
|
129
|
+
# Whether the client should create the slot before streaming.
|
|
130
|
+
# @return [Boolean]
|
|
131
|
+
# @!attribute [r] temporary_slot
|
|
132
|
+
# Whether a newly created slot should be temporary.
|
|
133
|
+
# @return [Boolean]
|
|
134
|
+
# @!attribute [r] feedback_interval
|
|
135
|
+
# Standby feedback interval in seconds.
|
|
136
|
+
# @return [Float]
|
|
137
|
+
attr_reader slot_name: untyped
|
|
138
|
+
|
|
139
|
+
# @!attribute [r] database_url
|
|
140
|
+
# PostgreSQL connection URL.
|
|
141
|
+
# @return [String]
|
|
142
|
+
# @!attribute [r] slot_name
|
|
143
|
+
# Logical replication slot name.
|
|
144
|
+
# @return [String]
|
|
145
|
+
# @!attribute [r] publication_names
|
|
146
|
+
# Publication names requested from pgoutput.
|
|
147
|
+
# @return [Array<String>]
|
|
148
|
+
# @!attribute [r] start_lsn
|
|
149
|
+
# Optional normalized starting LSN.
|
|
150
|
+
# @return [String, nil]
|
|
151
|
+
# @!attribute [r] plugin
|
|
152
|
+
# Logical decoding output plugin name.
|
|
153
|
+
# @return [String]
|
|
154
|
+
# @!attribute [r] proto_version
|
|
155
|
+
# pgoutput protocol version.
|
|
156
|
+
# @return [Integer]
|
|
157
|
+
# @!attribute [r] binary
|
|
158
|
+
# Whether to request binary column values from pgoutput.
|
|
159
|
+
# @return [Boolean]
|
|
160
|
+
# @!attribute [r] messages
|
|
161
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
162
|
+
# @return [Boolean]
|
|
163
|
+
# @!attribute [r] auto_create_slot
|
|
164
|
+
# Whether the client should create the slot before streaming.
|
|
165
|
+
# @return [Boolean]
|
|
166
|
+
# @!attribute [r] temporary_slot
|
|
167
|
+
# Whether a newly created slot should be temporary.
|
|
168
|
+
# @return [Boolean]
|
|
169
|
+
# @!attribute [r] feedback_interval
|
|
170
|
+
# Standby feedback interval in seconds.
|
|
171
|
+
# @return [Float]
|
|
172
|
+
attr_reader publication_names: untyped
|
|
173
|
+
|
|
174
|
+
# @!attribute [r] database_url
|
|
175
|
+
# PostgreSQL connection URL.
|
|
176
|
+
# @return [String]
|
|
177
|
+
# @!attribute [r] slot_name
|
|
178
|
+
# Logical replication slot name.
|
|
179
|
+
# @return [String]
|
|
180
|
+
# @!attribute [r] publication_names
|
|
181
|
+
# Publication names requested from pgoutput.
|
|
182
|
+
# @return [Array<String>]
|
|
183
|
+
# @!attribute [r] start_lsn
|
|
184
|
+
# Optional normalized starting LSN.
|
|
185
|
+
# @return [String, nil]
|
|
186
|
+
# @!attribute [r] plugin
|
|
187
|
+
# Logical decoding output plugin name.
|
|
188
|
+
# @return [String]
|
|
189
|
+
# @!attribute [r] proto_version
|
|
190
|
+
# pgoutput protocol version.
|
|
191
|
+
# @return [Integer]
|
|
192
|
+
# @!attribute [r] binary
|
|
193
|
+
# Whether to request binary column values from pgoutput.
|
|
194
|
+
# @return [Boolean]
|
|
195
|
+
# @!attribute [r] messages
|
|
196
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
197
|
+
# @return [Boolean]
|
|
198
|
+
# @!attribute [r] auto_create_slot
|
|
199
|
+
# Whether the client should create the slot before streaming.
|
|
200
|
+
# @return [Boolean]
|
|
201
|
+
# @!attribute [r] temporary_slot
|
|
202
|
+
# Whether a newly created slot should be temporary.
|
|
203
|
+
# @return [Boolean]
|
|
204
|
+
# @!attribute [r] feedback_interval
|
|
205
|
+
# Standby feedback interval in seconds.
|
|
206
|
+
# @return [Float]
|
|
207
|
+
attr_reader start_lsn: untyped
|
|
208
|
+
|
|
209
|
+
# @!attribute [r] database_url
|
|
210
|
+
# PostgreSQL connection URL.
|
|
211
|
+
# @return [String]
|
|
212
|
+
# @!attribute [r] slot_name
|
|
213
|
+
# Logical replication slot name.
|
|
214
|
+
# @return [String]
|
|
215
|
+
# @!attribute [r] publication_names
|
|
216
|
+
# Publication names requested from pgoutput.
|
|
217
|
+
# @return [Array<String>]
|
|
218
|
+
# @!attribute [r] start_lsn
|
|
219
|
+
# Optional normalized starting LSN.
|
|
220
|
+
# @return [String, nil]
|
|
221
|
+
# @!attribute [r] plugin
|
|
222
|
+
# Logical decoding output plugin name.
|
|
223
|
+
# @return [String]
|
|
224
|
+
# @!attribute [r] proto_version
|
|
225
|
+
# pgoutput protocol version.
|
|
226
|
+
# @return [Integer]
|
|
227
|
+
# @!attribute [r] binary
|
|
228
|
+
# Whether to request binary column values from pgoutput.
|
|
229
|
+
# @return [Boolean]
|
|
230
|
+
# @!attribute [r] messages
|
|
231
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
232
|
+
# @return [Boolean]
|
|
233
|
+
# @!attribute [r] auto_create_slot
|
|
234
|
+
# Whether the client should create the slot before streaming.
|
|
235
|
+
# @return [Boolean]
|
|
236
|
+
# @!attribute [r] temporary_slot
|
|
237
|
+
# Whether a newly created slot should be temporary.
|
|
238
|
+
# @return [Boolean]
|
|
239
|
+
# @!attribute [r] feedback_interval
|
|
240
|
+
# Standby feedback interval in seconds.
|
|
241
|
+
# @return [Float]
|
|
242
|
+
attr_reader plugin: untyped
|
|
243
|
+
|
|
244
|
+
# @!attribute [r] database_url
|
|
245
|
+
# PostgreSQL connection URL.
|
|
246
|
+
# @return [String]
|
|
247
|
+
# @!attribute [r] slot_name
|
|
248
|
+
# Logical replication slot name.
|
|
249
|
+
# @return [String]
|
|
250
|
+
# @!attribute [r] publication_names
|
|
251
|
+
# Publication names requested from pgoutput.
|
|
252
|
+
# @return [Array<String>]
|
|
253
|
+
# @!attribute [r] start_lsn
|
|
254
|
+
# Optional normalized starting LSN.
|
|
255
|
+
# @return [String, nil]
|
|
256
|
+
# @!attribute [r] plugin
|
|
257
|
+
# Logical decoding output plugin name.
|
|
258
|
+
# @return [String]
|
|
259
|
+
# @!attribute [r] proto_version
|
|
260
|
+
# pgoutput protocol version.
|
|
261
|
+
# @return [Integer]
|
|
262
|
+
# @!attribute [r] binary
|
|
263
|
+
# Whether to request binary column values from pgoutput.
|
|
264
|
+
# @return [Boolean]
|
|
265
|
+
# @!attribute [r] messages
|
|
266
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
267
|
+
# @return [Boolean]
|
|
268
|
+
# @!attribute [r] auto_create_slot
|
|
269
|
+
# Whether the client should create the slot before streaming.
|
|
270
|
+
# @return [Boolean]
|
|
271
|
+
# @!attribute [r] temporary_slot
|
|
272
|
+
# Whether a newly created slot should be temporary.
|
|
273
|
+
# @return [Boolean]
|
|
274
|
+
# @!attribute [r] feedback_interval
|
|
275
|
+
# Standby feedback interval in seconds.
|
|
276
|
+
# @return [Float]
|
|
277
|
+
attr_reader proto_version: untyped
|
|
278
|
+
|
|
279
|
+
# @!attribute [r] database_url
|
|
280
|
+
# PostgreSQL connection URL.
|
|
281
|
+
# @return [String]
|
|
282
|
+
# @!attribute [r] slot_name
|
|
283
|
+
# Logical replication slot name.
|
|
284
|
+
# @return [String]
|
|
285
|
+
# @!attribute [r] publication_names
|
|
286
|
+
# Publication names requested from pgoutput.
|
|
287
|
+
# @return [Array<String>]
|
|
288
|
+
# @!attribute [r] start_lsn
|
|
289
|
+
# Optional normalized starting LSN.
|
|
290
|
+
# @return [String, nil]
|
|
291
|
+
# @!attribute [r] plugin
|
|
292
|
+
# Logical decoding output plugin name.
|
|
293
|
+
# @return [String]
|
|
294
|
+
# @!attribute [r] proto_version
|
|
295
|
+
# pgoutput protocol version.
|
|
296
|
+
# @return [Integer]
|
|
297
|
+
# @!attribute [r] binary
|
|
298
|
+
# Whether to request binary column values from pgoutput.
|
|
299
|
+
# @return [Boolean]
|
|
300
|
+
# @!attribute [r] messages
|
|
301
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
302
|
+
# @return [Boolean]
|
|
303
|
+
# @!attribute [r] auto_create_slot
|
|
304
|
+
# Whether the client should create the slot before streaming.
|
|
305
|
+
# @return [Boolean]
|
|
306
|
+
# @!attribute [r] temporary_slot
|
|
307
|
+
# Whether a newly created slot should be temporary.
|
|
308
|
+
# @return [Boolean]
|
|
309
|
+
# @!attribute [r] feedback_interval
|
|
310
|
+
# Standby feedback interval in seconds.
|
|
311
|
+
# @return [Float]
|
|
312
|
+
attr_reader binary: untyped
|
|
313
|
+
|
|
314
|
+
# @!attribute [r] database_url
|
|
315
|
+
# PostgreSQL connection URL.
|
|
316
|
+
# @return [String]
|
|
317
|
+
# @!attribute [r] slot_name
|
|
318
|
+
# Logical replication slot name.
|
|
319
|
+
# @return [String]
|
|
320
|
+
# @!attribute [r] publication_names
|
|
321
|
+
# Publication names requested from pgoutput.
|
|
322
|
+
# @return [Array<String>]
|
|
323
|
+
# @!attribute [r] start_lsn
|
|
324
|
+
# Optional normalized starting LSN.
|
|
325
|
+
# @return [String, nil]
|
|
326
|
+
# @!attribute [r] plugin
|
|
327
|
+
# Logical decoding output plugin name.
|
|
328
|
+
# @return [String]
|
|
329
|
+
# @!attribute [r] proto_version
|
|
330
|
+
# pgoutput protocol version.
|
|
331
|
+
# @return [Integer]
|
|
332
|
+
# @!attribute [r] binary
|
|
333
|
+
# Whether to request binary column values from pgoutput.
|
|
334
|
+
# @return [Boolean]
|
|
335
|
+
# @!attribute [r] messages
|
|
336
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
337
|
+
# @return [Boolean]
|
|
338
|
+
# @!attribute [r] auto_create_slot
|
|
339
|
+
# Whether the client should create the slot before streaming.
|
|
340
|
+
# @return [Boolean]
|
|
341
|
+
# @!attribute [r] temporary_slot
|
|
342
|
+
# Whether a newly created slot should be temporary.
|
|
343
|
+
# @return [Boolean]
|
|
344
|
+
# @!attribute [r] feedback_interval
|
|
345
|
+
# Standby feedback interval in seconds.
|
|
346
|
+
# @return [Float]
|
|
347
|
+
attr_reader messages: untyped
|
|
348
|
+
|
|
349
|
+
# @!attribute [r] database_url
|
|
350
|
+
# PostgreSQL connection URL.
|
|
351
|
+
# @return [String]
|
|
352
|
+
# @!attribute [r] slot_name
|
|
353
|
+
# Logical replication slot name.
|
|
354
|
+
# @return [String]
|
|
355
|
+
# @!attribute [r] publication_names
|
|
356
|
+
# Publication names requested from pgoutput.
|
|
357
|
+
# @return [Array<String>]
|
|
358
|
+
# @!attribute [r] start_lsn
|
|
359
|
+
# Optional normalized starting LSN.
|
|
360
|
+
# @return [String, nil]
|
|
361
|
+
# @!attribute [r] plugin
|
|
362
|
+
# Logical decoding output plugin name.
|
|
363
|
+
# @return [String]
|
|
364
|
+
# @!attribute [r] proto_version
|
|
365
|
+
# pgoutput protocol version.
|
|
366
|
+
# @return [Integer]
|
|
367
|
+
# @!attribute [r] binary
|
|
368
|
+
# Whether to request binary column values from pgoutput.
|
|
369
|
+
# @return [Boolean]
|
|
370
|
+
# @!attribute [r] messages
|
|
371
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
372
|
+
# @return [Boolean]
|
|
373
|
+
# @!attribute [r] auto_create_slot
|
|
374
|
+
# Whether the client should create the slot before streaming.
|
|
375
|
+
# @return [Boolean]
|
|
376
|
+
# @!attribute [r] temporary_slot
|
|
377
|
+
# Whether a newly created slot should be temporary.
|
|
378
|
+
# @return [Boolean]
|
|
379
|
+
# @!attribute [r] feedback_interval
|
|
380
|
+
# Standby feedback interval in seconds.
|
|
381
|
+
# @return [Float]
|
|
382
|
+
attr_reader auto_create_slot: untyped
|
|
383
|
+
|
|
384
|
+
# @!attribute [r] database_url
|
|
385
|
+
# PostgreSQL connection URL.
|
|
386
|
+
# @return [String]
|
|
387
|
+
# @!attribute [r] slot_name
|
|
388
|
+
# Logical replication slot name.
|
|
389
|
+
# @return [String]
|
|
390
|
+
# @!attribute [r] publication_names
|
|
391
|
+
# Publication names requested from pgoutput.
|
|
392
|
+
# @return [Array<String>]
|
|
393
|
+
# @!attribute [r] start_lsn
|
|
394
|
+
# Optional normalized starting LSN.
|
|
395
|
+
# @return [String, nil]
|
|
396
|
+
# @!attribute [r] plugin
|
|
397
|
+
# Logical decoding output plugin name.
|
|
398
|
+
# @return [String]
|
|
399
|
+
# @!attribute [r] proto_version
|
|
400
|
+
# pgoutput protocol version.
|
|
401
|
+
# @return [Integer]
|
|
402
|
+
# @!attribute [r] binary
|
|
403
|
+
# Whether to request binary column values from pgoutput.
|
|
404
|
+
# @return [Boolean]
|
|
405
|
+
# @!attribute [r] messages
|
|
406
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
407
|
+
# @return [Boolean]
|
|
408
|
+
# @!attribute [r] auto_create_slot
|
|
409
|
+
# Whether the client should create the slot before streaming.
|
|
410
|
+
# @return [Boolean]
|
|
411
|
+
# @!attribute [r] temporary_slot
|
|
412
|
+
# Whether a newly created slot should be temporary.
|
|
413
|
+
# @return [Boolean]
|
|
414
|
+
# @!attribute [r] feedback_interval
|
|
415
|
+
# Standby feedback interval in seconds.
|
|
416
|
+
# @return [Float]
|
|
417
|
+
attr_reader temporary_slot: untyped
|
|
418
|
+
|
|
419
|
+
# @!attribute [r] database_url
|
|
420
|
+
# PostgreSQL connection URL.
|
|
421
|
+
# @return [String]
|
|
422
|
+
# @!attribute [r] slot_name
|
|
423
|
+
# Logical replication slot name.
|
|
424
|
+
# @return [String]
|
|
425
|
+
# @!attribute [r] publication_names
|
|
426
|
+
# Publication names requested from pgoutput.
|
|
427
|
+
# @return [Array<String>]
|
|
428
|
+
# @!attribute [r] start_lsn
|
|
429
|
+
# Optional normalized starting LSN.
|
|
430
|
+
# @return [String, nil]
|
|
431
|
+
# @!attribute [r] plugin
|
|
432
|
+
# Logical decoding output plugin name.
|
|
433
|
+
# @return [String]
|
|
434
|
+
# @!attribute [r] proto_version
|
|
435
|
+
# pgoutput protocol version.
|
|
436
|
+
# @return [Integer]
|
|
437
|
+
# @!attribute [r] binary
|
|
438
|
+
# Whether to request binary column values from pgoutput.
|
|
439
|
+
# @return [Boolean]
|
|
440
|
+
# @!attribute [r] messages
|
|
441
|
+
# Whether to request logical decoding messages from pgoutput.
|
|
442
|
+
# @return [Boolean]
|
|
443
|
+
# @!attribute [r] auto_create_slot
|
|
444
|
+
# Whether the client should create the slot before streaming.
|
|
445
|
+
# @return [Boolean]
|
|
446
|
+
# @!attribute [r] temporary_slot
|
|
447
|
+
# Whether a newly created slot should be temporary.
|
|
448
|
+
# @return [Boolean]
|
|
449
|
+
# @!attribute [r] feedback_interval
|
|
450
|
+
# Standby feedback interval in seconds.
|
|
451
|
+
# @return [Float]
|
|
452
|
+
attr_reader feedback_interval: untyped
|
|
453
|
+
|
|
454
|
+
# Build and validate a logical replication stream configuration.
|
|
455
|
+
#
|
|
456
|
+
# `slot_name` and every publication name are intentionally limited to
|
|
457
|
+
# simple PostgreSQL identifier-like strings. This keeps command rendering
|
|
458
|
+
# small and predictable while avoiding quoting rules in this transport
|
|
459
|
+
# layer.
|
|
460
|
+
#
|
|
461
|
+
# Boolean options are normalized with Ruby truthiness. `nil` and `false`
|
|
462
|
+
# become `false`; all other values become `true`.
|
|
463
|
+
#
|
|
464
|
+
# @param database_url [#to_s] PostgreSQL connection URL
|
|
465
|
+
# @param slot_name [#to_s] logical replication slot name
|
|
466
|
+
# @param publication_names [Array<#to_s>, #to_s] one or more publication
|
|
467
|
+
# names to pass to pgoutput
|
|
468
|
+
# @param start_lsn [String, Integer, nil] starting LSN as a PostgreSQL LSN
|
|
469
|
+
# string, an integer WAL position, or `nil` for `0/0`
|
|
470
|
+
# @param plugin [#to_s] logical decoding plugin name
|
|
471
|
+
# @param proto_version [#to_int, #to_s] pgoutput protocol version
|
|
472
|
+
# @param binary [Object] truthy to request binary column values
|
|
473
|
+
# @param messages [Object] truthy to request logical decoding messages
|
|
474
|
+
# @param auto_create_slot [Object] truthy to create the slot before
|
|
475
|
+
# starting replication
|
|
476
|
+
# @param temporary_slot [Object] truthy to create a temporary replication
|
|
477
|
+
# slot when `auto_create_slot` is enabled
|
|
478
|
+
# @param feedback_interval [#to_f, #to_s] seconds between periodic standby
|
|
479
|
+
# feedback messages
|
|
480
|
+
# @return [void]
|
|
481
|
+
# @raise [ConfigurationError] if publication names are empty or numeric
|
|
482
|
+
# settings are invalid
|
|
483
|
+
# @raise [ArgumentError] if `start_lsn`, `proto_version`, or
|
|
484
|
+
# `feedback_interval` cannot be coerced
|
|
485
|
+
def initialize: (database_url: untyped, slot_name: untyped, publication_names: untyped, ?start_lsn: untyped?, ?plugin: untyped, ?proto_version: untyped, ?binary: bool, ?messages: bool, ?auto_create_slot: bool, ?temporary_slot: bool, ?feedback_interval: untyped) -> void
|
|
486
|
+
|
|
487
|
+
# Starting LSN to render in `START_REPLICATION`.
|
|
488
|
+
#
|
|
489
|
+
# @return [String] normalized LSN string, defaulting to `"0/0"`
|
|
490
|
+
def start_lsn_string: () -> untyped
|
|
491
|
+
|
|
492
|
+
private
|
|
493
|
+
|
|
494
|
+
def validate!: () -> untyped
|
|
495
|
+
|
|
496
|
+
def normalize_lsn: (untyped value) -> (nil | untyped)
|
|
497
|
+
|
|
498
|
+
def validate_identifier: (untyped value, untyped field) -> untyped
|
|
499
|
+
|
|
500
|
+
# Boolean type checking helper
|
|
501
|
+
def boolean: (untyped value, untyped name) -> (true | false | untyped)
|
|
502
|
+
end
|
|
503
|
+
end
|
|
504
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module Pgoutput
|
|
2
|
+
module Client
|
|
3
|
+
# Thin wrapper around `PG::Connection` for logical replication operations.
|
|
4
|
+
#
|
|
5
|
+
# `Connection` hides the small amount of PostgreSQL driver plumbing needed by
|
|
6
|
+
# the rest of the transport layer. It opens the connection in replication
|
|
7
|
+
# mode, renders replication commands through {Commands}, and translates
|
|
8
|
+
# `PG::Error` exceptions into {ConnectionError}.
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
class Connection
|
|
12
|
+
@configuration: untyped
|
|
13
|
+
|
|
14
|
+
@pg_connection: untyped
|
|
15
|
+
|
|
16
|
+
# Configuration associated with this connection.
|
|
17
|
+
#
|
|
18
|
+
# @return [Configuration]
|
|
19
|
+
attr_reader configuration: untyped
|
|
20
|
+
|
|
21
|
+
# Open a PostgreSQL connection in database replication mode.
|
|
22
|
+
#
|
|
23
|
+
# @param configuration [Configuration] replication configuration
|
|
24
|
+
# @return [Connection] wrapper around an open `PG::Connection`
|
|
25
|
+
# @raise [ConnectionError] if the `pg` gem cannot connect
|
|
26
|
+
def self.open: (untyped configuration) -> untyped
|
|
27
|
+
|
|
28
|
+
# Build a connection wrapper.
|
|
29
|
+
#
|
|
30
|
+
# This constructor is public primarily for tests and alternative connection
|
|
31
|
+
# factories. Normal callers should use {.open}.
|
|
32
|
+
#
|
|
33
|
+
# @param configuration [Configuration] replication configuration
|
|
34
|
+
# @param pg_connection [PG::Connection] connected PostgreSQL driver object
|
|
35
|
+
# @return [void]
|
|
36
|
+
def initialize: (configuration: untyped, pg_connection: untyped) -> void
|
|
37
|
+
|
|
38
|
+
# Execute PostgreSQL's `IDENTIFY_SYSTEM` replication command.
|
|
39
|
+
#
|
|
40
|
+
# @return [PG::Result] server identity result
|
|
41
|
+
# @raise [ConnectionError] if PostgreSQL rejects the command
|
|
42
|
+
def identify_system: () -> untyped
|
|
43
|
+
|
|
44
|
+
# Create the configured logical replication slot.
|
|
45
|
+
#
|
|
46
|
+
# @return [PG::Result] command result
|
|
47
|
+
# @raise [ConnectionError] if PostgreSQL rejects the command
|
|
48
|
+
def create_replication_slot: () -> untyped
|
|
49
|
+
|
|
50
|
+
# Drop the configured logical replication slot.
|
|
51
|
+
#
|
|
52
|
+
# @return [PG::Result] command result
|
|
53
|
+
# @raise [ConnectionError] if PostgreSQL rejects the command
|
|
54
|
+
def drop_replication_slot: () -> untyped
|
|
55
|
+
|
|
56
|
+
# Start streaming logical replication from the configured slot and LSN.
|
|
57
|
+
#
|
|
58
|
+
# @return [PG::Result] command result
|
|
59
|
+
# @raise [ConnectionError] if PostgreSQL rejects the command
|
|
60
|
+
def start_replication: () -> untyped
|
|
61
|
+
|
|
62
|
+
# Receive one CopyData payload from the server.
|
|
63
|
+
#
|
|
64
|
+
# The call is non-blocking because the underlying `pg` call receives
|
|
65
|
+
# `false` for its blocking argument. `nil` means no complete CopyData
|
|
66
|
+
# payload is currently available.
|
|
67
|
+
#
|
|
68
|
+
# @return [String, nil] raw CopyData payload or `nil`
|
|
69
|
+
# @raise [ConnectionError] if receiving fails
|
|
70
|
+
def get_copy_data: () -> untyped
|
|
71
|
+
|
|
72
|
+
# Send one CopyData payload to the server.
|
|
73
|
+
#
|
|
74
|
+
# Used for standby status feedback messages.
|
|
75
|
+
#
|
|
76
|
+
# @param payload [String] raw CopyData payload
|
|
77
|
+
# @return [void]
|
|
78
|
+
# @raise [ConnectionError] if sending fails
|
|
79
|
+
def put_copy_data: (untyped payload) -> untyped
|
|
80
|
+
|
|
81
|
+
# Close the PostgreSQL connection if it is still open.
|
|
82
|
+
#
|
|
83
|
+
# @return [void]
|
|
84
|
+
def close: () -> (untyped | nil)
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def exec: (untyped sql) -> untyped
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Pgoutput
|
|
2
|
+
module Client
|
|
3
|
+
# Base error class for all pgoutput-client failures.
|
|
4
|
+
#
|
|
5
|
+
# Rescue this class when callers want to handle any error raised by the
|
|
6
|
+
# transport layer without also rescuing unrelated Ruby or PostgreSQL driver
|
|
7
|
+
# exceptions.
|
|
8
|
+
#
|
|
9
|
+
# @api public
|
|
10
|
+
class Error < StandardError
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Raised when stream configuration is invalid.
|
|
14
|
+
#
|
|
15
|
+
# Examples include an empty publication list, invalid replication slot name,
|
|
16
|
+
# invalid publication name, non-positive protocol version, or non-positive
|
|
17
|
+
# feedback interval.
|
|
18
|
+
#
|
|
19
|
+
# @api public
|
|
20
|
+
class ConfigurationError < Error
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Raised when a replication protocol envelope cannot be parsed.
|
|
24
|
+
#
|
|
25
|
+
# This error represents malformed or unexpected CopyData payloads at the
|
|
26
|
+
# transport-envelope level. It does not describe pgoutput plugin payload
|
|
27
|
+
# parsing errors; those belong to the parser layer.
|
|
28
|
+
#
|
|
29
|
+
# @api public
|
|
30
|
+
class ProtocolError < Error
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Raised when a PostgreSQL replication connection operation fails.
|
|
34
|
+
#
|
|
35
|
+
# `Connection` converts `PG::Error` instances into this error so public
|
|
36
|
+
# callers do not need to depend on the PostgreSQL driver's exception classes
|
|
37
|
+
# for transport-level handling.
|
|
38
|
+
#
|
|
39
|
+
# @api public
|
|
40
|
+
class ConnectionError < Error
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|