2 54.9. Logical Replication Message Formats #
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
14 Identifies the message as a begin message.
17 The final LSN of the transaction.
20 Commit timestamp of the transaction. The value is in
21 number of microseconds since PostgreSQL epoch
25 Xid of the transaction.
30 Identifies the message as a logical decoding message.
33 Xid of the transaction (only present for streamed
34 transactions). This field is available since protocol
38 Flags; Either 0 for no flags or 1 if the logical decoding
39 message is transactional.
42 The LSN of the logical decoding message.
45 The prefix of the logical decoding message.
48 Length of the content.
51 The content of the logical decoding message.
56 Identifies the message as a commit message.
59 Flags; currently unused.
62 The LSN of the commit.
65 The end LSN of the transaction.
68 Commit timestamp of the transaction. The value is in
69 number of microseconds since PostgreSQL epoch
75 Identifies the message as an origin message.
78 The LSN of the commit on the origin server.
83 Note that there can be multiple Origin messages inside a single
89 Identifies the message as a relation message.
92 Xid of the transaction (only present for streamed
93 transactions). This field is available since protocol
100 Namespace (empty string for pg_catalog).
106 Replica identity setting for the relation (same as
107 relreplident in pg_class).
112 Next, the following message part appears for each column
113 included in the publication:
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.
123 OID of the column's data type.
126 Type modifier of the column (atttypmod).
131 Identifies the message as a type message.
133 Int32 (TransactionId)
134 Xid of the transaction (only present for streamed
135 transactions). This field is available since protocol
139 OID of the data type.
142 Namespace (empty string for pg_catalog).
145 Name of the data type.
150 Identifies the message as an insert message.
152 Int32 (TransactionId)
153 Xid of the transaction (only present for streamed
154 transactions). This field is available since protocol
158 OID of the relation corresponding to the ID in the
162 Identifies the following TupleData message as a new tuple.
165 TupleData message part representing the contents of new
171 Identifies the message as an update message.
173 Int32 (TransactionId)
174 Xid of the transaction (only present for streamed
175 transactions). This field is available since protocol
179 OID of the relation corresponding to the ID in the
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.
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
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.
200 Identifies the following TupleData message as a new tuple.
203 TupleData message part representing the contents of a new
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.
212 Identifies the message as a delete message.
214 Int32 (TransactionId)
215 Xid of the transaction (only present for streamed
216 transactions). This field is available since protocol
220 OID of the relation corresponding to the ID in the
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.
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.
234 TupleData message part representing the contents of the
235 old tuple or primary key, depending on the previous field.
237 The Delete message may contain either a 'K' message part or an
238 'O' message part, but never both of them.
243 Identifies the message as a truncate message.
245 Int32 (TransactionId)
246 Xid of the transaction (only present for streamed
247 transactions). This field is available since protocol
254 Option bits for TRUNCATE: 1 for CASCADE, 2 for RESTART
258 OID of the relation corresponding to the ID in the
259 relation message. This field is repeated for each
262 The following messages (Stream Start, Stream Stop, Stream Commit, and
263 Stream Abort) are available since protocol version 2.
268 Identifies the message as a stream start message.
270 Int32 (TransactionId)
271 Xid of the transaction.
274 A value of 1 indicates this is the first stream segment
275 for this XID, 0 for any other stream segment.
280 Identifies the message as a stream stop message.
285 Identifies the message as a stream commit message.
287 Int32 (TransactionId)
288 Xid of the transaction.
291 Flags; currently unused.
294 The LSN of the commit.
297 The end LSN of the transaction.
300 Commit timestamp of the transaction. The value is in
301 number of microseconds since PostgreSQL epoch
307 Identifies the message as a stream abort message.
309 Int32 (TransactionId)
310 Xid of the transaction.
312 Int32 (TransactionId)
313 Xid of the subtransaction (will be same as xid of the
314 transaction for top-level transactions).
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.
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.
327 The following messages (Begin Prepare, Prepare, Commit Prepared,
328 Rollback Prepared, Stream Prepare) are available since protocol version
334 Identifies the message as the beginning of a prepared
338 The LSN of the prepare.
341 The end LSN of the prepared transaction.
344 Prepare timestamp of the transaction. The value is in
345 number of microseconds since PostgreSQL epoch
348 Int32 (TransactionId)
349 Xid of the transaction.
352 The user defined GID of the prepared transaction.
357 Identifies the message as a prepared transaction message.
360 Flags; currently unused.
363 The LSN of the prepare.
366 The end LSN of the prepared transaction.
369 Prepare timestamp of the transaction. The value is in
370 number of microseconds since PostgreSQL epoch
373 Int32 (TransactionId)
374 Xid of the transaction.
377 The user defined GID of the prepared transaction.
382 Identifies the message as the commit of a prepared
386 Flags; currently unused.
389 The LSN of the commit of the prepared transaction.
392 The end LSN of the commit of the prepared transaction.
395 Commit timestamp of the transaction. The value is in
396 number of microseconds since PostgreSQL epoch
399 Int32 (TransactionId)
400 Xid of the transaction.
403 The user defined GID of the prepared transaction.
408 Identifies the message as the rollback of a prepared
412 Flags; currently unused.
415 The end LSN of the prepared transaction.
418 The end LSN of the rollback of the prepared transaction.
421 Prepare timestamp of the transaction. The value is in
422 number of microseconds since PostgreSQL epoch
426 Rollback timestamp of the transaction. The value is in
427 number of microseconds since PostgreSQL epoch
430 Int32 (TransactionId)
431 Xid of the transaction.
434 The user defined GID of the prepared transaction.
439 Identifies the message as a stream prepared transaction
443 Flags; currently unused.
446 The LSN of the prepare.
449 The end LSN of the prepared transaction.
452 Prepare timestamp of the transaction. The value is in
453 number of microseconds since PostgreSQL epoch
456 Int32 (TransactionId)
457 Xid of the transaction.
460 The user defined GID of the prepared transaction.
462 The following message parts are shared by the above messages.
469 Next, one of the following submessages appears for each
473 Identifies the data as NULL value.
478 Identifies unchanged TOASTed value (the actual value is
484 Identifies the data as text formatted value.
489 Identifies the data as binary formatted value.
492 Length of the column value.
495 The value of the column, either in binary or in text
496 format. (As specified in the preceding format byte). n is