blob: c164e3df52603ea891e717bb99808fded78c5b07 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
<?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 id="docContent" class="container-fluid col-10"><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 13.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 an old tuple.
This field is present if the table in which the delete
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 xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navfooter"><hr></hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="protocol-error-fields.html" title="52.8. Error and Notice Message Fields">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="protocol.html" title="Chapter 52. Frontend/Backend Protocol">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="protocol-changes.html" title="52.10. Summary of Changes since Protocol 2.0">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" title="PostgreSQL 13.4 Documentation">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>
|