]> begriffs open source - ai-pg/blob - full-docs/txt/protocol-logicalrep-message-formats.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / protocol-logicalrep-message-formats.txt
1
2 54.9. Logical Replication Message Formats #
3
4    This section describes the detailed format of each logical replication
5    message. These messages are either returned by the replication slot SQL
6    interface or are sent by a walsender. In the case of a walsender, they
7    are encapsulated inside replication protocol WAL messages as described
8    in Section 54.4, and generally obey the same message flow as physical
9    replication.
10
11    Begin #
12
13         Byte1('B')
14                 Identifies the message as a begin message.
15
16         Int64 (XLogRecPtr)
17                 The final LSN of the transaction.
18
19         Int64 (TimestampTz)
20                 Commit timestamp of the transaction. The value is in
21                 number of microseconds since PostgreSQL epoch
22                 (2000-01-01).
23
24         Int32 (TransactionId)
25                 Xid of the transaction.
26
27    Message #
28
29         Byte1('M')
30                 Identifies the message as a logical decoding message.
31
32         Int32 (TransactionId)
33                 Xid of the transaction (only present for streamed
34                 transactions). This field is available since protocol
35                 version 2.
36
37         Int8
38                 Flags; Either 0 for no flags or 1 if the logical decoding
39                 message is transactional.
40
41         Int64 (XLogRecPtr)
42                 The LSN of the logical decoding message.
43
44         String
45                 The prefix of the logical decoding message.
46
47         Int32
48                 Length of the content.
49
50         Byten
51                 The content of the logical decoding message.
52
53    Commit #
54
55         Byte1('C')
56                 Identifies the message as a commit message.
57
58         Int8(0)
59                 Flags; currently unused.
60
61         Int64 (XLogRecPtr)
62                 The LSN of the commit.
63
64         Int64 (XLogRecPtr)
65                 The end LSN of the transaction.
66
67         Int64 (TimestampTz)
68                 Commit timestamp of the transaction. The value is in
69                 number of microseconds since PostgreSQL epoch
70                 (2000-01-01).
71
72    Origin #
73
74         Byte1('O')
75                 Identifies the message as an origin message.
76
77         Int64 (XLogRecPtr)
78                 The LSN of the commit on the origin server.
79
80         String
81                 Name of the origin.
82
83           Note that there can be multiple Origin messages inside a single
84           transaction.
85
86    Relation #
87
88         Byte1('R')
89                 Identifies the message as a relation message.
90
91         Int32 (TransactionId)
92                 Xid of the transaction (only present for streamed
93                 transactions). This field is available since protocol
94                 version 2.
95
96         Int32 (Oid)
97                 OID of the relation.
98
99         String
100                 Namespace (empty string for pg_catalog).
101
102         String
103                 Relation name.
104
105         Int8
106                 Replica identity setting for the relation (same as
107                 relreplident in pg_class).
108
109         Int16
110                 Number of columns.
111
112           Next, the following message part appears for each column
113           included in the publication:
114
115         Int8
116                 Flags for the column. Currently can be either 0 for no
117                 flags or 1 which marks the column as part of the key.
118
119         String
120                 Name of the column.
121
122         Int32 (Oid)
123                 OID of the column's data type.
124
125         Int32
126                 Type modifier of the column (atttypmod).
127
128    Type #
129
130         Byte1('Y')
131                 Identifies the message as a type message.
132
133         Int32 (TransactionId)
134                 Xid of the transaction (only present for streamed
135                 transactions). This field is available since protocol
136                 version 2.
137
138         Int32 (Oid)
139                 OID of the data type.
140
141         String
142                 Namespace (empty string for pg_catalog).
143
144         String
145                 Name of the data type.
146
147    Insert #
148
149         Byte1('I')
150                 Identifies the message as an insert message.
151
152         Int32 (TransactionId)
153                 Xid of the transaction (only present for streamed
154                 transactions). This field is available since protocol
155                 version 2.
156
157         Int32 (Oid)
158                 OID of the relation corresponding to the ID in the
159                 relation message.
160
161         Byte1('N')
162                 Identifies the following TupleData message as a new tuple.
163
164         TupleData
165                 TupleData message part representing the contents of new
166                 tuple.
167
168    Update #
169
170         Byte1('U')
171                 Identifies the message as an update message.
172
173         Int32 (TransactionId)
174                 Xid of the transaction (only present for streamed
175                 transactions). This field is available since protocol
176                 version 2.
177
178         Int32 (Oid)
179                 OID of the relation corresponding to the ID in the
180                 relation message.
181
182         Byte1('K')
183                 Identifies the following TupleData submessage as a key.
184                 This field is optional and is only present if the update
185                 changed data in any of the column(s) that are part of the
186                 REPLICA IDENTITY index.
187
188         Byte1('O')
189                 Identifies the following TupleData submessage as an old
190                 tuple. This field is optional and is only present if table
191                 in which the update happened has REPLICA IDENTITY set to
192                 FULL.
193
194         TupleData
195                 TupleData message part representing the contents of the
196                 old tuple or primary key. Only present if the previous 'O'
197                 or 'K' part is present.
198
199         Byte1('N')
200                 Identifies the following TupleData message as a new tuple.
201
202         TupleData
203                 TupleData message part representing the contents of a new
204                 tuple.
205
206           The Update message may contain either a 'K' message part or an
207           'O' message part or neither of them, but never both of them.
208
209    Delete #
210
211         Byte1('D')
212                 Identifies the message as a delete message.
213
214         Int32 (TransactionId)
215                 Xid of the transaction (only present for streamed
216                 transactions). This field is available since protocol
217                 version 2.
218
219         Int32 (Oid)
220                 OID of the relation corresponding to the ID in the
221                 relation message.
222
223         Byte1('K')
224                 Identifies the following TupleData submessage as a key.
225                 This field is present if the table in which the delete has
226                 happened uses an index as REPLICA IDENTITY.
227
228         Byte1('O')
229                 Identifies the following TupleData message as an old
230                 tuple. This field is present if the table in which the
231                 delete happened has REPLICA IDENTITY set to FULL.
232
233         TupleData
234                 TupleData message part representing the contents of the
235                 old tuple or primary key, depending on the previous field.
236
237           The Delete message may contain either a 'K' message part or an
238           'O' message part, but never both of them.
239
240    Truncate #
241
242         Byte1('T')
243                 Identifies the message as a truncate message.
244
245         Int32 (TransactionId)
246                 Xid of the transaction (only present for streamed
247                 transactions). This field is available since protocol
248                 version 2.
249
250         Int32
251                 Number of relations
252
253         Int8
254                 Option bits for TRUNCATE: 1 for CASCADE, 2 for RESTART
255                 IDENTITY
256
257         Int32 (Oid)
258                 OID of the relation corresponding to the ID in the
259                 relation message. This field is repeated for each
260                 relation.
261
262    The following messages (Stream Start, Stream Stop, Stream Commit, and
263    Stream Abort) are available since protocol version 2.
264
265    Stream Start #
266
267         Byte1('S')
268                 Identifies the message as a stream start message.
269
270         Int32 (TransactionId)
271                 Xid of the transaction.
272
273         Int8
274                 A value of 1 indicates this is the first stream segment
275                 for this XID, 0 for any other stream segment.
276
277    Stream Stop #
278
279         Byte1('E')
280                 Identifies the message as a stream stop message.
281
282    Stream Commit #
283
284         Byte1('c')
285                 Identifies the message as a stream commit message.
286
287         Int32 (TransactionId)
288                 Xid of the transaction.
289
290         Int8(0)
291                 Flags; currently unused.
292
293         Int64 (XLogRecPtr)
294                 The LSN of the commit.
295
296         Int64 (XLogRecPtr)
297                 The end LSN of the transaction.
298
299         Int64 (TimestampTz)
300                 Commit timestamp of the transaction. The value is in
301                 number of microseconds since PostgreSQL epoch
302                 (2000-01-01).
303
304    Stream Abort #
305
306         Byte1('A')
307                 Identifies the message as a stream abort message.
308
309         Int32 (TransactionId)
310                 Xid of the transaction.
311
312         Int32 (TransactionId)
313                 Xid of the subtransaction (will be same as xid of the
314                 transaction for top-level transactions).
315
316         Int64 (XLogRecPtr)
317                 The LSN of the abort operation, present only when
318                 streaming is set to parallel. This field is available
319                 since protocol version 4.
320
321         Int64 (TimestampTz)
322                 Abort timestamp of the transaction, present only when
323                 streaming is set to parallel. The value is in number of
324                 microseconds since PostgreSQL epoch (2000-01-01). This
325                 field is available since protocol version 4.
326
327    The following messages (Begin Prepare, Prepare, Commit Prepared,
328    Rollback Prepared, Stream Prepare) are available since protocol version
329    3.
330
331    Begin Prepare #
332
333         Byte1('b')
334                 Identifies the message as the beginning of a prepared
335                 transaction message.
336
337         Int64 (XLogRecPtr)
338                 The LSN of the prepare.
339
340         Int64 (XLogRecPtr)
341                 The end LSN of the prepared transaction.
342
343         Int64 (TimestampTz)
344                 Prepare timestamp of the transaction. The value is in
345                 number of microseconds since PostgreSQL epoch
346                 (2000-01-01).
347
348         Int32 (TransactionId)
349                 Xid of the transaction.
350
351         String
352                 The user defined GID of the prepared transaction.
353
354    Prepare #
355
356         Byte1('P')
357                 Identifies the message as a prepared transaction message.
358
359         Int8(0)
360                 Flags; currently unused.
361
362         Int64 (XLogRecPtr)
363                 The LSN of the prepare.
364
365         Int64 (XLogRecPtr)
366                 The end LSN of the prepared transaction.
367
368         Int64 (TimestampTz)
369                 Prepare timestamp of the transaction. The value is in
370                 number of microseconds since PostgreSQL epoch
371                 (2000-01-01).
372
373         Int32 (TransactionId)
374                 Xid of the transaction.
375
376         String
377                 The user defined GID of the prepared transaction.
378
379    Commit Prepared #
380
381         Byte1('K')
382                 Identifies the message as the commit of a prepared
383                 transaction message.
384
385         Int8(0)
386                 Flags; currently unused.
387
388         Int64 (XLogRecPtr)
389                 The LSN of the commit of the prepared transaction.
390
391         Int64 (XLogRecPtr)
392                 The end LSN of the commit of the prepared transaction.
393
394         Int64 (TimestampTz)
395                 Commit timestamp of the transaction. The value is in
396                 number of microseconds since PostgreSQL epoch
397                 (2000-01-01).
398
399         Int32 (TransactionId)
400                 Xid of the transaction.
401
402         String
403                 The user defined GID of the prepared transaction.
404
405    Rollback Prepared #
406
407         Byte1('r')
408                 Identifies the message as the rollback of a prepared
409                 transaction message.
410
411         Int8(0)
412                 Flags; currently unused.
413
414         Int64 (XLogRecPtr)
415                 The end LSN of the prepared transaction.
416
417         Int64 (XLogRecPtr)
418                 The end LSN of the rollback of the prepared transaction.
419
420         Int64 (TimestampTz)
421                 Prepare timestamp of the transaction. The value is in
422                 number of microseconds since PostgreSQL epoch
423                 (2000-01-01).
424
425         Int64 (TimestampTz)
426                 Rollback timestamp of the transaction. The value is in
427                 number of microseconds since PostgreSQL epoch
428                 (2000-01-01).
429
430         Int32 (TransactionId)
431                 Xid of the transaction.
432
433         String
434                 The user defined GID of the prepared transaction.
435
436    Stream Prepare #
437
438         Byte1('p')
439                 Identifies the message as a stream prepared transaction
440                 message.
441
442         Int8(0)
443                 Flags; currently unused.
444
445         Int64 (XLogRecPtr)
446                 The LSN of the prepare.
447
448         Int64 (XLogRecPtr)
449                 The end LSN of the prepared transaction.
450
451         Int64 (TimestampTz)
452                 Prepare timestamp of the transaction. The value is in
453                 number of microseconds since PostgreSQL epoch
454                 (2000-01-01).
455
456         Int32 (TransactionId)
457                 Xid of the transaction.
458
459         String
460                 The user defined GID of the prepared transaction.
461
462    The following message parts are shared by the above messages.
463
464    TupleData #
465
466         Int16
467                 Number of columns.
468
469           Next, one of the following submessages appears for each
470           published column:
471
472         Byte1('n')
473                 Identifies the data as NULL value.
474
475           Or
476
477         Byte1('u')
478                 Identifies unchanged TOASTed value (the actual value is
479                 not sent).
480
481           Or
482
483         Byte1('t')
484                 Identifies the data as text formatted value.
485
486           Or
487
488         Byte1('b')
489                 Identifies the data as binary formatted value.
490
491         Int32
492                 Length of the column value.
493
494         Byten
495                 The value of the column, either in binary or in text
496                 format. (As specified in the preceding format byte). n is
497                 the above length.