This section describes the detailed format of each logical replication message. These messages are either returned by the replication slot SQL interface or are sent by a walsender. In the case of a walsender, they are encapsulated inside replication protocol WAL messages as described in Section 57.4, and generally obey the same message flow as physical replication.
Identifies the message as a begin message.
The final LSN of the transaction.
Commit timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Xid of the transaction.
Identifies the message as a logical decoding message.
Xid of the transaction (only present for streamed transactions). This field is available since protocol version 2.
Flags; Either 0 for no flags or 1 if the logical decoding message is transactional.
The LSN of the logical decoding message.
The prefix of the logical decoding message.
Length of the content.
n
The content of the logical decoding message.
Identifies the message as a commit message.
Flags; currently unused.
The LSN of the commit.
The end LSN of the transaction.
Commit timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Identifies the message as an origin message.
The LSN of the commit on the origin server.
Name of the origin.
Note that there can be multiple Origin messages inside a single transaction.
Identifies the message as a relation message.
Xid of the transaction (only present for streamed transactions). This field is available since protocol version 2.
OID of the relation.
Namespace (empty string for pg_catalog
).
Relation name.
Replica identity setting for the relation (same as
relreplident
in pg_class
).
Number of columns.
Next, the following message part appears for each column included in the publication (except generated columns):
Flags for the column. Currently can be either 0 for no flags or 1 which marks the column as part of the key.
Name of the column.
OID of the column's data type.
Type modifier of the column (atttypmod
).
Identifies the message as a type message.
Xid of the transaction (only present for streamed transactions). This field is available since protocol version 2.
OID of the data type.
Namespace (empty string for pg_catalog
).
Name of the data type.
Identifies the message as an insert message.
Xid of the transaction (only present for streamed transactions). This field is available since protocol version 2.
OID of the relation corresponding to the ID in the relation message.
Identifies the following TupleData message as a new tuple.
TupleData message part representing the contents of new tuple.
Identifies the message as an update message.
Xid of the transaction (only present for streamed transactions). This field is available since protocol version 2.
OID of the relation corresponding to the ID in the relation message.
Identifies the following TupleData submessage as a key. This field is optional and is only present if the update changed data in any of the column(s) that are part of the REPLICA IDENTITY index.
Identifies the following TupleData submessage as an old tuple. This field is optional and is only present if table in which the update happened has REPLICA IDENTITY set to FULL.
TupleData message part representing the contents of the old tuple or primary key. Only present if the previous 'O' or 'K' part is present.
Identifies the following TupleData message as a new tuple.
TupleData message part representing the contents of a new tuple.
The Update message may contain either a 'K' message part or an 'O' message part or neither of them, but never both of them.
Identifies the message as a delete message.
Xid of the transaction (only present for streamed transactions). This field is available since protocol version 2.
OID of the relation corresponding to the ID in the relation message.
Identifies the following TupleData submessage as a key. This field is present if the table in which the delete has happened uses an index as REPLICA IDENTITY.
Identifies the following TupleData message as an old tuple. This field is present if the table in which the delete happened has REPLICA IDENTITY set to FULL.
TupleData message part representing the contents of the old tuple or primary key, depending on the previous field.
The Delete message may contain either a 'K' message part or an 'O' message part, but never both of them.
Identifies the message as a truncate message.
Xid of the transaction (only present for streamed transactions). This field is available since protocol version 2.
Number of relations
Option bits for TRUNCATE
:
1 for CASCADE
, 2 for RESTART IDENTITY
OID of the relation corresponding to the ID in the relation message. This field is repeated for each relation.
The following messages (Stream Start, Stream Stop, Stream Commit, and Stream Abort) are available since protocol version 2.
Identifies the message as a stream start message.
Xid of the transaction.
A value of 1 indicates this is the first stream segment for this XID, 0 for any other stream segment.
Identifies the message as a stream stop message.
Identifies the message as a stream commit message.
Xid of the transaction.
Flags; currently unused.
The LSN of the commit.
The end LSN of the transaction.
Commit timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Identifies the message as a stream abort message.
Xid of the transaction.
Xid of the subtransaction (will be same as xid of the transaction for top-level transactions).
The following messages (Begin Prepare, Prepare, Commit Prepared, Rollback Prepared, Stream Prepare) are available since protocol version 3.
Identifies the message as the beginning of a prepared transaction message.
The LSN of the prepare.
The end LSN of the prepared transaction.
Prepare timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Xid of the transaction.
The user defined GID of the prepared transaction.
Identifies the message as a prepared transaction message.
Flags; currently unused.
The LSN of the prepare.
The end LSN of the prepared transaction.
Prepare timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Xid of the transaction.
The user defined GID of the prepared transaction.
Identifies the message as the commit of a prepared transaction message.
Flags; currently unused.
The LSN of the commit of the prepared transaction.
The end LSN of the commit of the prepared transaction.
Commit timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Xid of the transaction.
The user defined GID of the prepared transaction.
Identifies the message as the rollback of a prepared transaction message.
Flags; currently unused.
The end LSN of the prepared transaction.
The end LSN of the rollback of the prepared transaction.
Prepare timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Rollback timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Xid of the transaction.
The user defined GID of the prepared transaction.
Identifies the message as a stream prepared transaction message.
Flags; currently unused.
The LSN of the prepare.
The end LSN of the prepared transaction.
Prepare timestamp of the transaction. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
Xid of the transaction.
The user defined GID of the prepared transaction.
The following message parts are shared by the above messages.
Number of columns.
Next, one of the following submessages appears for each column (except generated columns):
Identifies the data as NULL value.
Or
Identifies unchanged TOASTed value (the actual value is not sent).
Or
Identifies the data as text formatted value.
Or
Identifies the data as binary formatted value.
Length of the column value.
n
The value of the column, either in binary or in text format.
(As specified in the preceding format byte).
n
is the above length.