|
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>52.9. Logical Replication Message Formats</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="protocol-error-fields.html" title="52.8. Error and Notice Message Fields" /><link rel="next" href="protocol-changes.html" title="52.10. Summary of Changes since Protocol 2.0" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">52.9. Logical Replication Message Formats</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="protocol-error-fields.html" title="52.8. Error and Notice Message Fields">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="protocol.html" title="Chapter 52. Frontend/Backend Protocol">Up</a></td><th width="60%" align="center">Chapter 52. Frontend/Backend Protocol</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="protocol-changes.html" title="52.10. Summary of Changes since Protocol 2.0">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="PROTOCOL-LOGICALREP-MESSAGE-FORMATS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">52.9. Logical Replication Message Formats</h2></div></div></div><p>
- This section describes the detailed format of each logical replication message.
- These messages are returned either by the replication slot SQL interface or are
- sent by a walsender. In case of a walsender they are encapsulated inside the replication
- protocol WAL messages as described in <a class="xref" href="protocol-replication.html" title="52.4. Streaming Replication Protocol">Section 52.4</a>
- and generally obey same message flow as physical replication.
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Begin
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('B')
- </span></dt><dd><p>
- Identifies the message as a begin message.
- </p></dd><dt><span class="term">
- Int64
- </span></dt><dd><p>
- The final LSN of the transaction.
- </p></dd><dt><span class="term">
- Int64
- </span></dt><dd><p>
- Commit timestamp of the transaction. The value is in number
- of microseconds since PostgreSQL epoch (2000-01-01).
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- Xid of the transaction.
- </p></dd></dl></div><p>
- </p></dd><dt><span class="term">
- Commit
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('C')
- </span></dt><dd><p>
- Identifies the message as a commit message.
- </p></dd><dt><span class="term">
- Int8
- </span></dt><dd><p>
- Flags; currently unused (must be 0).
- </p></dd><dt><span class="term">
- Int64
- </span></dt><dd><p>
- The LSN of the commit.
- </p></dd><dt><span class="term">
- Int64
- </span></dt><dd><p>
- The end LSN of the transaction.
- </p></dd><dt><span class="term">
- Int64
- </span></dt><dd><p>
- Commit timestamp of the transaction. The value is in number
- of microseconds since PostgreSQL epoch (2000-01-01).
- </p></dd></dl></div><p>
- </p></dd><dt><span class="term">
- Origin
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('O')
- </span></dt><dd><p>
- Identifies the message as an origin message.
- </p></dd><dt><span class="term">
- Int64
- </span></dt><dd><p>
- The LSN of the commit on the origin server.
- </p></dd><dt><span class="term">
- String
- </span></dt><dd><p>
- Name of the origin.
- </p></dd></dl></div><p>
- </p><p>
- Note that there can be multiple Origin messages inside a single transaction.
- </p></dd><dt><span class="term">
- Relation
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('R')
- </span></dt><dd><p>
- Identifies the message as a relation message.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- ID of the relation.
- </p></dd><dt><span class="term">
- String
- </span></dt><dd><p>
- Namespace (empty string for <code class="literal">pg_catalog</code>).
- </p></dd><dt><span class="term">
- String
- </span></dt><dd><p>
- Relation name.
- </p></dd><dt><span class="term">
- Int8
- </span></dt><dd><p>
- Replica identity setting for the relation (same as
- <code class="structfield">relreplident</code> in <code class="structname">pg_class</code>).
- </p></dd><dt><span class="term">
- Int16
- </span></dt><dd><p>
- Number of columns.
- </p></dd></dl></div><p>
- Next, the following message part appears for each column (except generated columns):
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Int8
- </span></dt><dd><p>
- Flags for the column. Currently can be either 0 for no flags
- or 1 which marks the column as part of the key.
- </p></dd><dt><span class="term">
- String
- </span></dt><dd><p>
- Name of the column.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- ID of the column's data type.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- Type modifier of the column (<code class="structfield">atttypmod</code>).
- </p></dd></dl></div><p>
- </p></dd><dt><span class="term">
- Type
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('Y')
- </span></dt><dd><p>
- Identifies the message as a type message.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- ID of the data type.
- </p></dd><dt><span class="term">
- String
- </span></dt><dd><p>
- Namespace (empty string for <code class="literal">pg_catalog</code>).
- </p></dd><dt><span class="term">
- String
- </span></dt><dd><p>
- Name of the data type.
- </p></dd></dl></div><p>
- </p></dd><dt><span class="term">
- Insert
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('I')
- </span></dt><dd><p>
- Identifies the message as an insert message.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- ID of the relation corresponding to the ID in the relation
- message.
- </p></dd><dt><span class="term">
- Byte1('N')
- </span></dt><dd><p>
- Identifies the following TupleData message as a new tuple.
- </p></dd><dt><span class="term">
- TupleData
- </span></dt><dd><p>
- TupleData message part representing the contents of new tuple.
- </p></dd></dl></div><p>
- </p></dd><dt><span class="term">
- Update
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('U')
- </span></dt><dd><p>
- Identifies the message as an update message.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- ID of the relation corresponding to the ID in the relation
- message.
- </p></dd><dt><span class="term">
- Byte1('K')
- </span></dt><dd><p>
- 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.
- </p></dd><dt><span class="term">
- Byte1('O')
- </span></dt><dd><p>
- 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.
- </p></dd><dt><span class="term">
- TupleData
- </span></dt><dd><p>
- TupleData message part representing the contents of the old tuple
- or primary key. Only present if the previous 'O' or 'K' part
- is present.
- </p></dd><dt><span class="term">
- Byte1('N')
- </span></dt><dd><p>
- Identifies the following TupleData message as a new tuple.
- </p></dd><dt><span class="term">
- TupleData
- </span></dt><dd><p>
- TupleData message part representing the contents of a new tuple.
- </p></dd></dl></div><p>
- </p><p>
- The Update message may contain either a 'K' message part or an 'O' message part
- or neither of them, but never both of them.
- </p></dd><dt><span class="term">
- Delete
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('D')
- </span></dt><dd><p>
- Identifies the message as a delete message.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- ID of the relation corresponding to the ID in the relation
- message.
- </p></dd><dt><span class="term">
- Byte1('K')
- </span></dt><dd><p>
- 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.
- </p></dd><dt><span class="term">
- Byte1('O')
- </span></dt><dd><p>
- Identifies the following TupleData message as a old tuple.
- This field is present if the table in which the delete has
- happened has REPLICA IDENTITY set to FULL.
- </p></dd><dt><span class="term">
- TupleData
- </span></dt><dd><p>
- TupleData message part representing the contents of the old tuple
- or primary key, depending on the previous field.
- </p></dd></dl></div><p>
- </p><p>
- The Delete message may contain either a 'K' message part or an 'O' message part,
- but never both of them.
- </p></dd><dt><span class="term">
- Truncate
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('T')
- </span></dt><dd><p>
- Identifies the message as a truncate message.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- Number of relations
- </p></dd><dt><span class="term">
- Int8
- </span></dt><dd><p>
- Option bits for <code class="command">TRUNCATE</code>:
- 1 for <code class="literal">CASCADE</code>, 2 for <code class="literal">RESTART IDENTITY</code>
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- ID of the relation corresponding to the ID in the relation
- message. This field is repeated for each relation.
- </p></dd></dl></div><p>
- </p></dd></dl></div><p>
-
- The following message parts are shared by the above messages.
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- TupleData
- </span></dt><dd><p>
-
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Int16
- </span></dt><dd><p>
- Number of columns.
- </p></dd></dl></div><p>
- Next, one of the following submessages appears for each column (except generated columns):
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('n')
- </span></dt><dd><p>
- Identifies the data as NULL value.
- </p></dd></dl></div><p>
- Or
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('u')
- </span></dt><dd><p>
- Identifies unchanged TOASTed value (the actual value is not
- sent).
- </p></dd></dl></div><p>
- Or
- </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
- Byte1('t')
- </span></dt><dd><p>
- Identifies the data as text formatted value.
- </p></dd><dt><span class="term">
- Int32
- </span></dt><dd><p>
- Length of the column value.
- </p></dd><dt><span class="term">
- Byte<em class="replaceable"><code>n</code></em>
- </span></dt><dd><p>
- The value of the column, in text format. (A future release
- might support additional formats.)
- <em class="replaceable"><code>n</code></em> is the above length.
-
- </p></dd></dl></div><p>
- </p></dd></dl></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="protocol-error-fields.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="protocol.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="protocol-changes.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">52.8. Error and Notice Message Fields </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 52.10. Summary of Changes since Protocol 2.0</td></tr></table></div></body></html>
|