18
18
</para>
19
19
20
20
<para>
21
- This document describes version 3.0 of the protocol, implemented in
22
- <productname>PostgreSQL</productname> 7.4 and later. For descriptions
23
- of the earlier protocol versions, see previous releases of the
24
- <productname>PostgreSQL</productname> documentation. A single server
25
- can support multiple protocol versions. The initial startup-request
26
- message tells the server which protocol version the client is attempting to
27
- use. If the major version requested by the client is not supported by
28
- the server, the connection will be rejected (for example, this would occur
29
- if the client requested protocol version 4.0, which does not exist as of
30
- this writing). If the minor version requested by the client is not
31
- supported by the server (e.g., the client requests version 3.1, but the
32
- server supports only 3.0), the server may either reject the connection or
33
- may respond with a NegotiateProtocolVersion message containing the highest
34
- minor protocol version which it supports. The client may then choose either
35
- to continue with the connection using the specified protocol version or
36
- to abort the connection.
21
+ This document describes version 3.2 of the protocol, introduced in
22
+ <productname>PostgreSQL</productname> version 17. The server and the libpq
23
+ client library is compatible with protocol version 3.0, implemented in
24
+ <productname>PostgreSQL</productname> 7.4 and later.
37
25
</para>
38
26
39
27
<para>
199
187
server versions; the text format is usually the more portable choice.
200
188
</para>
201
189
</sect2>
190
+
191
+ <sect2 id="protocol-versions">
192
+ <title>Protocol versions</title>
193
+
194
+ <para>
195
+ The current, latest version of the protocol is version 3.2. For backwards
196
+ compatibility with old server versions and middleware that don't support
197
+ the version negotiation yet, the libpq library still uses protocol version
198
+ 3.0 by default however.
199
+ </para>
200
+
201
+ <para>
202
+ A single server can support multiple protocol versions. The initial
203
+ startup-request message tells the server which protocol version the client
204
+ is attempting to use. If the major version requested by the client is not
205
+ supported by the server, the connection will be rejected (for example,
206
+ this would occur if the client requested protocol version 4.0, which does
207
+ not exist as of this writing). If the minor version requested by the
208
+ client is not supported by the server (e.g., the client requests version
209
+ 3.2, but the server supports only 3.0), the server may either reject the
210
+ connection or may respond with a NegotiateProtocolVersion message
211
+ containing the highest minor protocol version which it supports. The
212
+ client may then choose either to continue with the connection using the
213
+ specified protocol version or to abort the connection.
214
+ </para>
215
+
216
+ <para>
217
+ The protocol negotiation was introduced in
218
+ <productname>PostgreSQL</productname> version 9.3.21. Earlier versions
219
+ would reject the connection if the client requested a minor version that
220
+ was not supported by the server.
221
+ </para>
222
+
223
+ <table>
224
+ <title>Protocol versions</title>
225
+
226
+ <tgroup cols="2">
227
+ <thead>
228
+ <row>
229
+ <entry>Version</entry>
230
+ <entry>Supported by</entry>
231
+ <entry>Description</entry>
232
+ </row>
233
+ </thead>
234
+
235
+ <tbody>
236
+ <row>
237
+ <entry>3.2</entry>
238
+ <entry>PostgreSQL 18 and later</entry>
239
+ <entry>Current latest version. The secret key used in query
240
+ cancellation was enlarged from 4 bytes to a variable length field. The
241
+ BackendKeyData message was changed to accomodate that, and the CancelRequest
242
+ message was redefined to have a variable length payload.
243
+ </entry>
244
+ </row>
245
+ <row>
246
+ <entry>3.1</entry>
247
+ <entry>-</entry>
248
+ <entry>Reserved. Version 3.1 has not been used by any PostgreSQL
249
+ version, but it was skipped because old versions of the popular
250
+ pgbouncer application had a bug in the protocol negotiation which made
251
+ it incorrectly claim that it supported version 3.1.
252
+ </entry>
253
+ </row>
254
+ <row>
255
+ <entry>3.0</entry>
256
+ <entry>PostgreSQL 7.4 and later</entry>
257
+ </row>
258
+ <row>
259
+ <entry>2.0</entry>
260
+ <entry>up to PostgreSQL 13</entry>
261
+ <entry>See previous releases of
262
+ the <productname>PostgreSQL</productname> documentation for
263
+ details</entry>
264
+ </row>
265
+ </tbody>
266
+ </tgroup>
267
+ </table>
268
+ </sect2>
202
269
</sect1>
203
270
204
271
<sect1 id="protocol-flow">
413
480
this message indicates the highest supported minor version. This
414
481
message will also be sent if the client requested unsupported protocol
415
482
options (i.e., beginning with <literal>_pq_.</literal>) in the
416
- startup packet. This message will be followed by an ErrorResponse or
417
- a message indicating the success or failure of authentication.
483
+ startup packet.
484
+ </para>
485
+ <para>
486
+ After this message, the authentication will continue using the version
487
+ indicated by the server. If the client does not support the older
488
+ version, it should immediately close the connection. If the server
489
+ does not send this message, it supports the client's requested
490
+ protocol version and all the protocol options.
418
491
</para>
419
492
</listitem>
420
493
</varlistentry>
@@ -3624,10 +3697,10 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
3624
3697
indicate that it can be sent by a frontend (F), a backend (B), or both
3625
3698
(F & B).
3626
3699
Notice that although each message includes a byte count at the beginning,
3627
- the message format is defined so that the message end can be found without
3628
- reference to the byte count. This aids validity checking. (The CopyData
3629
- message is an exception, because it forms part of a data stream; the contents
3630
- of any individual CopyData message cannot be interpretable on their own.)
3700
+ most messages are defined so that the message end can be found without
3701
+ reference to the byte count. This is mostly for historical reasons, as
3702
+ the original, now-obsolete protocol version 2 did not have an explicit length
3703
+ field, but it also aids validity checking.
3631
3704
</para>
3632
3705
3633
3706
<variablelist>
@@ -4043,7 +4116,7 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
4043
4116
</varlistentry>
4044
4117
4045
4118
<varlistentry>
4046
- <term>Int32(12) </term>
4119
+ <term>Int32</term>
4047
4120
<listitem>
4048
4121
<para>
4049
4122
Length of message contents in bytes, including self.
@@ -4061,14 +4134,18 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
4061
4134
</varlistentry>
4062
4135
4063
4136
<varlistentry>
4064
- <term>Int32 </term>
4137
+ <term>Byte<replaceable>n</replaceable> </term>
4065
4138
<listitem>
4066
4139
<para>
4067
- The secret key of this backend.
4140
+ The secret key of this backend. This field extends to the end of the
4141
+ message, indicated by the length field. The maximum key length is 256 bytes.
4068
4142
</para>
4069
4143
</listitem>
4070
4144
</varlistentry>
4071
4145
</variablelist>
4146
+ <para>
4147
+ Before protocol version 3.2, the secret key was always 4 bytes long.
4148
+ </para>
4072
4149
</listitem>
4073
4150
</varlistentry>
4074
4151
@@ -4274,14 +4351,18 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
4274
4351
</varlistentry>
4275
4352
4276
4353
<varlistentry>
4277
- <term>Int32 </term>
4354
+ <term>Byte<replaceable>n</replaceable> </term>
4278
4355
<listitem>
4279
4356
<para>
4280
- The secret key for the target backend.
4357
+ The secret key for the target backend. This field extends to the end of the
4358
+ message, indicated by the length field. The maximum key length is 256 bytes.
4281
4359
</para>
4282
4360
</listitem>
4283
4361
</varlistentry>
4284
4362
</variablelist>
4363
+ <para>
4364
+ Before protocol version 3.2, the secret key was always 4 bytes long.
4365
+ </para>
4285
4366
</listitem>
4286
4367
</varlistentry>
4287
4368
0 commit comments