Indent protocol.sgml
[pgsql.git] / doc / src / sgml / protocol.sgml
bloba155370a3c4786d302ae8d296205d22cbf01a1c0
1 <!-- doc/src/sgml/protocol.sgml -->
3 <chapter id="protocol">
4 <title>Frontend/Backend Protocol</title>
6 <indexterm zone="protocol">
7 <primary>protocol</primary>
8 <secondary>frontend-backend</secondary>
9 </indexterm>
11 <para>
12 <productname>PostgreSQL</productname> uses a message-based protocol
13 for communication between frontends and backends (clients and servers).
14 The protocol is supported over <acronym>TCP/IP</acronym> and also over
15 Unix-domain sockets. Port number 5432 has been registered with IANA as
16 the customary TCP port number for servers supporting this protocol, but
17 in practice any non-privileged port number can be used.
18 </para>
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.
37 </para>
39 <para>
40 In order to serve multiple clients efficiently, the server launches
41 a new <quote>backend</quote> process for each client.
42 In the current implementation, a new child
43 process is created immediately after an incoming connection is detected.
44 This is transparent to the protocol, however. For purposes of the
45 protocol, the terms <quote>backend</quote> and <quote>server</quote> are
46 interchangeable; likewise <quote>frontend</quote> and <quote>client</quote>
47 are interchangeable.
48 </para>
50 <sect1 id="protocol-overview">
51 <title>Overview</title>
53 <para>
54 The protocol has separate phases for startup and normal operation.
55 In the startup phase, the frontend opens a connection to the server
56 and authenticates itself to the satisfaction of the server. (This might
57 involve a single message, or multiple messages depending on the
58 authentication method being used.) If all goes well, the server then sends
59 status information to the frontend, and finally enters normal operation.
60 Except for the initial startup-request message, this part of the
61 protocol is driven by the server.
62 </para>
64 <para>
65 During normal operation, the frontend sends queries and
66 other commands to the backend, and the backend sends back query results
67 and other responses. There are a few cases (such as <command>NOTIFY</command>)
68 wherein the
69 backend will send unsolicited messages, but for the most part this portion
70 of a session is driven by frontend requests.
71 </para>
73 <para>
74 Termination of the session is normally by frontend choice, but can be
75 forced by the backend in certain cases. In any case, when the backend
76 closes the connection, it will roll back any open (incomplete) transaction
77 before exiting.
78 </para>
80 <para>
81 Within normal operation, SQL commands can be executed through either of
82 two sub-protocols. In the <quote>simple query</quote> protocol, the frontend
83 just sends a textual query string, which is parsed and immediately
84 executed by the backend. In the <quote>extended query</quote> protocol,
85 processing of queries is separated into multiple steps: parsing,
86 binding of parameter values, and execution. This offers flexibility
87 and performance benefits, at the cost of extra complexity.
88 </para>
90 <para>
91 Normal operation has additional sub-protocols for special operations
92 such as <command>COPY</command>.
93 </para>
95 <sect2 id="protocol-message-concepts">
96 <title>Messaging Overview</title>
98 <para>
99 All communication is through a stream of messages. The first byte of a
100 message identifies the message type, and the next four bytes specify the
101 length of the rest of the message (this length count includes itself, but
102 not the message-type byte). The remaining contents of the message are
103 determined by the message type. For historical reasons, the very first
104 message sent by the client (the startup message) has no initial
105 message-type byte.
106 </para>
108 <para>
109 To avoid losing synchronization with the message stream, both servers and
110 clients typically read an entire message into a buffer (using the byte
111 count) before attempting to process its contents. This allows easy
112 recovery if an error is detected while processing the contents. In
113 extreme situations (such as not having enough memory to buffer the
114 message), the receiver can use the byte count to determine how much
115 input to skip before it resumes reading messages.
116 </para>
118 <para>
119 Conversely, both servers and clients must take care never to send an
120 incomplete message. This is commonly done by marshaling the entire message
121 in a buffer before beginning to send it. If a communications failure
122 occurs partway through sending or receiving a message, the only sensible
123 response is to abandon the connection, since there is little hope of
124 recovering message-boundary synchronization.
125 </para>
126 </sect2>
128 <sect2 id="protocol-query-concepts">
129 <title>Extended Query Overview</title>
131 <para>
132 In the extended-query protocol, execution of SQL commands is divided
133 into multiple steps. The state retained between steps is represented
134 by two types of objects: <firstterm>prepared statements</firstterm> and
135 <firstterm>portals</firstterm>. A prepared statement represents the result of
136 parsing and semantic analysis of a textual query string.
137 A prepared statement is not in itself ready to execute, because it might
138 lack specific values for <firstterm>parameters</firstterm>. A portal represents
139 a ready-to-execute or already-partially-executed statement, with any
140 missing parameter values filled in. (For <command>SELECT</command> statements,
141 a portal is equivalent to an open cursor, but we choose to use a different
142 term since cursors don't handle non-<command>SELECT</command> statements.)
143 </para>
145 <para>
146 The overall execution cycle consists of a <firstterm>parse</firstterm> step,
147 which creates a prepared statement from a textual query string; a
148 <firstterm>bind</firstterm> step, which creates a portal given a prepared
149 statement and values for any needed parameters; and an
150 <firstterm>execute</firstterm> step that runs a portal's query. In the case of
151 a query that returns rows (<command>SELECT</command>, <command>SHOW</command>, etc),
152 the execute step can be told to fetch only
153 a limited number of rows, so that multiple execute steps might be needed
154 to complete the operation.
155 </para>
157 <para>
158 The backend can keep track of multiple prepared statements and portals
159 (but note that these exist only within a session, and are never shared
160 across sessions). Existing prepared statements and portals are
161 referenced by names assigned when they were created. In addition,
162 an <quote>unnamed</quote> prepared statement and portal exist. Although these
163 behave largely the same as named objects, operations on them are optimized
164 for the case of executing a query only once and then discarding it,
165 whereas operations on named objects are optimized on the expectation
166 of multiple uses.
167 </para>
168 </sect2>
170 <sect2 id="protocol-format-codes">
171 <title>Formats and Format Codes</title>
173 <para>
174 Data of a particular data type might be transmitted in any of several
175 different <firstterm>formats</firstterm>. As of <productname>PostgreSQL</productname> 7.4
176 the only supported formats are <quote>text</quote> and <quote>binary</quote>,
177 but the protocol makes provision for future extensions. The desired
178 format for any value is specified by a <firstterm>format code</firstterm>.
179 Clients can specify a format code for each transmitted parameter value
180 and for each column of a query result. Text has format code zero,
181 binary has format code one, and all other format codes are reserved
182 for future definition.
183 </para>
185 <para>
186 The text representation of values is whatever strings are produced
187 and accepted by the input/output conversion functions for the
188 particular data type. In the transmitted representation, there is
189 no trailing null character; the frontend must add one to received
190 values if it wants to process them as C strings.
191 (The text format does not allow embedded nulls, by the way.)
192 </para>
194 <para>
195 Binary representations for integers use network byte order (most
196 significant byte first). For other data types consult the documentation
197 or source code to learn about the binary representation. Keep in mind
198 that binary representations for complex data types might change across
199 server versions; the text format is usually the more portable choice.
200 </para>
201 </sect2>
202 </sect1>
204 <sect1 id="protocol-flow">
205 <title>Message Flow</title>
207 <para>
208 This section describes the message flow and the semantics of each
209 message type. (Details of the exact representation of each message
210 appear in <xref linkend="protocol-message-formats"/>.) There are
211 several different sub-protocols depending on the state of the
212 connection: start-up, query, function call,
213 <command>COPY</command>, and termination. There are also special
214 provisions for asynchronous operations (including notification
215 responses and command cancellation), which can occur at any time
216 after the start-up phase.
217 </para>
219 <sect2>
220 <title>Start-up</title>
222 <para>
223 To begin a session, a frontend opens a connection to the server and sends
224 a startup message. This message includes the names of the user and of the
225 database the user wants to connect to; it also identifies the particular
226 protocol version to be used. (Optionally, the startup message can include
227 additional settings for run-time parameters.)
228 The server then uses this information and
229 the contents of its configuration files (such as
230 <filename>pg_hba.conf</filename>) to determine
231 whether the connection is provisionally acceptable, and what additional
232 authentication is required (if any).
233 </para>
235 <para>
236 The server then sends an appropriate authentication request message,
237 to which the frontend must reply with an appropriate authentication
238 response message (such as a password).
239 For all authentication methods except GSSAPI, SSPI and SASL, there is at
240 most one request and one response. In some methods, no response
241 at all is needed from the frontend, and so no authentication request
242 occurs. For GSSAPI, SSPI and SASL, multiple exchanges of packets may be
243 needed to complete the authentication.
244 </para>
246 <para>
247 The authentication cycle ends with the server either rejecting the
248 connection attempt (ErrorResponse), or sending AuthenticationOk.
249 </para>
251 <para>
252 The possible messages from the server in this phase are:
254 <variablelist>
255 <varlistentry>
256 <term>ErrorResponse</term>
257 <listitem>
258 <para>
259 The connection attempt has been rejected.
260 The server then immediately closes the connection.
261 </para>
262 </listitem>
263 </varlistentry>
265 <varlistentry>
266 <term>AuthenticationOk</term>
267 <listitem>
268 <para>
269 The authentication exchange is successfully completed.
270 </para>
271 </listitem>
272 </varlistentry>
274 <varlistentry>
275 <term>AuthenticationKerberosV5</term>
276 <listitem>
277 <para>
278 The frontend must now take part in a Kerberos V5
279 authentication dialog (not described here, part of the
280 Kerberos specification) with the server. If this is
281 successful, the server responds with an AuthenticationOk,
282 otherwise it responds with an ErrorResponse. This is no
283 longer supported.
284 </para>
285 </listitem>
286 </varlistentry>
288 <varlistentry>
289 <term>AuthenticationCleartextPassword</term>
290 <listitem>
291 <para>
292 The frontend must now send a PasswordMessage containing the
293 password in clear-text form. If
294 this is the correct password, the server responds with an
295 AuthenticationOk, otherwise it responds with an ErrorResponse.
296 </para>
297 </listitem>
298 </varlistentry>
300 <varlistentry>
301 <term>AuthenticationMD5Password</term>
302 <listitem>
303 <para>
304 The frontend must now send a PasswordMessage containing the
305 password (with user name) encrypted via MD5, then encrypted
306 again using the 4-byte random salt specified in the
307 AuthenticationMD5Password message. If this is the correct
308 password, the server responds with an AuthenticationOk,
309 otherwise it responds with an ErrorResponse. The actual
310 PasswordMessage can be computed in SQL as <literal>concat('md5',
311 md5(concat(md5(concat(password, username)), random-salt)))</literal>.
312 (Keep in mind the <function>md5()</function> function returns its
313 result as a hex string.)
314 </para>
315 </listitem>
316 </varlistentry>
318 <varlistentry>
319 <term>AuthenticationSCMCredential</term>
320 <listitem>
321 <para>
322 This response is only possible for local Unix-domain connections
323 on platforms that support SCM credential messages. The frontend
324 must issue an SCM credential message and then send a single data
325 byte. (The contents of the data byte are uninteresting; it's
326 only used to ensure that the server waits long enough to receive
327 the credential message.) If the credential is acceptable,
328 the server responds with an
329 AuthenticationOk, otherwise it responds with an ErrorResponse.
330 (This message type is only issued by pre-9.1 servers. It may
331 eventually be removed from the protocol specification.)
332 </para>
333 </listitem>
334 </varlistentry>
336 <varlistentry>
337 <term>AuthenticationGSS</term>
338 <listitem>
339 <para>
340 The frontend must now initiate a GSSAPI negotiation. The frontend
341 will send a GSSResponse message with the first part of the GSSAPI
342 data stream in response to this. If further messages are needed,
343 the server will respond with AuthenticationGSSContinue.
344 </para>
345 </listitem>
346 </varlistentry>
348 <varlistentry>
349 <term>AuthenticationSSPI</term>
350 <listitem>
351 <para>
352 The frontend must now initiate an SSPI negotiation. The frontend
353 will send a GSSResponse with the first part of the SSPI
354 data stream in response to this. If further messages are needed,
355 the server will respond with AuthenticationGSSContinue.
356 </para>
357 </listitem>
359 </varlistentry>
360 <varlistentry>
361 <term>AuthenticationGSSContinue</term>
362 <listitem>
363 <para>
364 This message contains the response data from the previous step
365 of GSSAPI or SSPI negotiation (AuthenticationGSS, AuthenticationSSPI
366 or a previous AuthenticationGSSContinue). If the GSSAPI
367 or SSPI data in this message
368 indicates more data is needed to complete the authentication,
369 the frontend must send that data as another GSSResponse message. If
370 GSSAPI or SSPI authentication is completed by this message, the server
371 will next send AuthenticationOk to indicate successful authentication
372 or ErrorResponse to indicate failure.
373 </para>
374 </listitem>
375 </varlistentry>
377 <varlistentry>
378 <term>AuthenticationSASL</term>
379 <listitem>
380 <para>
381 The frontend must now initiate a SASL negotiation, using one of the
382 SASL mechanisms listed in the message. The frontend will send a
383 SASLInitialResponse with the name of the selected mechanism, and the
384 first part of the SASL data stream in response to this. If further
385 messages are needed, the server will respond with
386 AuthenticationSASLContinue. See <xref linkend="sasl-authentication"/>
387 for details.
388 </para>
389 </listitem>
390 </varlistentry>
392 <varlistentry>
393 <term>AuthenticationSASLContinue</term>
394 <listitem>
395 <para>
396 This message contains challenge data from the previous step of SASL
397 negotiation (AuthenticationSASL, or a previous
398 AuthenticationSASLContinue). The frontend must respond with a
399 SASLResponse message.
400 </para>
401 </listitem>
402 </varlistentry>
404 <varlistentry>
405 <term>AuthenticationSASLFinal</term>
406 <listitem>
407 <para>
408 SASL authentication has completed with additional mechanism-specific
409 data for the client. The server will next send AuthenticationOk to
410 indicate successful authentication, or an ErrorResponse to indicate
411 failure. This message is sent only if the SASL mechanism specifies
412 additional data to be sent from server to client at completion.
413 </para>
414 </listitem>
415 </varlistentry>
417 <varlistentry>
418 <term>NegotiateProtocolVersion</term>
419 <listitem>
420 <para>
421 The server does not support the minor protocol version requested
422 by the client, but does support an earlier version of the protocol;
423 this message indicates the highest supported minor version. This
424 message will also be sent if the client requested unsupported protocol
425 options (i.e., beginning with <literal>_pq_.</literal>) in the
426 startup packet. This message will be followed by an ErrorResponse or
427 a message indicating the success or failure of authentication.
428 </para>
429 </listitem>
430 </varlistentry>
432 </variablelist>
433 </para>
435 <para>
436 If the frontend does not support the authentication method
437 requested by the server, then it should immediately close the
438 connection.
439 </para>
441 <para>
442 After having received AuthenticationOk, the frontend must wait
443 for further messages from the server. In this phase a backend process
444 is being started, and the frontend is just an interested bystander.
445 It is still possible for the startup attempt
446 to fail (ErrorResponse) or the server to decline support for the requested
447 minor protocol version (NegotiateProtocolVersion), but in the normal case
448 the backend will send some ParameterStatus messages, BackendKeyData, and
449 finally ReadyForQuery.
450 </para>
452 <para>
453 During this phase the backend will attempt to apply any additional
454 run-time parameter settings that were given in the startup message.
455 If successful, these values become session defaults. An error causes
456 ErrorResponse and exit.
457 </para>
459 <para>
460 The possible messages from the backend in this phase are:
462 <variablelist>
463 <varlistentry>
464 <term>BackendKeyData</term>
465 <listitem>
466 <para>
467 This message provides secret-key data that the frontend must
468 save if it wants to be able to issue cancel requests later.
469 The frontend should not respond to this message, but should
470 continue listening for a ReadyForQuery message.
471 </para>
472 </listitem>
473 </varlistentry>
475 <varlistentry>
476 <term>ParameterStatus</term>
477 <listitem>
478 <para>
479 This message informs the frontend about the current (initial)
480 setting of backend parameters, such as <xref
481 linkend="guc-client-encoding"/> or <xref linkend="guc-datestyle"/>.
482 The frontend can ignore this message, or record the settings
483 for its future use; see <xref linkend="protocol-async"/> for
484 more details. The frontend should not respond to this
485 message, but should continue listening for a ReadyForQuery
486 message.
487 </para>
488 </listitem>
489 </varlistentry>
491 <varlistentry>
492 <term>ReadyForQuery</term>
493 <listitem>
494 <para>
495 Start-up is completed. The frontend can now issue commands.
496 </para>
497 </listitem>
498 </varlistentry>
500 <varlistentry>
501 <term>ErrorResponse</term>
502 <listitem>
503 <para>
504 Start-up failed. The connection is closed after sending this
505 message.
506 </para>
507 </listitem>
508 </varlistentry>
510 <varlistentry>
511 <term>NoticeResponse</term>
512 <listitem>
513 <para>
514 A warning message has been issued. The frontend should
515 display the message but continue listening for ReadyForQuery
516 or ErrorResponse.
517 </para>
518 </listitem>
519 </varlistentry>
520 </variablelist>
521 </para>
523 <para>
524 The ReadyForQuery message is the same one that the backend will
525 issue after each command cycle. Depending on the coding needs of
526 the frontend, it is reasonable to consider ReadyForQuery as
527 starting a command cycle, or to consider ReadyForQuery as ending the
528 start-up phase and each subsequent command cycle.
529 </para>
530 </sect2>
532 <sect2>
533 <title>Simple Query</title>
535 <para>
536 A simple query cycle is initiated by the frontend sending a Query message
537 to the backend. The message includes an SQL command (or commands)
538 expressed as a text string.
539 The backend then sends one or more response
540 messages depending on the contents of the query command string,
541 and finally a ReadyForQuery response message. ReadyForQuery
542 informs the frontend that it can safely send a new command.
543 (It is not actually necessary for the frontend to wait for
544 ReadyForQuery before issuing another command, but the frontend must
545 then take responsibility for figuring out what happens if the earlier
546 command fails and already-issued later commands succeed.)
547 </para>
549 <para>
550 The possible response messages from the backend are:
552 <variablelist>
553 <varlistentry>
554 <term>CommandComplete</term>
555 <listitem>
556 <para>
557 An SQL command completed normally.
558 </para>
559 </listitem>
560 </varlistentry>
562 <varlistentry>
563 <term>CopyInResponse</term>
564 <listitem>
565 <para>
566 The backend is ready to copy data from the frontend to a
567 table; see <xref linkend="protocol-copy"/>.
568 </para>
569 </listitem>
570 </varlistentry>
572 <varlistentry>
573 <term>CopyOutResponse</term>
574 <listitem>
575 <para>
576 The backend is ready to copy data from a table to the
577 frontend; see <xref linkend="protocol-copy"/>.
578 </para>
579 </listitem>
580 </varlistentry>
582 <varlistentry>
583 <term>RowDescription</term>
584 <listitem>
585 <para>
586 Indicates that rows are about to be returned in response to
587 a <command>SELECT</command>, <command>FETCH</command>, etc query.
588 The contents of this message describe the column layout of the rows.
589 This will be followed by a DataRow message for each row being returned
590 to the frontend.
591 </para>
592 </listitem>
593 </varlistentry>
595 <varlistentry>
596 <term>DataRow</term>
597 <listitem>
598 <para>
599 One of the set of rows returned by
600 a <command>SELECT</command>, <command>FETCH</command>, etc query.
601 </para>
602 </listitem>
603 </varlistentry>
605 <varlistentry>
606 <term>EmptyQueryResponse</term>
607 <listitem>
608 <para>
609 An empty query string was recognized.
610 </para>
611 </listitem>
612 </varlistentry>
614 <varlistentry>
615 <term>ErrorResponse</term>
616 <listitem>
617 <para>
618 An error has occurred.
619 </para>
620 </listitem>
621 </varlistentry>
623 <varlistentry>
624 <term>ReadyForQuery</term>
625 <listitem>
626 <para>
627 Processing of the query string is complete. A separate
628 message is sent to indicate this because the query string might
629 contain multiple SQL commands. (CommandComplete marks the
630 end of processing one SQL command, not the whole string.)
631 ReadyForQuery will always be sent, whether processing
632 terminates successfully or with an error.
633 </para>
634 </listitem>
635 </varlistentry>
637 <varlistentry>
638 <term>NoticeResponse</term>
639 <listitem>
640 <para>
641 A warning message has been issued in relation to the query.
642 Notices are in addition to other responses, i.e., the backend
643 will continue processing the command.
644 </para>
645 </listitem>
646 </varlistentry>
648 </variablelist>
649 </para>
651 <para>
652 The response to a <command>SELECT</command> query (or other queries that
653 return row sets, such as <command>EXPLAIN</command> or <command>SHOW</command>)
654 normally consists of RowDescription, zero or more
655 DataRow messages, and then CommandComplete.
656 <command>COPY</command> to or from the frontend invokes special protocol
657 as described in <xref linkend="protocol-copy"/>.
658 All other query types normally produce only
659 a CommandComplete message.
660 </para>
662 <para>
663 Since a query string could contain several queries (separated by
664 semicolons), there might be several such response sequences before the
665 backend finishes processing the query string. ReadyForQuery is issued
666 when the entire string has been processed and the backend is ready to
667 accept a new query string.
668 </para>
670 <para>
671 If a completely empty (no contents other than whitespace) query string
672 is received, the response is EmptyQueryResponse followed by ReadyForQuery.
673 </para>
675 <para>
676 In the event of an error, ErrorResponse is issued followed by
677 ReadyForQuery. All further processing of the query string is aborted by
678 ErrorResponse (even if more queries remained in it). Note that this
679 might occur partway through the sequence of messages generated by an
680 individual query.
681 </para>
683 <para>
684 In simple Query mode, the format of retrieved values is always text,
685 except when the given command is a <command>FETCH</command> from a cursor
686 declared with the <literal>BINARY</literal> option. In that case, the
687 retrieved values are in binary format. The format codes given in
688 the RowDescription message tell which format is being used.
689 </para>
691 <para>
692 A frontend must be prepared to accept ErrorResponse and
693 NoticeResponse messages whenever it is expecting any other type of
694 message. See also <xref linkend="protocol-async"/> concerning messages
695 that the backend might generate due to outside events.
696 </para>
698 <para>
699 Recommended practice is to code frontends in a state-machine style
700 that will accept any message type at any time that it could make sense,
701 rather than wiring in assumptions about the exact sequence of messages.
702 </para>
704 <sect3 id="protocol-flow-multi-statement">
705 <title>Multiple Statements in a Simple Query</title>
707 <para>
708 When a simple Query message contains more than one SQL statement
709 (separated by semicolons), those statements are executed as a single
710 transaction, unless explicit transaction control commands are included
711 to force a different behavior. For example, if the message contains
712 <programlisting>
713 INSERT INTO mytable VALUES(1);
714 SELECT 1/0;
715 INSERT INTO mytable VALUES(2);
716 </programlisting>
717 then the divide-by-zero failure in the <command>SELECT</command> will force
718 rollback of the first <command>INSERT</command>. Furthermore, because
719 execution of the message is abandoned at the first error, the second
720 <command>INSERT</command> is never attempted at all.
721 </para>
723 <para>
724 If instead the message contains
725 <programlisting>
726 BEGIN;
727 INSERT INTO mytable VALUES(1);
728 COMMIT;
729 INSERT INTO mytable VALUES(2);
730 SELECT 1/0;
731 </programlisting>
732 then the first <command>INSERT</command> is committed by the
733 explicit <command>COMMIT</command> command. The second <command>INSERT</command>
734 and the <command>SELECT</command> are still treated as a single transaction,
735 so that the divide-by-zero failure will roll back the
736 second <command>INSERT</command>, but not the first one.
737 </para>
739 <para>
740 This behavior is implemented by running the statements in a
741 multi-statement Query message in an <firstterm>implicit transaction
742 block</firstterm> unless there is some explicit transaction block for them to
743 run in. The main difference between an implicit transaction block and
744 a regular one is that an implicit block is closed automatically at the
745 end of the Query message, either by an implicit commit if there was no
746 error, or an implicit rollback if there was an error. This is similar
747 to the implicit commit or rollback that happens for a statement
748 executed by itself (when not in a transaction block).
749 </para>
751 <para>
752 If the session is already in a transaction block, as a result of
753 a <command>BEGIN</command> in some previous message, then the Query message
754 simply continues that transaction block, whether the message contains
755 one statement or several. However, if the Query message contains
756 a <command>COMMIT</command> or <command>ROLLBACK</command> closing the existing
757 transaction block, then any following statements are executed in an
758 implicit transaction block.
759 Conversely, if a <command>BEGIN</command> appears in a multi-statement Query
760 message, then it starts a regular transaction block that will only be
761 terminated by an explicit <command>COMMIT</command> or <command>ROLLBACK</command>,
762 whether that appears in this Query message or a later one.
763 If the <command>BEGIN</command> follows some statements that were executed as
764 an implicit transaction block, those statements are not immediately
765 committed; in effect, they are retroactively included into the new
766 regular transaction block.
767 </para>
769 <para>
770 A <command>COMMIT</command> or <command>ROLLBACK</command> appearing in an implicit
771 transaction block is executed as normal, closing the implicit block;
772 however, a warning will be issued since a <command>COMMIT</command>
773 or <command>ROLLBACK</command> without a previous <command>BEGIN</command> might
774 represent a mistake. If more statements follow, a new implicit
775 transaction block will be started for them.
776 </para>
778 <para>
779 Savepoints are not allowed in an implicit transaction block, since
780 they would conflict with the behavior of automatically closing the
781 block upon any error.
782 </para>
784 <para>
785 Remember that, regardless of any transaction control commands that may
786 be present, execution of the Query message stops at the first error.
787 Thus for example given
788 <programlisting>
789 BEGIN;
790 SELECT 1/0;
791 ROLLBACK;
792 </programlisting>
793 in a single Query message, the session will be left inside a failed
794 regular transaction block, since the <command>ROLLBACK</command> is not
795 reached after the divide-by-zero error. Another <command>ROLLBACK</command>
796 will be needed to restore the session to a usable state.
797 </para>
799 <para>
800 Another behavior of note is that initial lexical and syntactic
801 analysis is done on the entire query string before any of it is
802 executed. Thus simple errors (such as a misspelled keyword) in later
803 statements can prevent execution of any of the statements. This
804 is normally invisible to users since the statements would all roll
805 back anyway when done as an implicit transaction block. However,
806 it can be visible when attempting to do multiple transactions within a
807 multi-statement Query. For instance, if a typo turned our previous
808 example into
809 <programlisting>
810 BEGIN;
811 INSERT INTO mytable VALUES(1);
812 COMMIT;
813 INSERT INTO mytable VALUES(2);
814 SELCT 1/0;<!-- this typo is intentional -->
815 </programlisting>
816 then none of the statements would get run, resulting in the visible
817 difference that the first <command>INSERT</command> is not committed.
818 Errors detected at semantic analysis or later, such as a misspelled
819 table or column name, do not have this effect.
820 </para>
821 </sect3>
822 </sect2>
824 <sect2 id="protocol-flow-ext-query">
825 <title>Extended Query</title>
827 <para>
828 The extended query protocol breaks down the above-described simple
829 query protocol into multiple steps. The results of preparatory
830 steps can be re-used multiple times for improved efficiency.
831 Furthermore, additional features are available, such as the possibility
832 of supplying data values as separate parameters instead of having to
833 insert them directly into a query string.
834 </para>
836 <para>
837 In the extended protocol, the frontend first sends a Parse message,
838 which contains a textual query string, optionally some information
839 about data types of parameter placeholders, and the
840 name of a destination prepared-statement object (an empty string
841 selects the unnamed prepared statement). The response is
842 either ParseComplete or ErrorResponse. Parameter data types can be
843 specified by OID; if not given, the parser attempts to infer the
844 data types in the same way as it would do for untyped literal string
845 constants.
846 </para>
848 <note>
849 <para>
850 A parameter data type can be left unspecified by setting it to zero,
851 or by making the array of parameter type OIDs shorter than the
852 number of parameter symbols (<literal>$</literal><replaceable>n</replaceable>)
853 used in the query string. Another special case is that a parameter's
854 type can be specified as <type>void</type> (that is, the OID of the
855 <type>void</type> pseudo-type). This is meant to allow parameter symbols
856 to be used for function parameters that are actually OUT parameters.
857 Ordinarily there is no context in which a <type>void</type> parameter
858 could be used, but if such a parameter symbol appears in a function's
859 parameter list, it is effectively ignored. For example, a function
860 call such as <literal>foo($1,$2,$3,$4)</literal> could match a function with
861 two IN and two OUT arguments, if <literal>$3</literal> and <literal>$4</literal>
862 are specified as having type <type>void</type>.
863 </para>
864 </note>
866 <note>
867 <para>
868 The query string contained in a Parse message cannot include more
869 than one SQL statement; else a syntax error is reported. This
870 restriction does not exist in the simple-query protocol, but it
871 does exist in the extended protocol, because allowing prepared
872 statements or portals to contain multiple commands would complicate
873 the protocol unduly.
874 </para>
875 </note>
877 <para>
878 If successfully created, a named prepared-statement object lasts till
879 the end of the current session, unless explicitly destroyed. An unnamed
880 prepared statement lasts only until the next Parse statement specifying
881 the unnamed statement as destination is issued. (Note that a simple
882 Query message also destroys the unnamed statement.) Named prepared
883 statements must be explicitly closed before they can be redefined by
884 another Parse message, but this is not required for the unnamed statement.
885 Named prepared statements can also be created and accessed at the SQL
886 command level, using <command>PREPARE</command> and <command>EXECUTE</command>.
887 </para>
889 <para>
890 Once a prepared statement exists, it can be readied for execution using a
891 Bind message. The Bind message gives the name of the source prepared
892 statement (empty string denotes the unnamed prepared statement), the name
893 of the destination portal (empty string denotes the unnamed portal), and
894 the values to use for any parameter placeholders present in the prepared
895 statement. The
896 supplied parameter set must match those needed by the prepared statement.
897 (If you declared any <type>void</type> parameters in the Parse message,
898 pass NULL values for them in the Bind message.)
899 Bind also specifies the format to use for any data returned
900 by the query; the format can be specified overall, or per-column.
901 The response is either BindComplete or ErrorResponse.
902 </para>
904 <note>
905 <para>
906 The choice between text and binary output is determined by the format
907 codes given in Bind, regardless of the SQL command involved. The
908 <literal>BINARY</literal> attribute in cursor declarations is irrelevant when
909 using extended query protocol.
910 </para>
911 </note>
913 <para>
914 Query planning typically occurs when the Bind message is processed.
915 If the prepared statement has no parameters, or is executed repeatedly,
916 the server might save the created plan and re-use it during subsequent
917 Bind messages for the same prepared statement. However, it will do so
918 only if it finds that a generic plan can be created that is not much
919 less efficient than a plan that depends on the specific parameter values
920 supplied. This happens transparently so far as the protocol is concerned.
921 </para>
923 <para>
924 If successfully created, a named portal object lasts till the end of the
925 current transaction, unless explicitly destroyed. An unnamed portal is
926 destroyed at the end of the transaction, or as soon as the next Bind
927 statement specifying the unnamed portal as destination is issued. (Note
928 that a simple Query message also destroys the unnamed portal.) Named
929 portals must be explicitly closed before they can be redefined by another
930 Bind message, but this is not required for the unnamed portal.
931 Named portals can also be created and accessed at the SQL
932 command level, using <command>DECLARE CURSOR</command> and <command>FETCH</command>.
933 </para>
935 <para>
936 Once a portal exists, it can be executed using an Execute message.
937 The Execute message specifies the portal name (empty string denotes the
938 unnamed portal) and
939 a maximum result-row count (zero meaning <quote>fetch all rows</quote>).
940 The result-row count is only meaningful for portals
941 containing commands that return row sets; in other cases the command is
942 always executed to completion, and the row count is ignored.
943 The possible
944 responses to Execute are the same as those described above for queries
945 issued via simple query protocol, except that Execute doesn't cause
946 ReadyForQuery or RowDescription to be issued.
947 </para>
949 <para>
950 If Execute terminates before completing the execution of a portal
951 (due to reaching a nonzero result-row count), it will send a
952 PortalSuspended message; the appearance of this message tells the frontend
953 that another Execute should be issued against the same portal to
954 complete the operation. The CommandComplete message indicating
955 completion of the source SQL command is not sent until
956 the portal's execution is completed. Therefore, an Execute phase is
957 always terminated by the appearance of exactly one of these messages:
958 CommandComplete, EmptyQueryResponse (if the portal was created from
959 an empty query string), ErrorResponse, or PortalSuspended.
960 </para>
962 <para>
963 At completion of each series of extended-query messages, the frontend
964 should issue a Sync message. This parameterless message causes the
965 backend to close the current transaction if it's not inside a
966 <command>BEGIN</command>/<command>COMMIT</command> transaction block (<quote>close</quote>
967 meaning to commit if no error, or roll back if error). Then a
968 ReadyForQuery response is issued. The purpose of Sync is to provide
969 a resynchronization point for error recovery. When an error is detected
970 while processing any extended-query message, the backend issues
971 ErrorResponse, then reads and discards messages until a Sync is reached,
972 then issues ReadyForQuery and returns to normal message processing.
973 (But note that no skipping occurs if an error is detected
974 <emphasis>while</emphasis> processing Sync &mdash; this ensures that there is one
975 and only one ReadyForQuery sent for each Sync.)
976 </para>
978 <note>
979 <para>
980 Sync does not cause a transaction block opened with <command>BEGIN</command>
981 to be closed. It is possible to detect this situation since the
982 ReadyForQuery message includes transaction status information.
983 </para>
984 </note>
986 <para>
987 In addition to these fundamental, required operations, there are several
988 optional operations that can be used with extended-query protocol.
989 </para>
991 <para>
992 The Describe message (portal variant) specifies the name of an existing
993 portal (or an empty string for the unnamed portal). The response is a
994 RowDescription message describing the rows that will be returned by
995 executing the portal; or a NoData message if the portal does not contain a
996 query that will return rows; or ErrorResponse if there is no such portal.
997 </para>
999 <para>
1000 The Describe message (statement variant) specifies the name of an existing
1001 prepared statement (or an empty string for the unnamed prepared
1002 statement). The response is a ParameterDescription message describing the
1003 parameters needed by the statement, followed by a RowDescription message
1004 describing the rows that will be returned when the statement is eventually
1005 executed (or a NoData message if the statement will not return rows).
1006 ErrorResponse is issued if there is no such prepared statement. Note that
1007 since Bind has not yet been issued, the formats to be used for returned
1008 columns are not yet known to the backend; the format code fields in the
1009 RowDescription message will be zeroes in this case.
1010 </para>
1012 <tip>
1013 <para>
1014 In most scenarios the frontend should issue one or the other variant
1015 of Describe before issuing Execute, to ensure that it knows how to
1016 interpret the results it will get back.
1017 </para>
1018 </tip>
1020 <para>
1021 The Close message closes an existing prepared statement or portal
1022 and releases resources. It is not an error to issue Close against
1023 a nonexistent statement or portal name. The response is normally
1024 CloseComplete, but could be ErrorResponse if some difficulty is
1025 encountered while releasing resources. Note that closing a prepared
1026 statement implicitly closes any open portals that were constructed
1027 from that statement.
1028 </para>
1030 <para>
1031 The Flush message does not cause any specific output to be generated,
1032 but forces the backend to deliver any data pending in its output
1033 buffers. A Flush must be sent after any extended-query command except
1034 Sync, if the frontend wishes to examine the results of that command before
1035 issuing more commands. Without Flush, messages returned by the backend
1036 will be combined into the minimum possible number of packets to minimize
1037 network overhead.
1038 </para>
1040 <note>
1041 <para>
1042 The simple Query message is approximately equivalent to the series Parse,
1043 Bind, portal Describe, Execute, Close, Sync, using the unnamed prepared
1044 statement and portal objects and no parameters. One difference is that
1045 it will accept multiple SQL statements in the query string, automatically
1046 performing the bind/describe/execute sequence for each one in succession.
1047 Another difference is that it will not return ParseComplete, BindComplete,
1048 CloseComplete, or NoData messages.
1049 </para>
1050 </note>
1051 </sect2>
1053 <sect2>
1054 <title>Function Call</title>
1056 <para>
1057 The Function Call sub-protocol allows the client to request a direct
1058 call of any function that exists in the database's
1059 <structname>pg_proc</structname> system catalog. The client must have
1060 execute permission for the function.
1061 </para>
1063 <note>
1064 <para>
1065 The Function Call sub-protocol is a legacy feature that is probably best
1066 avoided in new code. Similar results can be accomplished by setting up
1067 a prepared statement that does <literal>SELECT function($1, ...)</literal>.
1068 The Function Call cycle can then be replaced with Bind/Execute.
1069 </para>
1070 </note>
1072 <para>
1073 A Function Call cycle is initiated by the frontend sending a
1074 FunctionCall message to the backend. The backend then sends one
1075 or more response messages depending on the results of the function
1076 call, and finally a ReadyForQuery response message. ReadyForQuery
1077 informs the frontend that it can safely send a new query or
1078 function call.
1079 </para>
1081 <para>
1082 The possible response messages from the backend are:
1084 <variablelist>
1085 <varlistentry>
1086 <term>ErrorResponse</term>
1087 <listitem>
1088 <para>
1089 An error has occurred.
1090 </para>
1091 </listitem>
1092 </varlistentry>
1094 <varlistentry>
1095 <term>FunctionCallResponse</term>
1096 <listitem>
1097 <para>
1098 The function call was completed and returned the result given
1099 in the message.
1100 (Note that the Function Call protocol can only handle a single
1101 scalar result, not a row type or set of results.)
1102 </para>
1103 </listitem>
1104 </varlistentry>
1106 <varlistentry>
1107 <term>ReadyForQuery</term>
1108 <listitem>
1109 <para>
1110 Processing of the function call is complete. ReadyForQuery
1111 will always be sent, whether processing terminates
1112 successfully or with an error.
1113 </para>
1114 </listitem>
1115 </varlistentry>
1117 <varlistentry>
1118 <term>NoticeResponse</term>
1119 <listitem>
1120 <para>
1121 A warning message has been issued in relation to the function
1122 call. Notices are in addition to other responses, i.e., the
1123 backend will continue processing the command.
1124 </para>
1125 </listitem>
1126 </varlistentry>
1127 </variablelist>
1128 </para>
1129 </sect2>
1131 <sect2 id="protocol-copy">
1132 <title>COPY Operations</title>
1134 <para>
1135 The <command>COPY</command> command allows high-speed bulk data transfer
1136 to or from the server. Copy-in and copy-out operations each switch
1137 the connection into a distinct sub-protocol, which lasts until the
1138 operation is completed.
1139 </para>
1141 <para>
1142 Copy-in mode (data transfer to the server) is initiated when the
1143 backend executes a <command>COPY FROM STDIN</command> SQL statement. The backend
1144 sends a CopyInResponse message to the frontend. The frontend should
1145 then send zero or more CopyData messages, forming a stream of input
1146 data. (The message boundaries are not required to have anything to do
1147 with row boundaries, although that is often a reasonable choice.)
1148 The frontend can terminate the copy-in mode by sending either a CopyDone
1149 message (allowing successful termination) or a CopyFail message (which
1150 will cause the <command>COPY</command> SQL statement to fail with an
1151 error). The backend then reverts to the command-processing mode it was
1152 in before the <command>COPY</command> started, which will be either simple or
1153 extended query protocol. It will next send either CommandComplete
1154 (if successful) or ErrorResponse (if not).
1155 </para>
1157 <para>
1158 In the event of a backend-detected error during copy-in mode (including
1159 receipt of a CopyFail message), the backend will issue an ErrorResponse
1160 message. If the <command>COPY</command> command was issued via an extended-query
1161 message, the backend will now discard frontend messages until a Sync
1162 message is received, then it will issue ReadyForQuery and return to normal
1163 processing. If the <command>COPY</command> command was issued in a simple
1164 Query message, the rest of that message is discarded and ReadyForQuery
1165 is issued. In either case, any subsequent CopyData, CopyDone, or CopyFail
1166 messages issued by the frontend will simply be dropped.
1167 </para>
1169 <para>
1170 The backend will ignore Flush and Sync messages received during copy-in
1171 mode. Receipt of any other non-copy message type constitutes an error
1172 that will abort the copy-in state as described above. (The exception for
1173 Flush and Sync is for the convenience of client libraries that always
1174 send Flush or Sync after an Execute message, without checking whether
1175 the command to be executed is a <command>COPY FROM STDIN</command>.)
1176 </para>
1178 <para>
1179 Copy-out mode (data transfer from the server) is initiated when the
1180 backend executes a <command>COPY TO STDOUT</command> SQL statement. The backend
1181 sends a CopyOutResponse message to the frontend, followed by
1182 zero or more CopyData messages (always one per row), followed by CopyDone.
1183 The backend then reverts to the command-processing mode it was
1184 in before the <command>COPY</command> started, and sends CommandComplete.
1185 The frontend cannot abort the transfer (except by closing the connection
1186 or issuing a Cancel request),
1187 but it can discard unwanted CopyData and CopyDone messages.
1188 </para>
1190 <para>
1191 In the event of a backend-detected error during copy-out mode,
1192 the backend will issue an ErrorResponse message and revert to normal
1193 processing. The frontend should treat receipt of ErrorResponse as
1194 terminating the copy-out mode.
1195 </para>
1197 <para>
1198 It is possible for NoticeResponse and ParameterStatus messages to be
1199 interspersed between CopyData messages; frontends must handle these cases,
1200 and should be prepared for other asynchronous message types as well (see
1201 <xref linkend="protocol-async"/>). Otherwise, any message type other than
1202 CopyData or CopyDone may be treated as terminating copy-out mode.
1203 </para>
1205 <para>
1206 There is another Copy-related mode called copy-both, which allows
1207 high-speed bulk data transfer to <emphasis>and</emphasis> from the server.
1208 Copy-both mode is initiated when a backend in walsender mode
1209 executes a <command>START_REPLICATION</command> statement. The
1210 backend sends a CopyBothResponse message to the frontend. Both
1211 the backend and the frontend may then send CopyData messages
1212 until either end sends a CopyDone message. After the client
1213 sends a CopyDone message, the connection goes from copy-both mode to
1214 copy-out mode, and the client may not send any more CopyData messages.
1215 Similarly, when the server sends a CopyDone message, the connection
1216 goes into copy-in mode, and the server may not send any more CopyData
1217 messages. After both sides have sent a CopyDone message, the copy mode
1218 is terminated, and the backend reverts to the command-processing mode.
1219 In the event of a backend-detected error during copy-both mode,
1220 the backend will issue an ErrorResponse message, discard frontend messages
1221 until a Sync message is received, and then issue ReadyForQuery and return
1222 to normal processing. The frontend should treat receipt of ErrorResponse
1223 as terminating the copy in both directions; no CopyDone should be sent
1224 in this case. See <xref linkend="protocol-replication"/> for more
1225 information on the subprotocol transmitted over copy-both mode.
1226 </para>
1228 <para>
1229 The CopyInResponse, CopyOutResponse and CopyBothResponse messages
1230 include fields that inform the frontend of the number of columns
1231 per row and the format codes being used for each column. (As of
1232 the present implementation, all columns in a given <command>COPY</command>
1233 operation will use the same format, but the message design does not
1234 assume this.)
1235 </para>
1237 </sect2>
1239 <sect2 id="protocol-async">
1240 <title>Asynchronous Operations</title>
1242 <para>
1243 There are several cases in which the backend will send messages that
1244 are not specifically prompted by the frontend's command stream.
1245 Frontends must be prepared to deal with these messages at any time,
1246 even when not engaged in a query.
1247 At minimum, one should check for these cases before beginning to
1248 read a query response.
1249 </para>
1251 <para>
1252 It is possible for NoticeResponse messages to be generated due to
1253 outside activity; for example, if the database administrator commands
1254 a <quote>fast</quote> database shutdown, the backend will send a NoticeResponse
1255 indicating this fact before closing the connection. Accordingly,
1256 frontends should always be prepared to accept and display NoticeResponse
1257 messages, even when the connection is nominally idle.
1258 </para>
1260 <para>
1261 ParameterStatus messages will be generated whenever the active
1262 value changes for any of the parameters the backend believes the
1263 frontend should know about. Most commonly this occurs in response
1264 to a <command>SET</command> SQL command executed by the frontend, and
1265 this case is effectively synchronous &mdash; but it is also possible
1266 for parameter status changes to occur because the administrator
1267 changed a configuration file and then sent the
1268 <systemitem>SIGHUP</systemitem> signal to the server. Also,
1269 if a <command>SET</command> command is rolled back, an appropriate
1270 ParameterStatus message will be generated to report the current
1271 effective value.
1272 </para>
1274 <para>
1275 At present there is a hard-wired set of parameters for which
1276 ParameterStatus will be generated: they are
1277 <varname>server_version</varname>,
1278 <varname>server_encoding</varname>,
1279 <varname>client_encoding</varname>,
1280 <varname>application_name</varname>,
1281 <varname>default_transaction_read_only</varname>,
1282 <varname>in_hot_standby</varname>,
1283 <varname>is_superuser</varname>,
1284 <varname>session_authorization</varname>,
1285 <varname>DateStyle</varname>,
1286 <varname>IntervalStyle</varname>,
1287 <varname>TimeZone</varname>,
1288 <varname>integer_datetimes</varname>, and
1289 <varname>standard_conforming_strings</varname>.
1290 (<varname>server_encoding</varname>, <varname>TimeZone</varname>, and
1291 <varname>integer_datetimes</varname> were not reported by releases before 8.0;
1292 <varname>standard_conforming_strings</varname> was not reported by releases
1293 before 8.1;
1294 <varname>IntervalStyle</varname> was not reported by releases before 8.4;
1295 <varname>application_name</varname> was not reported by releases before
1296 9.0;
1297 <varname>default_transaction_read_only</varname> and
1298 <varname>in_hot_standby</varname> were not reported by releases before
1299 14.)
1300 Note that
1301 <varname>server_version</varname>,
1302 <varname>server_encoding</varname> and
1303 <varname>integer_datetimes</varname>
1304 are pseudo-parameters that cannot change after startup.
1305 This set might change in the future, or even become configurable.
1306 Accordingly, a frontend should simply ignore ParameterStatus for
1307 parameters that it does not understand or care about.
1308 </para>
1310 <para>
1311 If a frontend issues a <command>LISTEN</command> command, then the
1312 backend will send a NotificationResponse message (not to be
1313 confused with NoticeResponse!) whenever a
1314 <command>NOTIFY</command> command is executed for the same
1315 channel name.
1316 </para>
1318 <note>
1319 <para>
1320 At present, NotificationResponse can only be sent outside a
1321 transaction, and thus it will not occur in the middle of a
1322 command-response series, though it might occur just before ReadyForQuery.
1323 It is unwise to design frontend logic that assumes that, however.
1324 Good practice is to be able to accept NotificationResponse at any
1325 point in the protocol.
1326 </para>
1327 </note>
1328 </sect2>
1330 <sect2>
1331 <title>Canceling Requests in Progress</title>
1333 <para>
1334 During the processing of a query, the frontend might request
1335 cancellation of the query. The cancel request is not sent
1336 directly on the open connection to the backend for reasons of
1337 implementation efficiency: we don't want to have the backend
1338 constantly checking for new input from the frontend during query
1339 processing. Cancel requests should be relatively infrequent, so
1340 we make them slightly cumbersome in order to avoid a penalty in
1341 the normal case.
1342 </para>
1344 <para>
1345 To issue a cancel request, the frontend opens a new connection to
1346 the server and sends a CancelRequest message, rather than the
1347 StartupMessage message that would ordinarily be sent across a new
1348 connection. The server will process this request and then close
1349 the connection. For security reasons, no direct reply is made to
1350 the cancel request message.
1351 </para>
1353 <para>
1354 A CancelRequest message will be ignored unless it contains the
1355 same key data (PID and secret key) passed to the frontend during
1356 connection start-up. If the request matches the PID and secret
1357 key for a currently executing backend, the processing of the
1358 current query is aborted. (In the existing implementation, this is
1359 done by sending a special signal to the backend process that is
1360 processing the query.)
1361 </para>
1363 <para>
1364 The cancellation signal might or might not have any effect &mdash; for
1365 example, if it arrives after the backend has finished processing
1366 the query, then it will have no effect. If the cancellation is
1367 effective, it results in the current command being terminated
1368 early with an error message.
1369 </para>
1371 <para>
1372 The upshot of all this is that for reasons of both security and
1373 efficiency, the frontend has no direct way to tell whether a
1374 cancel request has succeeded. It must continue to wait for the
1375 backend to respond to the query. Issuing a cancel simply improves
1376 the odds that the current query will finish soon, and improves the
1377 odds that it will fail with an error message instead of
1378 succeeding.
1379 </para>
1381 <para>
1382 Since the cancel request is sent across a new connection to the
1383 server and not across the regular frontend/backend communication
1384 link, it is possible for the cancel request to be issued by any
1385 process, not just the frontend whose query is to be canceled.
1386 This might provide additional flexibility when building
1387 multiple-process applications. It also introduces a security
1388 risk, in that unauthorized persons might try to cancel queries.
1389 The security risk is addressed by requiring a dynamically
1390 generated secret key to be supplied in cancel requests.
1391 </para>
1392 </sect2>
1394 <sect2>
1395 <title>Termination</title>
1397 <para>
1398 The normal, graceful termination procedure is that the frontend
1399 sends a Terminate message and immediately closes the connection.
1400 On receipt of this message, the backend closes the connection and
1401 terminates.
1402 </para>
1404 <para>
1405 In rare cases (such as an administrator-commanded database shutdown)
1406 the backend might disconnect without any frontend request to do so.
1407 In such cases the backend will attempt to send an error or notice message
1408 giving the reason for the disconnection before it closes the connection.
1409 </para>
1411 <para>
1412 Other termination scenarios arise from various failure cases, such as core
1413 dump at one end or the other, loss of the communications link, loss of
1414 message-boundary synchronization, etc. If either frontend or backend sees
1415 an unexpected closure of the connection, it should clean
1416 up and terminate. The frontend has the option of launching a new backend
1417 by recontacting the server if it doesn't want to terminate itself.
1418 Closing the connection is also advisable if an unrecognizable message type
1419 is received, since this probably indicates loss of message-boundary sync.
1420 </para>
1422 <para>
1423 For either normal or abnormal termination, any open transaction is
1424 rolled back, not committed. One should note however that if a
1425 frontend disconnects while a non-<command>SELECT</command> query
1426 is being processed, the backend will probably finish the query
1427 before noticing the disconnection. If the query is outside any
1428 transaction block (<command>BEGIN</command> ... <command>COMMIT</command>
1429 sequence) then its results might be committed before the
1430 disconnection is recognized.
1431 </para>
1432 </sect2>
1434 <sect2>
1435 <title><acronym>SSL</acronym> Session Encryption</title>
1437 <para>
1438 If <productname>PostgreSQL</productname> was built with
1439 <acronym>SSL</acronym> support, frontend/backend communications
1440 can be encrypted using <acronym>SSL</acronym>. This provides
1441 communication security in environments where attackers might be
1442 able to capture the session traffic. For more information on
1443 encrypting <productname>PostgreSQL</productname> sessions with
1444 <acronym>SSL</acronym>, see <xref linkend="ssl-tcp"/>.
1445 </para>
1447 <para>
1448 To initiate an <acronym>SSL</acronym>-encrypted connection, the
1449 frontend initially sends an SSLRequest message rather than a
1450 StartupMessage. The server then responds with a single byte
1451 containing <literal>S</literal> or <literal>N</literal>, indicating that it is
1452 willing or unwilling to perform <acronym>SSL</acronym>,
1453 respectively. The frontend might close the connection at this point
1454 if it is dissatisfied with the response. To continue after
1455 <literal>S</literal>, perform an <acronym>SSL</acronym> startup handshake
1456 (not described here, part of the <acronym>SSL</acronym>
1457 specification) with the server. If this is successful, continue
1458 with sending the usual StartupMessage. In this case the
1459 StartupMessage and all subsequent data will be
1460 <acronym>SSL</acronym>-encrypted. To continue after
1461 <literal>N</literal>, send the usual StartupMessage and proceed without
1462 encryption.
1463 (Alternatively, it is permissible to issue a GSSENCRequest message
1464 after an <literal>N</literal> response to try to
1465 use <acronym>GSSAPI</acronym> encryption instead
1466 of <acronym>SSL</acronym>.)
1467 </para>
1469 <para>
1470 The frontend should also be prepared to handle an ErrorMessage
1471 response to SSLRequest from the server. This would only occur if
1472 the server predates the addition of <acronym>SSL</acronym> support
1473 to <productname>PostgreSQL</productname>. (Such servers are now very ancient,
1474 and likely do not exist in the wild anymore.)
1475 In this case the connection must
1476 be closed, but the frontend might choose to open a fresh connection
1477 and proceed without requesting <acronym>SSL</acronym>.
1478 </para>
1480 <para>
1481 When <acronym>SSL</acronym> encryption can be performed, the server
1482 is expected to send only the single <literal>S</literal> byte and then
1483 wait for the frontend to initiate an <acronym>SSL</acronym> handshake.
1484 If additional bytes are available to read at this point, it likely
1485 means that a man-in-the-middle is attempting to perform a
1486 buffer-stuffing attack
1487 (<ulink url="https://www.postgresql.org/support/security/CVE-2021-23222/">CVE-2021-23222</ulink>).
1488 Frontends should be coded either to read exactly one byte from the
1489 socket before turning the socket over to their SSL library, or to
1490 treat it as a protocol violation if they find they have read additional
1491 bytes.
1492 </para>
1494 <para>
1495 An initial SSLRequest can also be used in a connection that is being
1496 opened to send a CancelRequest message.
1497 </para>
1499 <para>
1500 While the protocol itself does not provide a way for the server to
1501 force <acronym>SSL</acronym> encryption, the administrator can
1502 configure the server to reject unencrypted sessions as a byproduct
1503 of authentication checking.
1504 </para>
1505 </sect2>
1507 <sect2>
1508 <title><acronym>GSSAPI</acronym> Session Encryption</title>
1510 <para>
1511 If <productname>PostgreSQL</productname> was built with
1512 <acronym>GSSAPI</acronym> support, frontend/backend communications
1513 can be encrypted using <acronym>GSSAPI</acronym>. This provides
1514 communication security in environments where attackers might be
1515 able to capture the session traffic. For more information on
1516 encrypting <productname>PostgreSQL</productname> sessions with
1517 <acronym>GSSAPI</acronym>, see <xref linkend="gssapi-enc"/>.
1518 </para>
1520 <para>
1521 To initiate a <acronym>GSSAPI</acronym>-encrypted connection, the
1522 frontend initially sends a GSSENCRequest message rather than a
1523 StartupMessage. The server then responds with a single byte
1524 containing <literal>G</literal> or <literal>N</literal>, indicating that it
1525 is willing or unwilling to perform <acronym>GSSAPI</acronym> encryption,
1526 respectively. The frontend might close the connection at this point
1527 if it is dissatisfied with the response. To continue after
1528 <literal>G</literal>, using the GSSAPI C bindings as discussed in
1529 <ulink url="https://tools.ietf.org/html/rfc2744">RFC 2744</ulink>
1530 or equivalent, perform a <acronym>GSSAPI</acronym> initialization by
1531 calling <function>gss_init_sec_context()</function> in a loop and sending
1532 the result to the server, starting with an empty input and then with each
1533 result from the server, until it returns no output. When sending the
1534 results of <function>gss_init_sec_context()</function> to the server,
1535 prepend the length of the message as a four byte integer in network byte
1536 order.
1537 To continue after
1538 <literal>N</literal>, send the usual StartupMessage and proceed without
1539 encryption.
1540 (Alternatively, it is permissible to issue an SSLRequest message
1541 after an <literal>N</literal> response to try to
1542 use <acronym>SSL</acronym> encryption instead
1543 of <acronym>GSSAPI</acronym>.)
1544 </para>
1546 <para>
1547 The frontend should also be prepared to handle an ErrorMessage
1548 response to GSSENCRequest from the server. This would only occur if
1549 the server predates the addition of <acronym>GSSAPI</acronym> encryption
1550 support to <productname>PostgreSQL</productname>. In this case the
1551 connection must be closed, but the frontend might choose to open a fresh
1552 connection and proceed without requesting <acronym>GSSAPI</acronym>
1553 encryption.
1554 </para>
1556 <para>
1557 When <acronym>GSSAPI</acronym> encryption can be performed, the server
1558 is expected to send only the single <literal>G</literal> byte and then
1559 wait for the frontend to initiate a <acronym>GSSAPI</acronym> handshake.
1560 If additional bytes are available to read at this point, it likely
1561 means that a man-in-the-middle is attempting to perform a
1562 buffer-stuffing attack
1563 (<ulink url="https://www.postgresql.org/support/security/CVE-2021-23222/">CVE-2021-23222</ulink>).
1564 Frontends should be coded either to read exactly one byte from the
1565 socket before turning the socket over to their GSSAPI library, or to
1566 treat it as a protocol violation if they find they have read additional
1567 bytes.
1568 </para>
1570 <para>
1571 An initial GSSENCRequest can also be used in a connection that is being
1572 opened to send a CancelRequest message.
1573 </para>
1575 <para>
1576 Once <acronym>GSSAPI</acronym> encryption has been successfully
1577 established, use <function>gss_wrap()</function> to
1578 encrypt the usual StartupMessage and all subsequent data, prepending the
1579 length of the result from <function>gss_wrap()</function> as a four byte
1580 integer in network byte order to the actual encrypted payload. Note that
1581 the server will only accept encrypted packets from the client which are less
1582 than 16kB; <function>gss_wrap_size_limit()</function> should be used by the
1583 client to determine the size of the unencrypted message which will fit
1584 within this limit and larger messages should be broken up into multiple
1585 <function>gss_wrap()</function> calls. Typical segments are 8kB of
1586 unencrypted data, resulting in encrypted packets of slightly larger than 8kB
1587 but well within the 16kB maximum. The server can be expected to not send
1588 encrypted packets of larger than 16kB to the client.
1589 </para>
1591 <para>
1592 While the protocol itself does not provide a way for the server to
1593 force <acronym>GSSAPI</acronym> encryption, the administrator can
1594 configure the server to reject unencrypted sessions as a byproduct
1595 of authentication checking.
1596 </para>
1597 </sect2>
1598 </sect1>
1600 <sect1 id="sasl-authentication">
1601 <title>SASL Authentication</title>
1603 <para>
1604 <firstterm>SASL</firstterm> is a framework for authentication in connection-oriented
1605 protocols. At the moment, <productname>PostgreSQL</productname> implements two SASL
1606 authentication mechanisms, SCRAM-SHA-256 and SCRAM-SHA-256-PLUS. More
1607 might be added in the future. The below steps illustrate how SASL
1608 authentication is performed in general, while the next subsection gives
1609 more details on SCRAM-SHA-256 and SCRAM-SHA-256-PLUS.
1610 </para>
1612 <procedure>
1613 <title>SASL Authentication Message Flow</title>
1615 <step id="sasl-auth-begin">
1616 <para>
1617 To begin a SASL authentication exchange, the server sends an
1618 AuthenticationSASL message. It includes a list of SASL authentication
1619 mechanisms that the server can accept, in the server's preferred order.
1620 </para>
1621 </step>
1623 <step id="sasl-auth-initial-response">
1624 <para>
1625 The client selects one of the supported mechanisms from the list, and sends
1626 a SASLInitialResponse message to the server. The message includes the name
1627 of the selected mechanism, and an optional Initial Client Response, if the
1628 selected mechanism uses that.
1629 </para>
1630 </step>
1632 <step id="sasl-auth-continue">
1633 <para>
1634 One or more server-challenge and client-response message will follow. Each
1635 server-challenge is sent in an AuthenticationSASLContinue message, followed
1636 by a response from client in a SASLResponse message. The particulars of
1637 the messages are mechanism specific.
1638 </para>
1639 </step>
1641 <step id="sasl-auth-end">
1642 <para>
1643 Finally, when the authentication exchange is completed successfully, the
1644 server sends an AuthenticationSASLFinal message, followed
1645 immediately by an AuthenticationOk message. The AuthenticationSASLFinal
1646 contains additional server-to-client data, whose content is particular to the
1647 selected authentication mechanism. If the authentication mechanism doesn't
1648 use additional data that's sent at completion, the AuthenticationSASLFinal
1649 message is not sent.
1650 </para>
1651 </step>
1652 </procedure>
1654 <para>
1655 On error, the server can abort the authentication at any stage, and send an
1656 ErrorMessage.
1657 </para>
1659 <sect2 id="sasl-scram-sha-256">
1660 <title>SCRAM-SHA-256 Authentication</title>
1662 <para>
1663 The implemented SASL mechanisms at the moment
1664 are <literal>SCRAM-SHA-256</literal> and its variant with channel
1665 binding <literal>SCRAM-SHA-256-PLUS</literal>. They are described in
1666 detail in <ulink url="https://tools.ietf.org/html/rfc7677">RFC 7677</ulink>
1667 and <ulink url="https://tools.ietf.org/html/rfc5802">RFC 5802</ulink>.
1668 </para>
1670 <para>
1671 When SCRAM-SHA-256 is used in PostgreSQL, the server will ignore the user name
1672 that the client sends in the <structname>client-first-message</structname>. The user name
1673 that was already sent in the startup message is used instead.
1674 <productname>PostgreSQL</productname> supports multiple character encodings, while SCRAM
1675 dictates UTF-8 to be used for the user name, so it might be impossible to
1676 represent the PostgreSQL user name in UTF-8.
1677 </para>
1679 <para>
1680 The SCRAM specification dictates that the password is also in UTF-8, and is
1681 processed with the <firstterm>SASLprep</firstterm> algorithm.
1682 <productname>PostgreSQL</productname>, however, does not require UTF-8 to be used for
1683 the password. When a user's password is set, it is processed with SASLprep
1684 as if it was in UTF-8, regardless of the actual encoding used. However, if
1685 it is not a legal UTF-8 byte sequence, or it contains UTF-8 byte sequences
1686 that are prohibited by the SASLprep algorithm, the raw password will be used
1687 without SASLprep processing, instead of throwing an error. This allows the
1688 password to be normalized when it is in UTF-8, but still allows a non-UTF-8
1689 password to be used, and doesn't require the system to know which encoding
1690 the password is in.
1691 </para>
1693 <para>
1694 <firstterm>Channel binding</firstterm> is supported in PostgreSQL builds with
1695 SSL support. The SASL mechanism name for SCRAM with channel binding is
1696 <literal>SCRAM-SHA-256-PLUS</literal>. The channel binding type used by
1697 PostgreSQL is <literal>tls-server-end-point</literal>.
1698 </para>
1700 <para>
1701 In <acronym>SCRAM</acronym> without channel binding, the server chooses
1702 a random number that is transmitted to the client to be mixed with the
1703 user-supplied password in the transmitted password hash. While this
1704 prevents the password hash from being successfully retransmitted in
1705 a later session, it does not prevent a fake server between the real
1706 server and client from passing through the server's random value
1707 and successfully authenticating.
1708 </para>
1710 <para>
1711 <acronym>SCRAM</acronym> with channel binding prevents such
1712 man-in-the-middle attacks by mixing the signature of the server's
1713 certificate into the transmitted password hash. While a fake server can
1714 retransmit the real server's certificate, it doesn't have access to the
1715 private key matching that certificate, and therefore cannot prove it is
1716 the owner, causing SSL connection failure.
1717 </para>
1719 <procedure>
1720 <title>Example</title>
1721 <step id="scram-begin">
1722 <para>
1723 The server sends an AuthenticationSASL message. It includes a list of
1724 SASL authentication mechanisms that the server can accept.
1725 This will be <literal>SCRAM-SHA-256-PLUS</literal>
1726 and <literal>SCRAM-SHA-256</literal> if the server is built with SSL
1727 support, or else just the latter.
1728 </para>
1729 </step>
1731 <step id="scram-client-first">
1732 <para>
1733 The client responds by sending a SASLInitialResponse message, which
1734 indicates the chosen mechanism, <literal>SCRAM-SHA-256</literal> or
1735 <literal>SCRAM-SHA-256-PLUS</literal>. (A client is free to choose either
1736 mechanism, but for better security it should choose the channel-binding
1737 variant if it can support it.) In the Initial Client response field, the
1738 message contains the SCRAM <structname>client-first-message</structname>.
1739 The <structname>client-first-message</structname> also contains the channel
1740 binding type chosen by the client.
1741 </para>
1742 </step>
1744 <step id="scram-server-first">
1745 <para>
1746 Server sends an AuthenticationSASLContinue message, with a SCRAM
1747 <structname>server-first-message</structname> as the content.
1748 </para>
1749 </step>
1751 <step id="scram-client-final">
1752 <para>
1753 Client sends a SASLResponse message, with SCRAM
1754 <structname>client-final-message</structname> as the content.
1755 </para>
1756 </step>
1758 <step id="scram-server-final">
1759 <para>
1760 Server sends an AuthenticationSASLFinal message, with the SCRAM
1761 <structname>server-final-message</structname>, followed immediately by
1762 an AuthenticationOk message.
1763 </para>
1764 </step>
1765 </procedure>
1766 </sect2>
1767 </sect1>
1769 <sect1 id="protocol-replication">
1770 <title>Streaming Replication Protocol</title>
1772 <para>
1773 To initiate streaming replication, the frontend sends the
1774 <literal>replication</literal> parameter in the startup message. A Boolean
1775 value of <literal>true</literal> (or <literal>on</literal>,
1776 <literal>yes</literal>, <literal>1</literal>) tells the backend to go into
1777 physical replication walsender mode, wherein a small set of replication
1778 commands, shown below, can be issued instead of SQL statements.
1779 </para>
1781 <para>
1782 Passing <literal>database</literal> as the value for the
1783 <literal>replication</literal> parameter instructs the backend to go into
1784 logical replication walsender mode, connecting to the database specified in
1785 the <literal>dbname</literal> parameter. In logical replication walsender
1786 mode, the replication commands shown below as well as normal SQL commands can
1787 be issued.
1788 </para>
1790 <para>
1791 In either physical replication or logical replication walsender mode, only the
1792 simple query protocol can be used.
1793 </para>
1795 <para>
1796 For the purpose of testing replication commands, you can make a replication
1797 connection via <application>psql</application> or any other
1798 <application>libpq</application>-using tool with a connection string including
1799 the <literal>replication</literal> option,
1800 e.g.:
1801 <programlisting>
1802 psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
1803 </programlisting>
1804 However, it is often more useful to use
1805 <xref linkend="app-pgreceivewal"/> (for physical replication) or
1806 <xref linkend="app-pgrecvlogical"/> (for logical replication).
1807 </para>
1809 <para>
1810 Replication commands are logged in the server log when
1811 <xref linkend="guc-log-replication-commands"/> is enabled.
1812 </para>
1814 <para>
1815 The commands accepted in replication mode are:
1817 <variablelist>
1818 <varlistentry id="protocol-replication-identify-system">
1819 <term><literal>IDENTIFY_SYSTEM</literal>
1820 <indexterm><primary>IDENTIFY_SYSTEM</primary></indexterm>
1821 </term>
1822 <listitem>
1823 <para>
1824 Requests the server to identify itself. Server replies with a result
1825 set of a single row, containing four fields:
1826 </para>
1828 <variablelist>
1829 <varlistentry>
1830 <term><literal>systemid</literal> (<type>text</type>)</term>
1831 <listitem>
1832 <para>
1833 The unique system identifier identifying the cluster. This
1834 can be used to check that the base backup used to initialize the
1835 standby came from the same cluster.
1836 </para>
1837 </listitem>
1838 </varlistentry>
1840 <varlistentry>
1841 <term><literal>timeline</literal> (<type>int4</type>)</term>
1842 <listitem>
1843 <para>
1844 Current timeline ID. Also useful to check that the standby is
1845 consistent with the primary.
1846 </para>
1847 </listitem>
1848 </varlistentry>
1850 <varlistentry>
1851 <term><literal>xlogpos</literal> (<type>text</type>)</term>
1852 <listitem>
1853 <para>
1854 Current WAL flush location. Useful to get a known location in the
1855 write-ahead log where streaming can start.
1856 </para>
1857 </listitem>
1858 </varlistentry>
1860 <varlistentry>
1861 <term><literal>dbname</literal> (<type>text</type>)</term>
1862 <listitem>
1863 <para>
1864 Database connected to or null.
1865 </para>
1866 </listitem>
1867 </varlistentry>
1868 </variablelist>
1869 </listitem>
1870 </varlistentry>
1872 <varlistentry id="protocol-replication-show">
1873 <term><literal>SHOW</literal> <replaceable class="parameter">name</replaceable>
1874 <indexterm><primary>SHOW</primary></indexterm>
1875 </term>
1876 <listitem>
1877 <para>
1878 Requests the server to send the current setting of a run-time parameter.
1879 This is similar to the SQL command <xref linkend="sql-show"/>.
1880 </para>
1882 <variablelist>
1883 <varlistentry>
1884 <term><replaceable class="parameter">name</replaceable></term>
1885 <listitem>
1886 <para>
1887 The name of a run-time parameter. Available parameters are documented
1888 in <xref linkend="runtime-config"/>.
1889 </para>
1890 </listitem>
1891 </varlistentry>
1892 </variablelist>
1893 </listitem>
1894 </varlistentry>
1896 <varlistentry id="protocol-replication-timeline-history">
1897 <term><literal>TIMELINE_HISTORY</literal> <replaceable class="parameter">tli</replaceable>
1898 <indexterm><primary>TIMELINE_HISTORY</primary></indexterm>
1899 </term>
1900 <listitem>
1901 <para>
1902 Requests the server to send over the timeline history file for timeline
1903 <replaceable class="parameter">tli</replaceable>. Server replies with a
1904 result set of a single row, containing two fields. While the fields
1905 are labeled as <type>text</type>, they effectively return raw bytes,
1906 with no encoding conversion:
1907 </para>
1909 <variablelist>
1910 <varlistentry>
1911 <term><literal>filename</literal> (<type>text</type>)</term>
1912 <listitem>
1913 <para>
1914 File name of the timeline history file, e.g., <filename>00000002.history</filename>.
1915 </para>
1916 </listitem>
1917 </varlistentry>
1919 <varlistentry>
1920 <term><literal>content</literal> (<type>text</type>)</term>
1921 <listitem>
1922 <para>
1923 Contents of the timeline history file.
1924 </para>
1925 </listitem>
1926 </varlistentry>
1927 </variablelist>
1928 </listitem>
1929 </varlistentry>
1931 <varlistentry id="protocol-replication-create-replication-slot" xreflabel="CREATE_REPLICATION_SLOT">
1932 <term><literal>CREATE_REPLICATION_SLOT</literal> <replaceable class="parameter">slot_name</replaceable> [ <literal>TEMPORARY</literal> ] { <literal>PHYSICAL</literal> | <literal>LOGICAL</literal> } [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
1933 <indexterm><primary>CREATE_REPLICATION_SLOT</primary></indexterm>
1934 </term>
1935 <listitem>
1936 <para>
1937 Create a physical or logical replication
1938 slot. See <xref linkend="streaming-replication-slots"/> for more about
1939 replication slots.
1940 </para>
1942 <variablelist>
1943 <varlistentry>
1944 <term><replaceable class="parameter">slot_name</replaceable></term>
1945 <listitem>
1946 <para>
1947 The name of the slot to create. Must be a valid replication slot
1948 name (see <xref linkend="streaming-replication-slots-manipulation"/>).
1949 </para>
1950 </listitem>
1951 </varlistentry>
1953 <varlistentry>
1954 <term><replaceable class="parameter">output_plugin</replaceable></term>
1955 <listitem>
1956 <para>
1957 The name of the output plugin used for logical decoding
1958 (see <xref linkend="logicaldecoding-output-plugin"/>).
1959 </para>
1960 </listitem>
1961 </varlistentry>
1963 <varlistentry>
1964 <term><literal>TEMPORARY</literal></term>
1965 <listitem>
1966 <para>
1967 Specify that this replication slot is a temporary one. Temporary
1968 slots are not saved to disk and are automatically dropped on error
1969 or when the session has finished.
1970 </para>
1971 </listitem>
1972 </varlistentry>
1973 </variablelist>
1975 <para>The following options are supported:</para>
1977 <variablelist>
1978 <varlistentry>
1979 <term><literal>TWO_PHASE [ <replaceable class="parameter">boolean</replaceable> ]</literal></term>
1980 <listitem>
1981 <para>
1982 If true, this logical replication slot supports decoding of two-phase
1983 transactions. With this option, two-phase commands like
1984 <literal>PREPARE TRANSACTION</literal>, <literal>COMMIT PREPARED</literal>
1985 and <literal>ROLLBACK PREPARED</literal> are decoded and transmitted.
1986 The transaction will be decoded and transmitted at
1987 <literal>PREPARE TRANSACTION</literal> time.
1988 The default is false.
1989 </para>
1990 </listitem>
1991 </varlistentry>
1993 <varlistentry>
1994 <term><literal>RESERVE_WAL [ <replaceable class="parameter">boolean</replaceable> ]</literal></term>
1995 <listitem>
1996 <para>
1997 If true, this physical replication slot reserves <acronym>WAL</acronym>
1998 immediately. Otherwise, <acronym>WAL</acronym> is only reserved upon
1999 connection from a streaming replication client.
2000 The default is false.
2001 </para>
2002 </listitem>
2003 </varlistentry>
2005 <varlistentry>
2006 <term><literal>SNAPSHOT { 'export' | 'use' | 'nothing' }</literal></term>
2007 <listitem>
2008 <para>
2009 Decides what to do with the snapshot created during logical slot
2010 initialization. <literal>'export'</literal>, which is the default,
2011 will export the snapshot for use in other sessions. This option can't
2012 be used inside a transaction. <literal>'use'</literal> will use the
2013 snapshot for the current transaction executing the command. This
2014 option must be used in a transaction, and
2015 <literal>CREATE_REPLICATION_SLOT</literal> must be the first command
2016 run in that transaction. Finally, <literal>'nothing'</literal> will
2017 just use the snapshot for logical decoding as normal but won't do
2018 anything else with it.
2019 </para>
2020 </listitem>
2021 </varlistentry>
2022 </variablelist>
2024 <para>
2025 In response to this command, the server will send a one-row result set
2026 containing the following fields:
2028 <variablelist>
2029 <varlistentry>
2030 <term><literal>slot_name</literal> (<type>text</type>)</term>
2031 <listitem>
2032 <para>
2033 The name of the newly-created replication slot.
2034 </para>
2035 </listitem>
2036 </varlistentry>
2038 <varlistentry>
2039 <term><literal>consistent_point</literal> (<type>text</type>)</term>
2040 <listitem>
2041 <para>
2042 The WAL location at which the slot became consistent. This is the
2043 earliest location from which streaming can start on this replication
2044 slot.
2045 </para>
2046 </listitem>
2047 </varlistentry>
2049 <varlistentry>
2050 <term><literal>snapshot_name</literal> (<type>text</type>)</term>
2051 <listitem>
2052 <para>
2053 The identifier of the snapshot exported by the command. The
2054 snapshot is valid until a new command is executed on this connection
2055 or the replication connection is closed. Null if the created slot
2056 is physical.
2057 </para>
2058 </listitem>
2059 </varlistentry>
2061 <varlistentry>
2062 <term><literal>output_plugin</literal> (<type>text</type>)</term>
2063 <listitem>
2064 <para>
2065 The name of the output plugin used by the newly-created replication
2066 slot. Null if the created slot is physical.
2067 </para>
2068 </listitem>
2069 </varlistentry>
2070 </variablelist>
2071 </para>
2072 </listitem>
2073 </varlistentry>
2075 <varlistentry id="protocol-replication-create-replication-slot-legacy">
2076 <term><literal>CREATE_REPLICATION_SLOT</literal> <replaceable class="parameter">slot_name</replaceable> [ <literal>TEMPORARY</literal> ] { <literal>PHYSICAL</literal> [ <literal>RESERVE_WAL</literal> ] | <literal>LOGICAL</literal> <replaceable class="parameter">output_plugin</replaceable> [ <literal>EXPORT_SNAPSHOT</literal> | <literal>NOEXPORT_SNAPSHOT</literal> | <literal>USE_SNAPSHOT</literal> | <literal>TWO_PHASE</literal> ] }
2077 </term>
2078 <listitem>
2079 <para>
2080 For compatibility with older releases, this alternative syntax for
2081 the <literal>CREATE_REPLICATION_SLOT</literal> command is still supported.
2082 </para>
2083 </listitem>
2084 </varlistentry>
2086 <varlistentry id="protocol-replication-read-replication-slot">
2087 <term><literal>READ_REPLICATION_SLOT</literal> <replaceable class="parameter">slot_name</replaceable>
2088 <indexterm><primary>READ_REPLICATION_SLOT</primary></indexterm>
2089 </term>
2090 <listitem>
2091 <para>
2092 Read some information associated with a replication slot. Returns a tuple
2093 with <literal>NULL</literal> values if the replication slot does not
2094 exist. This command is currently only supported for physical replication
2095 slots.
2096 </para>
2098 <para>
2099 In response to this command, the server will return a one-row result set,
2100 containing the following fields:
2101 <variablelist>
2102 <varlistentry>
2103 <term><literal>slot_type</literal> (<type>text</type>)</term>
2104 <listitem>
2105 <para>
2106 The replication slot's type, either <literal>physical</literal> or
2107 <literal>NULL</literal>.
2108 </para>
2109 </listitem>
2110 </varlistentry>
2112 <varlistentry>
2113 <term><literal>restart_lsn</literal> (<type>text</type>)</term>
2114 <listitem>
2115 <para>
2116 The replication slot's <literal>restart_lsn</literal>.
2117 </para>
2118 </listitem>
2119 </varlistentry>
2121 <varlistentry>
2122 <term><literal>restart_tli</literal> (<type>int8</type>)</term>
2123 <listitem>
2124 <para>
2125 The timeline ID associated with <literal>restart_lsn</literal>,
2126 following the current timeline history.
2127 </para>
2128 </listitem>
2129 </varlistentry>
2130 </variablelist>
2131 </para>
2132 </listitem>
2133 </varlistentry>
2135 <varlistentry id="protocol-replication-start-replication">
2136 <term><literal>START_REPLICATION</literal> [ <literal>SLOT</literal> <replaceable class="parameter">slot_name</replaceable> ] [ <literal>PHYSICAL</literal> ] <replaceable class="parameter">XXX/XXX</replaceable> [ <literal>TIMELINE</literal> <replaceable class="parameter">tli</replaceable> ]
2137 <indexterm><primary>START_REPLICATION</primary></indexterm>
2138 </term>
2139 <listitem>
2140 <para>
2141 Instructs server to start streaming WAL, starting at
2142 WAL location <replaceable class="parameter">XXX/XXX</replaceable>.
2143 If <literal>TIMELINE</literal> option is specified,
2144 streaming starts on timeline <replaceable class="parameter">tli</replaceable>;
2145 otherwise, the server's current timeline is selected. The server can
2146 reply with an error, for example if the requested section of WAL has already
2147 been recycled. On success, the server responds with a CopyBothResponse
2148 message, and then starts to stream WAL to the frontend.
2149 </para>
2151 <para>
2152 If a slot's name is provided
2153 via <replaceable class="parameter">slot_name</replaceable>, it will be updated
2154 as replication progresses so that the server knows which WAL segments,
2155 and if <varname>hot_standby_feedback</varname> is on which transactions,
2156 are still needed by the standby.
2157 </para>
2159 <para>
2160 If the client requests a timeline that's not the latest but is part of
2161 the history of the server, the server will stream all the WAL on that
2162 timeline starting from the requested start point up to the point where
2163 the server switched to another timeline. If the client requests
2164 streaming at exactly the end of an old timeline, the server skips COPY
2165 mode entirely.
2166 </para>
2168 <para>
2169 After streaming all the WAL on a timeline that is not the latest one,
2170 the server will end streaming by exiting the COPY mode. When the client
2171 acknowledges this by also exiting COPY mode, the server sends a result
2172 set with one row and two columns, indicating the next timeline in this
2173 server's history. The first column is the next timeline's ID (type <type>int8</type>), and the
2174 second column is the WAL location where the switch happened (type <type>text</type>). Usually,
2175 the switch position is the end of the WAL that was streamed, but there
2176 are corner cases where the server can send some WAL from the old
2177 timeline that it has not itself replayed before promoting. Finally, the
2178 server sends two CommandComplete messages (one that ends the CopyData
2179 and the other ends the <literal>START_REPLICATION</literal> itself), and
2180 is ready to accept a new command.
2181 </para>
2183 <para>
2184 WAL data is sent as a series of CopyData messages. (This allows
2185 other information to be intermixed; in particular the server can send
2186 an ErrorResponse message if it encounters a failure after beginning
2187 to stream.) The payload of each CopyData message from server to the
2188 client contains a message of one of the following formats:
2189 </para>
2191 <variablelist>
2192 <varlistentry id="protocol-replication-xlogdata">
2193 <term>XLogData (B)</term>
2194 <listitem>
2195 <variablelist>
2196 <varlistentry>
2197 <term>Byte1('w')</term>
2198 <listitem>
2199 <para>
2200 Identifies the message as WAL data.
2201 </para>
2202 </listitem>
2203 </varlistentry>
2205 <varlistentry>
2206 <term>Int64</term>
2207 <listitem>
2208 <para>
2209 The starting point of the WAL data in this message.
2210 </para>
2211 </listitem>
2212 </varlistentry>
2214 <varlistentry>
2215 <term>Int64</term>
2216 <listitem>
2217 <para>
2218 The current end of WAL on the server.
2219 </para>
2220 </listitem>
2221 </varlistentry>
2223 <varlistentry>
2224 <term>Int64</term>
2225 <listitem>
2226 <para>
2227 The server's system clock at the time of transmission, as
2228 microseconds since midnight on 2000-01-01.
2229 </para>
2230 </listitem>
2231 </varlistentry>
2233 <varlistentry>
2234 <term>Byte<replaceable>n</replaceable></term>
2235 <listitem>
2236 <para>
2237 A section of the WAL data stream.
2238 </para>
2240 <para>
2241 A single WAL record is never split across two XLogData messages.
2242 When a WAL record crosses a WAL page boundary, and is therefore
2243 already split using continuation records, it can be split at the page
2244 boundary. In other words, the first main WAL record and its
2245 continuation records can be sent in different XLogData messages.
2246 </para>
2247 </listitem>
2248 </varlistentry>
2249 </variablelist>
2250 </listitem>
2251 </varlistentry>
2253 <varlistentry id="protocol-replication-primary-keepalive-message">
2254 <term>Primary keepalive message (B)</term>
2255 <listitem>
2256 <variablelist>
2257 <varlistentry>
2258 <term>Byte1('k')</term>
2259 <listitem>
2260 <para>
2261 Identifies the message as a sender keepalive.
2262 </para>
2263 </listitem>
2264 </varlistentry>
2266 <varlistentry>
2267 <term>Int64</term>
2268 <listitem>
2269 <para>
2270 The current end of WAL on the server.
2271 </para>
2272 </listitem>
2273 </varlistentry>
2275 <varlistentry>
2276 <term>Int64</term>
2277 <listitem>
2278 <para>
2279 The server's system clock at the time of transmission, as
2280 microseconds since midnight on 2000-01-01.
2281 </para>
2282 </listitem>
2283 </varlistentry>
2285 <varlistentry>
2286 <term>Byte1</term>
2287 <listitem>
2288 <para>
2289 1 means that the client should reply to this message as soon as
2290 possible, to avoid a timeout disconnect. 0 otherwise.
2291 </para>
2292 </listitem>
2293 </varlistentry>
2294 </variablelist>
2295 </listitem>
2296 </varlistentry>
2297 </variablelist>
2299 <para>
2300 The receiving process can send replies back to the sender at any time,
2301 using one of the following message formats (also in the payload of a
2302 CopyData message):
2303 </para>
2305 <variablelist>
2306 <varlistentry id="protocol-replication-standby-status-update">
2307 <term>Standby status update (F)</term>
2308 <listitem>
2309 <variablelist>
2310 <varlistentry>
2311 <term>Byte1('r')</term>
2312 <listitem>
2313 <para>
2314 Identifies the message as a receiver status update.
2315 </para>
2316 </listitem>
2317 </varlistentry>
2319 <varlistentry>
2320 <term>Int64</term>
2321 <listitem>
2322 <para>
2323 The location of the last WAL byte + 1 received and written to disk
2324 in the standby.
2325 </para>
2326 </listitem>
2327 </varlistentry>
2329 <varlistentry>
2330 <term>Int64</term>
2331 <listitem>
2332 <para>
2333 The location of the last WAL byte + 1 flushed to disk in
2334 the standby.
2335 </para>
2336 </listitem>
2337 </varlistentry>
2339 <varlistentry>
2340 <term>Int64</term>
2341 <listitem>
2342 <para>
2343 The location of the last WAL byte + 1 applied in the standby.
2344 </para>
2345 </listitem>
2346 </varlistentry>
2348 <varlistentry>
2349 <term>Int64</term>
2350 <listitem>
2351 <para>
2352 The client's system clock at the time of transmission, as
2353 microseconds since midnight on 2000-01-01.
2354 </para>
2355 </listitem>
2356 </varlistentry>
2358 <varlistentry>
2359 <term>Byte1</term>
2360 <listitem>
2361 <para>
2362 If 1, the client requests the server to reply to this message
2363 immediately. This can be used to ping the server, to test if
2364 the connection is still healthy.
2365 </para>
2366 </listitem>
2367 </varlistentry>
2368 </variablelist>
2369 </listitem>
2370 </varlistentry>
2372 <varlistentry id="protocol-replication-hot-standby-feedback-message">
2373 <term>Hot standby feedback message (F)</term>
2374 <listitem>
2375 <variablelist>
2376 <varlistentry>
2377 <term>Byte1('h')</term>
2378 <listitem>
2379 <para>
2380 Identifies the message as a hot standby feedback message.
2381 </para>
2382 </listitem>
2383 </varlistentry>
2385 <varlistentry>
2386 <term>Int64</term>
2387 <listitem>
2388 <para>
2389 The client's system clock at the time of transmission, as
2390 microseconds since midnight on 2000-01-01.
2391 </para>
2392 </listitem>
2393 </varlistentry>
2395 <varlistentry>
2396 <term>Int32</term>
2397 <listitem>
2398 <para>
2399 The standby's current global xmin, excluding the catalog_xmin from any
2400 replication slots. If both this value and the following
2401 catalog_xmin are 0 this is treated as a notification that hot standby
2402 feedback will no longer be sent on this connection. Later non-zero
2403 messages may reinitiate the feedback mechanism.
2404 </para>
2405 </listitem>
2406 </varlistentry>
2408 <varlistentry>
2409 <term>Int32</term>
2410 <listitem>
2411 <para>
2412 The epoch of the global xmin xid on the standby.
2413 </para>
2414 </listitem>
2415 </varlistentry>
2417 <varlistentry>
2418 <term>Int32</term>
2419 <listitem>
2420 <para>
2421 The lowest catalog_xmin of any replication slots on the standby. Set to 0
2422 if no catalog_xmin exists on the standby or if hot standby feedback is being
2423 disabled.
2424 </para>
2425 </listitem>
2426 </varlistentry>
2428 <varlistentry>
2429 <term>Int32</term>
2430 <listitem>
2431 <para>
2432 The epoch of the catalog_xmin xid on the standby.
2433 </para>
2434 </listitem>
2435 </varlistentry>
2436 </variablelist>
2437 </listitem>
2438 </varlistentry>
2439 </variablelist>
2440 </listitem>
2441 </varlistentry>
2443 <varlistentry id="protocol-replication-start-replication-slot-logical">
2444 <term><literal>START_REPLICATION</literal> <literal>SLOT</literal> <replaceable class="parameter">slot_name</replaceable> <literal>LOGICAL</literal> <replaceable class="parameter">XXX/XXX</replaceable> [ ( <replaceable>option_name</replaceable> [ <replaceable>option_value</replaceable> ] [, ...] ) ]</term>
2445 <listitem>
2446 <para>
2447 Instructs server to start streaming WAL for logical replication,
2448 starting at either WAL location <replaceable
2449 class="parameter">XXX/XXX</replaceable> or the slot's
2450 <literal>confirmed_flush_lsn</literal> (see <xref
2451 linkend="view-pg-replication-slots"/>), whichever is greater. This
2452 behavior makes it easier for clients to avoid updating their local LSN
2453 status when there is no data to process. However, starting at a
2454 different LSN than requested might not catch certain kinds of client
2455 errors; so the client may wish to check that
2456 <literal>confirmed_flush_lsn</literal> matches its expectations before
2457 issuing <literal>START_REPLICATION</literal>.
2458 </para>
2460 <para>
2461 The server can reply with an error, for example if the
2462 slot does not exist. On success, the server responds with a CopyBothResponse
2463 message, and then starts to stream WAL to the frontend.
2464 </para>
2466 <para>
2467 The messages inside the CopyBothResponse messages are of the same format
2468 documented for <literal>START_REPLICATION ... PHYSICAL</literal>, including
2469 two CommandComplete messages.
2470 </para>
2472 <para>
2473 The output plugin associated with the selected slot is used
2474 to process the output for streaming.
2475 </para>
2477 <variablelist>
2478 <varlistentry>
2479 <term><literal>SLOT</literal> <replaceable class="parameter">slot_name</replaceable></term>
2480 <listitem>
2481 <para>
2482 The name of the slot to stream changes from. This parameter is required,
2483 and must correspond to an existing logical replication slot created
2484 with <literal>CREATE_REPLICATION_SLOT</literal> in
2485 <literal>LOGICAL</literal> mode.
2486 </para>
2487 </listitem>
2488 </varlistentry>
2490 <varlistentry>
2491 <term><replaceable class="parameter">XXX/XXX</replaceable></term>
2492 <listitem>
2493 <para>
2494 The WAL location to begin streaming at.
2495 </para>
2496 </listitem>
2497 </varlistentry>
2499 <varlistentry>
2500 <term><replaceable class="parameter">option_name</replaceable></term>
2501 <listitem>
2502 <para>
2503 The name of an option passed to the slot's logical decoding plugin.
2504 </para>
2505 </listitem>
2506 </varlistentry>
2508 <varlistentry>
2509 <term><replaceable class="parameter">option_value</replaceable></term>
2510 <listitem>
2511 <para>
2512 Optional value, in the form of a string constant, associated with the
2513 specified option.
2514 </para>
2515 </listitem>
2516 </varlistentry>
2517 </variablelist>
2518 </listitem>
2519 </varlistentry>
2521 <varlistentry id="protocol-replication-drop-replication-slot">
2522 <term>
2523 <literal>DROP_REPLICATION_SLOT</literal> <replaceable class="parameter">slot_name</replaceable> <optional> <literal>WAIT</literal> </optional>
2524 <indexterm><primary>DROP_REPLICATION_SLOT</primary></indexterm>
2525 </term>
2526 <listitem>
2527 <para>
2528 Drops a replication slot, freeing any reserved server-side resources.
2529 If the slot is a logical slot that was created in a database other than
2530 the database the walsender is connected to, this command fails.
2531 </para>
2533 <variablelist>
2534 <varlistentry>
2535 <term><replaceable class="parameter">slot_name</replaceable></term>
2536 <listitem>
2537 <para>
2538 The name of the slot to drop.
2539 </para>
2540 </listitem>
2541 </varlistentry>
2543 <varlistentry>
2544 <term><literal>WAIT</literal></term>
2545 <listitem>
2546 <para>
2547 This option causes the command to wait if the slot is active until
2548 it becomes inactive, instead of the default behavior of raising an
2549 error.
2550 </para>
2551 </listitem>
2552 </varlistentry>
2553 </variablelist>
2554 </listitem>
2555 </varlistentry>
2557 <varlistentry id="protocol-replication-base-backup" xreflabel="BASE_BACKUP">
2558 <term><literal>BASE_BACKUP</literal> [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
2559 <indexterm><primary>BASE_BACKUP</primary></indexterm>
2560 </term>
2561 <listitem>
2562 <para>
2563 Instructs the server to start streaming a base backup.
2564 The system will automatically be put in backup mode before the backup
2565 is started, and taken out of it when the backup is complete. The
2566 following options are accepted:
2568 <variablelist>
2569 <varlistentry>
2570 <term><literal>LABEL</literal> <replaceable>'label'</replaceable></term>
2571 <listitem>
2572 <para>
2573 Sets the label of the backup. If none is specified, a backup label
2574 of <literal>base backup</literal> will be used. The quoting rules
2575 for the label are the same as a standard SQL string with
2576 <xref linkend="guc-standard-conforming-strings"/> turned on.
2577 </para>
2578 </listitem>
2579 </varlistentry>
2581 <varlistentry>
2582 <term><literal>TARGET</literal> <replaceable>'target'</replaceable></term>
2583 <listitem>
2584 <para>
2585 Tells the server where to send the backup. If the target is
2586 <literal>client</literal>, which is the default, the backup data is
2587 sent to the client. If it is <literal>server</literal>, the backup
2588 data is written to the server at the pathname specified by the
2589 <literal>TARGET_DETAIL</literal> option. If it is
2590 <literal>blackhole</literal>, the backup data is not sent
2591 anywhere; it is simply discarded.
2592 </para>
2594 <para>
2595 The <literal>server</literal> target requires superuser privilege or
2596 being granted the <literal>pg_write_server_files</literal> role.
2597 </para>
2598 </listitem>
2599 </varlistentry>
2601 <varlistentry>
2602 <term><literal>TARGET_DETAIL</literal> <replaceable>'detail'</replaceable></term>
2603 <listitem>
2604 <para>
2605 Provides additional information about the backup target.
2606 </para>
2608 <para>
2609 Currently, this option can only be used when the backup target is
2610 <literal>server</literal>. It specifies the server directory
2611 to which the backup should be written.
2612 </para>
2613 </listitem>
2614 </varlistentry>
2616 <varlistentry>
2617 <term><literal>PROGRESS [ <replaceable class="parameter">boolean</replaceable> ]</literal></term>
2618 <listitem>
2619 <para>
2620 If set to true, request information required to generate a progress
2621 report. This will send back an approximate size in the header of each
2622 tablespace, which can be used to calculate how far along the stream
2623 is done. This is calculated by enumerating all the file sizes once
2624 before the transfer is even started, and might as such have a
2625 negative impact on the performance. In particular, it might take
2626 longer before the first data
2627 is streamed. Since the database files can change during the backup,
2628 the size is only approximate and might both grow and shrink between
2629 the time of approximation and the sending of the actual files.
2630 The default is false.
2631 </para>
2632 </listitem>
2633 </varlistentry>
2635 <varlistentry>
2636 <term><literal>CHECKPOINT { 'fast' | 'spread' }</literal></term>
2637 <listitem>
2638 <para>
2639 Sets the type of checkpoint to be performed at the beginning of the
2640 base backup. The default is <literal>spread</literal>.
2641 </para>
2642 </listitem>
2643 </varlistentry>
2645 <varlistentry>
2646 <term><literal>WAL [ <replaceable class="parameter">boolean</replaceable> ]</literal></term>
2647 <listitem>
2648 <para>
2649 If set to true, include the necessary WAL segments in the backup.
2650 This will include all the files between start and stop backup in the
2651 <filename>pg_wal</filename> directory of the base directory tar
2652 file. The default is false.
2653 </para>
2654 </listitem>
2655 </varlistentry>
2657 <varlistentry>
2658 <term><literal>WAIT [ <replaceable class="parameter">boolean</replaceable> ]</literal></term>
2659 <listitem>
2660 <para>
2661 If set to true, the backup will wait until the last required WAL
2662 segment has been archived, or emit a warning if log archiving is
2663 not enabled. If false, the backup will neither wait nor warn,
2664 leaving the client responsible for ensuring the required log is
2665 available. The default is true.
2666 </para>
2667 </listitem>
2668 </varlistentry>
2670 <varlistentry>
2671 <term><literal>COMPRESSION</literal> <replaceable>'method'</replaceable></term>
2672 <listitem>
2673 <para>
2674 Instructs the server to compress the backup using the specified
2675 method. Currently, the supported methods are <literal>gzip</literal>,
2676 <literal>lz4</literal>, and <literal>zstd</literal>.
2677 </para>
2678 </listitem>
2679 </varlistentry>
2681 <varlistentry>
2682 <term><literal>COMPRESSION_DETAIL</literal> <replaceable>detail</replaceable></term>
2683 <listitem>
2684 <para>
2685 Specifies details for the chosen compression method. This should only
2686 be used in conjunction with the <literal>COMPRESSION</literal>
2687 option. If the value is an integer, it specifies the compression
2688 level. Otherwise, it should be a comma-separated list of items,
2689 each of the form <literal>keyword</literal> or
2690 <literal>keyword=value</literal>. Currently, the supported keywords
2691 are <literal>level</literal> and <literal>workers</literal>.
2692 </para>
2694 <para>
2695 The <literal>level</literal> keyword sets the compression level.
2696 For <literal>gzip</literal> the compression level should be an
2697 integer between 1 and 9, for <literal>lz4</literal> an integer
2698 between 1 and 12, and for <literal>zstd</literal> an integer
2699 between 1 and 22.
2700 </para>
2702 <para>
2703 The <literal>workers</literal> keyword sets the number of threads
2704 that should be used for parallel compression. Parallel compression
2705 is supported only for <literal>zstd</literal>.
2706 </para>
2707 </listitem>
2708 </varlistentry>
2710 <varlistentry>
2711 <term><literal>MAX_RATE</literal> <replaceable>rate</replaceable></term>
2712 <listitem>
2713 <para>
2714 Limit (throttle) the maximum amount of data transferred from server
2715 to client per unit of time. The expected unit is kilobytes per second.
2716 If this option is specified, the value must either be equal to zero
2717 or it must fall within the range from 32 kB through 1 GB (inclusive).
2718 If zero is passed or the option is not specified, no restriction is
2719 imposed on the transfer.
2720 </para>
2721 </listitem>
2722 </varlistentry>
2724 <varlistentry>
2725 <term><literal>TABLESPACE_MAP [ <replaceable class="parameter">boolean</replaceable> ]</literal></term>
2726 <listitem>
2727 <para>
2728 If true, include information about symbolic links present in the
2729 directory <filename>pg_tblspc</filename> in a file named
2730 <filename>tablespace_map</filename>. The tablespace map file includes
2731 each symbolic link name as it exists in the directory
2732 <filename>pg_tblspc/</filename> and the full path of that symbolic link.
2733 The default is false.
2734 </para>
2735 </listitem>
2736 </varlistentry>
2738 <varlistentry>
2739 <term><literal>VERIFY_CHECKSUMS [ <replaceable class="parameter">boolean</replaceable> ]</literal></term>
2740 <listitem>
2741 <para>
2742 If true, checksums are verified during a base backup if they are
2743 enabled. If false, this is skipped. The default is true.
2744 </para>
2745 </listitem>
2746 </varlistentry>
2748 <varlistentry>
2749 <term><literal>MANIFEST</literal> <replaceable>manifest_option</replaceable></term>
2750 <listitem>
2751 <para>
2752 When this option is specified with a value of <literal>yes</literal>
2753 or <literal>force-encode</literal>, a backup manifest is created
2754 and sent along with the backup. The manifest is a list of every
2755 file present in the backup with the exception of any WAL files that
2756 may be included. It also stores the size, last modification time, and
2757 optionally a checksum for each file.
2758 A value of <literal>force-encode</literal> forces all filenames
2759 to be hex-encoded; otherwise, this type of encoding is performed only
2760 for files whose names are non-UTF8 octet sequences.
2761 <literal>force-encode</literal> is intended primarily for testing
2762 purposes, to be sure that clients which read the backup manifest
2763 can handle this case. For compatibility with previous releases,
2764 the default is <literal>MANIFEST 'no'</literal>.
2765 </para>
2766 </listitem>
2767 </varlistentry>
2769 <varlistentry>
2770 <term><literal>MANIFEST_CHECKSUMS</literal> <replaceable>checksum_algorithm</replaceable></term>
2771 <listitem>
2772 <para>
2773 Specifies the checksum algorithm that should be applied to each file included
2774 in the backup manifest. Currently, the available
2775 algorithms are <literal>NONE</literal>, <literal>CRC32C</literal>,
2776 <literal>SHA224</literal>, <literal>SHA256</literal>,
2777 <literal>SHA384</literal>, and <literal>SHA512</literal>.
2778 The default is <literal>CRC32C</literal>.
2779 </para>
2780 </listitem>
2781 </varlistentry>
2782 </variablelist>
2783 </para>
2785 <para>
2786 When the backup is started, the server will first send two
2787 ordinary result sets, followed by one or more CopyOutResponse
2788 results.
2789 </para>
2791 <para>
2792 The first ordinary result set contains the starting position of the
2793 backup, in a single row with two columns. The first column contains
2794 the start position given in XLogRecPtr format, and the second column
2795 contains the corresponding timeline ID.
2796 </para>
2798 <para>
2799 The second ordinary result set has one row for each tablespace.
2800 The fields in this row are:
2802 <variablelist>
2803 <varlistentry>
2804 <term><literal>spcoid</literal> (<type>oid</type>)</term>
2805 <listitem>
2806 <para>
2807 The OID of the tablespace, or null if it's the base
2808 directory.
2809 </para>
2810 </listitem>
2811 </varlistentry>
2813 <varlistentry>
2814 <term><literal>spclocation</literal> (<type>text</type>)</term>
2815 <listitem>
2816 <para>
2817 The full path of the tablespace directory, or null
2818 if it's the base directory.
2819 </para>
2820 </listitem>
2821 </varlistentry>
2823 <varlistentry>
2824 <term><literal>size</literal> (<type>int8</type>)</term>
2825 <listitem>
2826 <para>
2827 The approximate size of the tablespace, in kilobytes (1024 bytes),
2828 if progress report has been requested; otherwise it's null.
2829 </para>
2830 </listitem>
2831 </varlistentry>
2832 </variablelist>
2833 </para>
2835 <para>
2836 After the second regular result set, a CopyOutResponse will be sent.
2837 The payload of each CopyData message will contain a message in one of
2838 the following formats:
2839 </para>
2841 <variablelist>
2842 <varlistentry>
2843 <term>new archive (B)</term>
2844 <listitem>
2845 <variablelist>
2846 <varlistentry>
2847 <term>Byte1('n')</term>
2848 <listitem><para>
2849 Identifes the messaage as indicating the start of a new archive.
2850 There will be one archive for the main data directory and one
2851 for each additional tablespace; each will use tar format
2852 (following the <quote>ustar interchange format</quote> specified
2853 in the POSIX 1003.1-2008 standard).
2854 </para></listitem>
2855 </varlistentry>
2857 <varlistentry>
2858 <term>String</term>
2859 <listitem><para>
2860 The file name for this archive.
2861 </para></listitem>
2862 </varlistentry>
2864 <varlistentry>
2865 <term>String</term>
2866 <listitem><para>
2867 For the main data directory, an empty string. For other
2868 tablespaces, the full path to the directory from which this
2869 archive was created.
2870 </para></listitem>
2871 </varlistentry>
2872 </variablelist>
2873 </listitem>
2874 </varlistentry>
2876 <varlistentry>
2877 <term>manifest (B)</term>
2878 <listitem>
2879 <variablelist>
2880 <varlistentry>
2881 <term>Byte1('m')</term>
2882 <listitem><para>
2883 Identifes the message as indicating the start of the backup
2884 manifest.
2885 </para></listitem>
2886 </varlistentry>
2887 </variablelist>
2888 </listitem>
2889 </varlistentry>
2891 <varlistentry>
2892 <term>archive or manifest data (B)</term>
2893 <listitem>
2894 <variablelist>
2895 <varlistentry>
2896 <term>Byte1('d')</term>
2897 <listitem><para>
2898 Identifes the message as containing archive or manifest data.
2899 </para></listitem>
2900 </varlistentry>
2902 <varlistentry>
2903 <term>Byte<replaceable>n</replaceable></term>
2904 <listitem><para>
2905 Data bytes.
2906 </para></listitem>
2907 </varlistentry>
2908 </variablelist>
2909 </listitem>
2910 </varlistentry>
2912 <varlistentry>
2913 <term>progress report (B)</term>
2914 <listitem>
2915 <variablelist>
2916 <varlistentry>
2917 <term>Byte1('p')</term>
2918 <listitem><para>
2919 Identifes the message as a progress report.
2920 </para></listitem>
2921 </varlistentry>
2923 <varlistentry>
2924 <term>Int64</term>
2925 <listitem><para>
2926 The number of bytes from the current tablespace for which
2927 processing has been completed.
2928 </para></listitem>
2929 </varlistentry>
2930 </variablelist>
2931 </listitem>
2932 </varlistentry>
2933 </variablelist>
2935 <para>
2936 After the CopyOutResponse, or all such responses, have been sent, a
2937 final ordinary result set will be sent, containing the WAL end position
2938 of the backup, in the same format as the start position.
2939 </para>
2941 <para>
2942 The tar archive for the data directory and each tablespace will contain
2943 all files in the directories, regardless of whether they are
2944 <productname>PostgreSQL</productname> files or other files added to the same
2945 directory. The only excluded files are:
2947 <itemizedlist spacing="compact" mark="bullet">
2948 <listitem>
2949 <para>
2950 <filename>postmaster.pid</filename>
2951 </para>
2952 </listitem>
2953 <listitem>
2954 <para>
2955 <filename>postmaster.opts</filename>
2956 </para>
2957 </listitem>
2958 <listitem>
2959 <para>
2960 <filename>pg_internal.init</filename> (found in multiple directories)
2961 </para>
2962 </listitem>
2963 <listitem>
2964 <para>
2965 Various temporary files and directories created during the operation
2966 of the PostgreSQL server, such as any file or directory beginning
2967 with <filename>pgsql_tmp</filename> and temporary relations.
2968 </para>
2969 </listitem>
2970 <listitem>
2971 <para>
2972 Unlogged relations, except for the init fork which is required to
2973 recreate the (empty) unlogged relation on recovery.
2974 </para>
2975 </listitem>
2976 <listitem>
2977 <para>
2978 <filename>pg_wal</filename>, including subdirectories. If the backup is run
2979 with WAL files included, a synthesized version of <filename>pg_wal</filename> will be
2980 included, but it will only contain the files necessary for the
2981 backup to work, not the rest of the contents.
2982 </para>
2983 </listitem>
2984 <listitem>
2985 <para>
2986 <filename>pg_dynshmem</filename>, <filename>pg_notify</filename>,
2987 <filename>pg_replslot</filename>, <filename>pg_serial</filename>,
2988 <filename>pg_snapshots</filename>, <filename>pg_stat_tmp</filename>, and
2989 <filename>pg_subtrans</filename> are copied as empty directories (even if
2990 they are symbolic links).
2991 </para>
2992 </listitem>
2993 <listitem>
2994 <para>
2995 Files other than regular files and directories, such as symbolic
2996 links (other than for the directories listed above) and special
2997 device files, are skipped. (Symbolic links
2998 in <filename>pg_tblspc</filename> are maintained.)
2999 </para>
3000 </listitem>
3001 </itemizedlist>
3002 Owner, group, and file mode are set if the underlying file system on
3003 the server supports it.
3004 </para>
3005 </listitem>
3006 </varlistentry>
3007 </variablelist>
3008 </para>
3009 </sect1>
3011 <sect1 id="protocol-logical-replication">
3012 <title>Logical Streaming Replication Protocol</title>
3014 <para>
3015 This section describes the logical replication protocol, which is the message
3016 flow started by the <literal>START_REPLICATION</literal>
3017 <literal>SLOT</literal> <replaceable class="parameter">slot_name</replaceable>
3018 <literal>LOGICAL</literal> replication command.
3019 </para>
3021 <para>
3022 The logical streaming replication protocol builds on the primitives of
3023 the physical streaming replication protocol.
3024 </para>
3026 <sect2 id="protocol-logical-replication-params">
3027 <title>Logical Streaming Replication Parameters</title>
3029 <para>
3030 The logical replication <literal>START_REPLICATION</literal> command
3031 accepts following parameters:
3033 <variablelist>
3034 <varlistentry>
3035 <term>
3036 proto_version
3037 </term>
3038 <listitem>
3039 <para>
3040 Protocol version. Currently versions <literal>1</literal>, <literal>2</literal>,
3041 and <literal>3</literal> are supported.
3042 </para>
3043 <para>
3044 Version <literal>2</literal> is supported only for server version 14
3045 and above, and it allows streaming of large in-progress transactions.
3046 </para>
3047 <para>
3048 Version <literal>3</literal> is supported only for server version 15
3049 and above, and it allows streaming of two-phase transactions.
3050 </para>
3051 </listitem>
3052 </varlistentry>
3054 <varlistentry>
3055 <term>
3056 publication_names
3057 </term>
3058 <listitem>
3059 <para>
3060 Comma separated list of publication names for which to subscribe
3061 (receive changes). The individual publication names are treated
3062 as standard objects names and can be quoted the same as needed.
3063 </para>
3064 </listitem>
3065 </varlistentry>
3066 </variablelist>
3068 </para>
3069 </sect2>
3071 <sect2 id="protocol-logical-messages">
3072 <title>Logical Replication Protocol Messages</title>
3074 <para>
3075 The individual protocol messages are discussed in the following
3076 subsections. Individual messages are described in
3077 <xref linkend="protocol-logicalrep-message-formats"/>.
3078 </para>
3080 <para>
3081 All top-level protocol messages begin with a message type byte.
3082 While represented in code as a character, this is a signed byte with no
3083 associated encoding.
3084 </para>
3086 <para>
3087 Since the streaming replication protocol supplies a message length there
3088 is no need for top-level protocol messages to embed a length in their
3089 header.
3090 </para>
3092 </sect2>
3094 <sect2 id="protocol-logical-messages-flow">
3095 <title>Logical Replication Protocol Message Flow</title>
3097 <para>
3098 With the exception of the <literal>START_REPLICATION</literal> command and
3099 the replay progress messages, all information flows only from the backend
3100 to the frontend.
3101 </para>
3103 <para>
3104 The logical replication protocol sends individual transactions one by one.
3105 This means that all messages between a pair of Begin and Commit messages
3106 belong to the same transaction. Similarly, all messages between a pair of
3107 Begin Prepare and Prepare messages belong to the same transaction.
3108 It also sends changes of large in-progress transactions between a pair of
3109 Stream Start and Stream Stop messages. The last stream of such a transaction
3110 contains a Stream Commit or Stream Abort message.
3111 </para>
3113 <para>
3114 Every sent transaction contains zero or more DML messages (Insert,
3115 Update, Delete). In case of a cascaded setup it can also contain Origin
3116 messages. The origin message indicates that the transaction originated on
3117 different replication node. Since a replication node in the scope of logical
3118 replication protocol can be pretty much anything, the only identifier
3119 is the origin name. It's downstream's responsibility to handle this as
3120 needed (if needed). The Origin message is always sent before any DML
3121 messages in the transaction.
3122 </para>
3124 <para>
3125 Every DML message contains a relation OID, identifying the publisher's
3126 relation that was acted on. Before the first DML message for a given
3127 relation OID, a Relation message will be sent, describing the schema of
3128 that relation. Subsequently, a new Relation message will be sent if
3129 the relation's definition has changed since the last Relation message
3130 was sent for it. (The protocol assumes that the client is capable of
3131 remembering this metadata for as many relations as needed.)
3132 </para>
3134 <para>
3135 Relation messages identify column types by their OIDs. In the case
3136 of a built-in type, it is assumed that the client can look up that
3137 type OID locally, so no additional data is needed. For a non-built-in
3138 type OID, a Type message will be sent before the Relation message,
3139 to provide the type name associated with that OID. Thus, a client that
3140 needs to specifically identify the types of relation columns should
3141 cache the contents of Type messages, and first consult that cache to
3142 see if the type OID is defined there. If not, look up the type OID
3143 locally.
3144 </para>
3145 </sect2>
3146 </sect1>
3148 <sect1 id="protocol-message-types">
3149 <title>Message Data Types</title>
3151 <para>
3152 This section describes the base data types used in messages.
3153 </para>
3155 <variablelist>
3156 <varlistentry>
3157 <term>Int<replaceable>n</replaceable>(<replaceable>i</replaceable>)</term>
3158 <listitem>
3159 <para>
3160 An <replaceable>n</replaceable>-bit integer in network byte
3161 order (most significant byte first).
3162 If <replaceable>i</replaceable> is specified it
3163 is the exact value that will appear, otherwise the value
3164 is variable. Eg. Int16, Int32(42).
3165 </para>
3166 </listitem>
3167 </varlistentry>
3169 <varlistentry>
3170 <term>Int<replaceable>n</replaceable>[<replaceable>k</replaceable>]</term>
3171 <listitem>
3172 <para>
3173 An array of <replaceable>k</replaceable>
3174 <replaceable>n</replaceable>-bit integers, each in network
3175 byte order. The array length <replaceable>k</replaceable>
3176 is always determined by an earlier field in the message.
3177 Eg. Int16[M].
3178 </para>
3179 </listitem>
3180 </varlistentry>
3182 <varlistentry>
3183 <term>String(<replaceable>s</replaceable>)</term>
3184 <listitem>
3185 <para>
3186 A null-terminated string (C-style string). There is no
3187 specific length limitation on strings.
3188 If <replaceable>s</replaceable> is specified it is the exact
3189 value that will appear, otherwise the value is variable.
3190 Eg. String, String("user").
3191 </para>
3193 <note>
3194 <para>
3195 <emphasis>There is no predefined limit</emphasis> on the length of a string
3196 that can be returned by the backend. Good coding strategy for a frontend
3197 is to use an expandable buffer so that anything that fits in memory can be
3198 accepted. If that's not feasible, read the full string and discard trailing
3199 characters that don't fit into your fixed-size buffer.
3200 </para>
3201 </note>
3202 </listitem>
3203 </varlistentry>
3205 <varlistentry>
3206 <term>Byte<replaceable>n</replaceable>(<replaceable>c</replaceable>)</term>
3207 <listitem>
3208 <para>
3209 Exactly <replaceable>n</replaceable> bytes. If the field
3210 width <replaceable>n</replaceable> is not a constant, it is
3211 always determinable from an earlier field in the message.
3212 If <replaceable>c</replaceable> is specified it is the exact
3213 value. Eg. Byte2, Byte1('\n').
3214 </para>
3215 </listitem>
3216 </varlistentry>
3217 </variablelist>
3218 </sect1>
3220 <sect1 id="protocol-message-formats">
3221 <title>Message Formats</title>
3223 <para>
3224 This section describes the detailed format of each message. Each is marked to
3225 indicate that it can be sent by a frontend (F), a backend (B), or both
3226 (F &amp; B).
3227 Notice that although each message includes a byte count at the beginning,
3228 the message format is defined so that the message end can be found without
3229 reference to the byte count. This aids validity checking. (The CopyData
3230 message is an exception, because it forms part of a data stream; the contents
3231 of any individual CopyData message cannot be interpretable on their own.)
3232 </para>
3234 <variablelist>
3235 <varlistentry id="protocol-message-formats-AuthenticationOk">
3236 <term>AuthenticationOk (B)</term>
3237 <listitem>
3238 <variablelist>
3239 <varlistentry>
3240 <term>Byte1('R')</term>
3241 <listitem>
3242 <para>
3243 Identifies the message as an authentication request.
3244 </para>
3245 </listitem>
3246 </varlistentry>
3248 <varlistentry>
3249 <term>Int32(8)</term>
3250 <listitem>
3251 <para>
3252 Length of message contents in bytes, including self.
3253 </para>
3254 </listitem>
3255 </varlistentry>
3257 <varlistentry>
3258 <term>Int32(0)</term>
3259 <listitem>
3260 <para>
3261 Specifies that the authentication was successful.
3262 </para>
3263 </listitem>
3264 </varlistentry>
3265 </variablelist>
3266 </listitem>
3267 </varlistentry>
3269 <varlistentry id="protocol-message-formats-AuthenticationKerberosV5">
3270 <term>AuthenticationKerberosV5 (B)</term>
3271 <listitem>
3273 <variablelist>
3274 <varlistentry>
3275 <term>Byte1('R')</term>
3276 <listitem>
3277 <para>
3278 Identifies the message as an authentication request.
3279 </para>
3280 </listitem>
3281 </varlistentry>
3283 <varlistentry>
3284 <term>Int32(8)</term>
3285 <listitem>
3286 <para>
3287 Length of message contents in bytes, including self.
3288 </para>
3289 </listitem>
3290 </varlistentry>
3292 <varlistentry>
3293 <term>Int32(2)</term>
3294 <listitem>
3295 <para>
3296 Specifies that Kerberos V5 authentication is required.
3297 </para>
3298 </listitem>
3299 </varlistentry>
3300 </variablelist>
3301 </listitem>
3302 </varlistentry>
3304 <varlistentry id="protocol-message-formats-AuthenticationCleartextPassword">
3305 <term>AuthenticationCleartextPassword (B)</term>
3306 <listitem>
3308 <variablelist>
3309 <varlistentry>
3310 <term>Byte1('R')</term>
3311 <listitem>
3312 <para>
3313 Identifies the message as an authentication request.
3314 </para>
3315 </listitem>
3316 </varlistentry>
3318 <varlistentry>
3319 <term>Int32(8)</term>
3320 <listitem>
3321 <para>
3322 Length of message contents in bytes, including self.
3323 </para>
3324 </listitem>
3325 </varlistentry>
3327 <varlistentry>
3328 <term>Int32(3)</term>
3329 <listitem>
3330 <para>
3331 Specifies that a clear-text password is required.
3332 </para>
3333 </listitem>
3334 </varlistentry>
3335 </variablelist>
3336 </listitem>
3337 </varlistentry>
3339 <varlistentry id="protocol-message-formats-AuthenticationMD5Password">
3340 <term>AuthenticationMD5Password (B)</term>
3341 <listitem>
3342 <variablelist>
3343 <varlistentry>
3344 <term>Byte1('R')</term>
3345 <listitem>
3346 <para>
3347 Identifies the message as an authentication request.
3348 </para>
3349 </listitem>
3350 </varlistentry>
3352 <varlistentry>
3353 <term>Int32(12)</term>
3354 <listitem>
3355 <para>
3356 Length of message contents in bytes, including self.
3357 </para>
3358 </listitem>
3359 </varlistentry>
3361 <varlistentry>
3362 <term>Int32(5)</term>
3363 <listitem>
3364 <para>
3365 Specifies that an MD5-encrypted password is required.
3366 </para>
3367 </listitem>
3368 </varlistentry>
3370 <varlistentry>
3371 <term>Byte4</term>
3372 <listitem>
3373 <para>
3374 The salt to use when encrypting the password.
3375 </para>
3376 </listitem>
3377 </varlistentry>
3378 </variablelist>
3379 </listitem>
3380 </varlistentry>
3382 <varlistentry id="protocol-message-formats-AuthenticationSCMCredential">
3383 <term>AuthenticationSCMCredential (B)</term>
3384 <listitem>
3385 <variablelist>
3386 <varlistentry>
3387 <term>Byte1('R')</term>
3388 <listitem>
3389 <para>
3390 Identifies the message as an authentication request.
3391 </para>
3392 </listitem>
3393 </varlistentry>
3395 <varlistentry>
3396 <term>Int32(8)</term>
3397 <listitem>
3398 <para>
3399 Length of message contents in bytes, including self.
3400 </para>
3401 </listitem>
3402 </varlistentry>
3404 <varlistentry>
3405 <term>Int32(6)</term>
3406 <listitem>
3407 <para>
3408 Specifies that an SCM credentials message is required.
3409 </para>
3410 </listitem>
3411 </varlistentry>
3412 </variablelist>
3413 </listitem>
3414 </varlistentry>
3416 <varlistentry id="protocol-message-formats-AuthenticationGSS">
3417 <term>AuthenticationGSS (B)</term>
3418 <listitem>
3419 <variablelist>
3420 <varlistentry>
3421 <term>Byte1('R')</term>
3422 <listitem>
3423 <para>
3424 Identifies the message as an authentication request.
3425 </para>
3426 </listitem>
3427 </varlistentry>
3428 <varlistentry>
3429 <term>Int32(8)</term>
3430 <listitem>
3431 <para>
3432 Length of message contents in bytes, including self.
3433 </para>
3434 </listitem>
3435 </varlistentry>
3437 <varlistentry>
3438 <term>Int32(7)</term>
3439 <listitem>
3440 <para>
3441 Specifies that GSSAPI authentication is required.
3442 </para>
3443 </listitem>
3444 </varlistentry>
3445 </variablelist>
3446 </listitem>
3447 </varlistentry>
3449 <varlistentry id="protocol-message-formats-AuthenticationGSSContinue">
3450 <term>AuthenticationGSSContinue (B)</term>
3451 <listitem>
3452 <variablelist>
3453 <varlistentry>
3454 <term>Byte1('R')</term>
3455 <listitem>
3456 <para>
3457 Identifies the message as an authentication request.
3458 </para>
3459 </listitem>
3460 </varlistentry>
3462 <varlistentry>
3463 <term>Int32</term>
3464 <listitem>
3465 <para>
3466 Length of message contents in bytes, including self.
3467 </para>
3468 </listitem>
3469 </varlistentry>
3471 <varlistentry>
3472 <term>Int32(8)</term>
3473 <listitem>
3474 <para>
3475 Specifies that this message contains GSSAPI or SSPI data.
3476 </para>
3477 </listitem>
3478 </varlistentry>
3480 <varlistentry>
3481 <term>Byte<replaceable>n</replaceable></term>
3482 <listitem>
3483 <para>
3484 GSSAPI or SSPI authentication data.
3485 </para>
3486 </listitem>
3487 </varlistentry>
3488 </variablelist>
3489 </listitem>
3490 </varlistentry>
3492 <varlistentry id="protocol-message-formats-AuthenticationSSPI">
3493 <term>AuthenticationSSPI (B)</term>
3494 <listitem>
3495 <variablelist>
3496 <varlistentry>
3497 <term>Byte1('R')</term>
3498 <listitem>
3499 <para>
3500 Identifies the message as an authentication request.
3501 </para>
3502 </listitem>
3503 </varlistentry>
3505 <varlistentry>
3506 <term>Int32(8)</term>
3507 <listitem>
3508 <para>
3509 Length of message contents in bytes, including self.
3510 </para>
3511 </listitem>
3512 </varlistentry>
3514 <varlistentry>
3515 <term>Int32(9)</term>
3516 <listitem>
3517 <para>
3518 Specifies that SSPI authentication is required.
3519 </para>
3520 </listitem>
3521 </varlistentry>
3522 </variablelist>
3523 </listitem>
3524 </varlistentry>
3526 <varlistentry id="protocol-message-formats-AuthenticationSASL">
3527 <term>AuthenticationSASL (B)</term>
3528 <listitem>
3529 <variablelist>
3530 <varlistentry>
3531 <term>Byte1('R')</term>
3532 <listitem>
3533 <para>
3534 Identifies the message as an authentication request.
3535 </para>
3536 </listitem>
3537 </varlistentry>
3539 <varlistentry>
3540 <term>Int32</term>
3541 <listitem>
3542 <para>
3543 Length of message contents in bytes, including self.
3544 </para>
3545 </listitem>
3546 </varlistentry>
3548 <varlistentry>
3549 <term>Int32(10)</term>
3550 <listitem>
3551 <para>
3552 Specifies that SASL authentication is required.
3553 </para>
3554 </listitem>
3555 </varlistentry>
3556 </variablelist>
3558 <para>
3559 The message body is a list of SASL authentication mechanisms, in the
3560 server's order of preference. A zero byte is required as terminator after
3561 the last authentication mechanism name. For each mechanism, there is the
3562 following:
3564 <variablelist>
3565 <varlistentry>
3566 <term>String</term>
3567 <listitem>
3568 <para>
3569 Name of a SASL authentication mechanism.
3570 </para>
3571 </listitem>
3572 </varlistentry>
3573 </variablelist>
3574 </para>
3575 </listitem>
3576 </varlistentry>
3578 <varlistentry id="protocol-message-formats-AuthenticationSASLContinue">
3579 <term>AuthenticationSASLContinue (B)</term>
3580 <listitem>
3581 <variablelist>
3582 <varlistentry>
3583 <term>Byte1('R')</term>
3584 <listitem>
3585 <para>
3586 Identifies the message as an authentication request.
3587 </para>
3588 </listitem>
3589 </varlistentry>
3591 <varlistentry>
3592 <term>Int32</term>
3593 <listitem>
3594 <para>
3595 Length of message contents in bytes, including self.
3596 </para>
3597 </listitem>
3598 </varlistentry>
3600 <varlistentry>
3601 <term>Int32(11)</term>
3602 <listitem>
3603 <para>
3604 Specifies that this message contains a SASL challenge.
3605 </para>
3606 </listitem>
3607 </varlistentry>
3609 <varlistentry>
3610 <term>Byte<replaceable>n</replaceable></term>
3611 <listitem>
3612 <para>
3613 SASL data, specific to the SASL mechanism being used.
3614 </para>
3615 </listitem>
3616 </varlistentry>
3617 </variablelist>
3618 </listitem>
3619 </varlistentry>
3621 <varlistentry id="protocol-message-formats-AuthenticationSASLFinal">
3622 <term>AuthenticationSASLFinal (B)</term>
3623 <listitem>
3624 <variablelist>
3625 <varlistentry>
3626 <term>Byte1('R')</term>
3627 <listitem>
3628 <para>
3629 Identifies the message as an authentication request.
3630 </para>
3631 </listitem>
3632 </varlistentry>
3634 <varlistentry>
3635 <term>Int32</term>
3636 <listitem>
3637 <para>
3638 Length of message contents in bytes, including self.
3639 </para>
3640 </listitem>
3641 </varlistentry>
3643 <varlistentry>
3644 <term>Int32(12)</term>
3645 <listitem>
3646 <para>
3647 Specifies that SASL authentication has completed.
3648 </para>
3649 </listitem>
3650 </varlistentry>
3652 <varlistentry>
3653 <term>Byte<replaceable>n</replaceable></term>
3654 <listitem>
3655 <para>
3656 SASL outcome "additional data", specific to the SASL mechanism
3657 being used.
3658 </para>
3659 </listitem>
3660 </varlistentry>
3661 </variablelist>
3662 </listitem>
3663 </varlistentry>
3665 <varlistentry id="protocol-message-formats-BackendKeyData">
3666 <term>BackendKeyData (B)</term>
3667 <listitem>
3668 <variablelist>
3669 <varlistentry>
3670 <term>Byte1('K')</term>
3671 <listitem>
3672 <para>
3673 Identifies the message as cancellation key data.
3674 The frontend must save these values if it wishes to be
3675 able to issue CancelRequest messages later.
3676 </para>
3677 </listitem>
3678 </varlistentry>
3680 <varlistentry>
3681 <term>Int32(12)</term>
3682 <listitem>
3683 <para>
3684 Length of message contents in bytes, including self.
3685 </para>
3686 </listitem>
3687 </varlistentry>
3689 <varlistentry>
3690 <term>Int32</term>
3691 <listitem>
3692 <para>
3693 The process ID of this backend.
3694 </para>
3695 </listitem>
3696 </varlistentry>
3698 <varlistentry>
3699 <term>Int32</term>
3700 <listitem>
3701 <para>
3702 The secret key of this backend.
3703 </para>
3704 </listitem>
3705 </varlistentry>
3706 </variablelist>
3707 </listitem>
3708 </varlistentry>
3710 <varlistentry id="protocol-message-formats-Bind">
3711 <term>Bind (F)</term>
3712 <listitem>
3713 <variablelist>
3714 <varlistentry>
3715 <term>Byte1('B')</term>
3716 <listitem>
3717 <para>
3718 Identifies the message as a Bind command.
3719 </para>
3720 </listitem>
3721 </varlistentry>
3723 <varlistentry>
3724 <term>Int32</term>
3725 <listitem>
3726 <para>
3727 Length of message contents in bytes, including self.
3728 </para>
3729 </listitem>
3730 </varlistentry>
3732 <varlistentry>
3733 <term>String</term>
3734 <listitem>
3735 <para>
3736 The name of the destination portal
3737 (an empty string selects the unnamed portal).
3738 </para>
3739 </listitem>
3740 </varlistentry>
3742 <varlistentry>
3743 <term>String</term>
3744 <listitem>
3745 <para>
3746 The name of the source prepared statement
3747 (an empty string selects the unnamed prepared statement).
3748 </para>
3749 </listitem>
3750 </varlistentry>
3752 <varlistentry>
3753 <term>Int16</term>
3754 <listitem>
3755 <para>
3756 The number of parameter format codes that follow
3757 (denoted <replaceable>C</replaceable> below).
3758 This can be zero to indicate that there are no parameters
3759 or that the parameters all use the default format (text);
3760 or one, in which case the specified format code is applied
3761 to all parameters; or it can equal the actual number of
3762 parameters.
3763 </para>
3764 </listitem>
3765 </varlistentry>
3767 <varlistentry>
3768 <term>Int16[<replaceable>C</replaceable>]</term>
3769 <listitem>
3770 <para>
3771 The parameter format codes. Each must presently be
3772 zero (text) or one (binary).
3773 </para>
3774 </listitem>
3775 </varlistentry>
3777 <varlistentry>
3778 <term>Int16</term>
3779 <listitem>
3780 <para>
3781 The number of parameter values that follow (possibly zero).
3782 This must match the number of parameters needed by the query.
3783 </para>
3784 </listitem>
3785 </varlistentry>
3786 </variablelist>
3788 <para>
3789 Next, the following pair of fields appear for each parameter:
3790 </para>
3792 <variablelist>
3793 <varlistentry>
3794 <term>Int32</term>
3795 <listitem>
3796 <para>
3797 The length of the parameter value, in bytes (this count
3798 does not include itself). Can be zero.
3799 As a special case, -1 indicates a NULL parameter value.
3800 No value bytes follow in the NULL case.
3801 </para>
3802 </listitem>
3803 </varlistentry>
3805 <varlistentry>
3806 <term>Byte<replaceable>n</replaceable></term>
3807 <listitem>
3808 <para>
3809 The value of the parameter, in the format indicated by the
3810 associated format code.
3811 <replaceable>n</replaceable> is the above length.
3812 </para>
3813 </listitem>
3814 </varlistentry>
3815 </variablelist>
3817 <para>
3818 After the last parameter, the following fields appear:
3819 </para>
3821 <variablelist>
3822 <varlistentry>
3823 <term>Int16</term>
3824 <listitem>
3825 <para>
3826 The number of result-column format codes that follow
3827 (denoted <replaceable>R</replaceable> below).
3828 This can be zero to indicate that there are no result columns
3829 or that the result columns should all use the default format
3830 (text);
3831 or one, in which case the specified format code is applied
3832 to all result columns (if any); or it can equal the actual
3833 number of result columns of the query.
3834 </para>
3835 </listitem>
3836 </varlistentry>
3838 <varlistentry>
3839 <term>Int16[<replaceable>R</replaceable>]</term>
3840 <listitem>
3841 <para>
3842 The result-column format codes. Each must presently be
3843 zero (text) or one (binary).
3844 </para>
3845 </listitem>
3846 </varlistentry>
3847 </variablelist>
3848 </listitem>
3849 </varlistentry>
3851 <varlistentry id="protocol-message-formats-BindComplete">
3852 <term>BindComplete (B)</term>
3853 <listitem>
3854 <variablelist>
3855 <varlistentry>
3856 <term>Byte1('2')</term>
3857 <listitem>
3858 <para>
3859 Identifies the message as a Bind-complete indicator.
3860 </para>
3861 </listitem>
3862 </varlistentry>
3864 <varlistentry>
3865 <term>Int32(4)</term>
3866 <listitem>
3867 <para>
3868 Length of message contents in bytes, including self.
3869 </para>
3870 </listitem>
3871 </varlistentry>
3873 </variablelist>
3874 </listitem>
3875 </varlistentry>
3877 <varlistentry id="protocol-message-formats-CancelRequest">
3878 <term>CancelRequest (F)</term>
3879 <listitem>
3880 <variablelist>
3881 <varlistentry>
3882 <term>Int32(16)</term>
3883 <listitem>
3884 <para>
3885 Length of message contents in bytes, including self.
3886 </para>
3887 </listitem>
3888 </varlistentry>
3890 <varlistentry>
3891 <term>Int32(80877102)</term>
3892 <listitem>
3893 <para>
3894 The cancel request code. The value is chosen to contain
3895 <literal>1234</literal> in the most significant 16 bits, and <literal>5678</literal> in the
3896 least significant 16 bits. (To avoid confusion, this code
3897 must not be the same as any protocol version number.)
3898 </para>
3899 </listitem>
3900 </varlistentry>
3902 <varlistentry>
3903 <term>Int32</term>
3904 <listitem>
3905 <para>
3906 The process ID of the target backend.
3907 </para>
3908 </listitem>
3909 </varlistentry>
3911 <varlistentry>
3912 <term>Int32</term>
3913 <listitem>
3914 <para>
3915 The secret key for the target backend.
3916 </para>
3917 </listitem>
3918 </varlistentry>
3919 </variablelist>
3920 </listitem>
3921 </varlistentry>
3923 <varlistentry id="protocol-message-formats-Close">
3924 <term>Close (F)</term>
3925 <listitem>
3926 <variablelist>
3927 <varlistentry>
3928 <term>Byte1('C')</term>
3929 <listitem>
3930 <para>
3931 Identifies the message as a Close command.
3932 </para>
3933 </listitem>
3934 </varlistentry>
3936 <varlistentry>
3937 <term>Int32</term>
3938 <listitem>
3939 <para>
3940 Length of message contents in bytes, including self.
3941 </para>
3942 </listitem>
3943 </varlistentry>
3945 <varlistentry>
3946 <term>Byte1</term>
3947 <listitem>
3948 <para>
3949 '<literal>S</literal>' to close a prepared statement; or
3950 '<literal>P</literal>' to close a portal.
3951 </para>
3952 </listitem>
3953 </varlistentry>
3955 <varlistentry>
3956 <term>String</term>
3957 <listitem>
3958 <para>
3959 The name of the prepared statement or portal to close
3960 (an empty string selects the unnamed prepared statement
3961 or portal).
3962 </para>
3963 </listitem>
3964 </varlistentry>
3965 </variablelist>
3966 </listitem>
3967 </varlistentry>
3969 <varlistentry id="protocol-message-formats-CloseComplete">
3970 <term>CloseComplete (B)</term>
3971 <listitem>
3972 <variablelist>
3973 <varlistentry>
3974 <term>Byte1('3')</term>
3975 <listitem>
3976 <para>
3977 Identifies the message as a Close-complete indicator.
3978 </para>
3979 </listitem>
3980 </varlistentry>
3982 <varlistentry>
3983 <term>Int32(4)</term>
3984 <listitem>
3985 <para>
3986 Length of message contents in bytes, including self.
3987 </para>
3988 </listitem>
3989 </varlistentry>
3990 </variablelist>
3991 </listitem>
3992 </varlistentry>
3994 <varlistentry id="protocol-message-formats-CommandComplete">
3995 <term>CommandComplete (B)</term>
3996 <listitem>
3997 <variablelist>
3998 <varlistentry>
3999 <term>Byte1('C')</term>
4000 <listitem>
4001 <para>
4002 Identifies the message as a command-completed response.
4003 </para>
4004 </listitem>
4005 </varlistentry>
4007 <varlistentry>
4008 <term>Int32</term>
4009 <listitem>
4010 <para>
4011 Length of message contents in bytes, including self.
4012 </para>
4013 </listitem>
4014 </varlistentry>
4016 <varlistentry>
4017 <term>String</term>
4018 <listitem>
4019 <para>
4020 The command tag. This is usually a single
4021 word that identifies which SQL command was completed.
4022 </para>
4024 <para>
4025 For an <command>INSERT</command> command, the tag is
4026 <literal>INSERT <replaceable>oid</replaceable>
4027 <replaceable>rows</replaceable></literal>, where
4028 <replaceable>rows</replaceable> is the number of rows
4029 inserted. <replaceable>oid</replaceable> used to be the object ID
4030 of the inserted row if <replaceable>rows</replaceable> was 1
4031 and the target table had OIDs, but OIDs system columns are
4032 not supported anymore; therefore <replaceable>oid</replaceable>
4033 is always 0.
4034 </para>
4036 <para>
4037 For a <command>DELETE</command> command, the tag is
4038 <literal>DELETE <replaceable>rows</replaceable></literal> where
4039 <replaceable>rows</replaceable> is the number of rows deleted.
4040 </para>
4042 <para>
4043 For an <command>UPDATE</command> command, the tag is
4044 <literal>UPDATE <replaceable>rows</replaceable></literal> where
4045 <replaceable>rows</replaceable> is the number of rows updated.
4046 </para>
4048 <para>
4049 For a <command>SELECT</command> or <command>CREATE TABLE AS</command>
4050 command, the tag is <literal>SELECT <replaceable>rows</replaceable></literal>
4051 where <replaceable>rows</replaceable> is the number of rows retrieved.
4052 </para>
4054 <para>
4055 For a <command>MOVE</command> command, the tag is
4056 <literal>MOVE <replaceable>rows</replaceable></literal> where
4057 <replaceable>rows</replaceable> is the number of rows the
4058 cursor's position has been changed by.
4059 </para>
4061 <para>
4062 For a <command>FETCH</command> command, the tag is
4063 <literal>FETCH <replaceable>rows</replaceable></literal> where
4064 <replaceable>rows</replaceable> is the number of rows that
4065 have been retrieved from the cursor.
4066 </para>
4068 <para>
4069 For a <command>COPY</command> command, the tag is
4070 <literal>COPY <replaceable>rows</replaceable></literal> where
4071 <replaceable>rows</replaceable> is the number of rows copied.
4072 (Note: the row count appears only in
4073 <productname>PostgreSQL</productname> 8.2 and later.)
4074 </para>
4075 </listitem>
4076 </varlistentry>
4077 </variablelist>
4078 </listitem>
4079 </varlistentry>
4081 <varlistentry id="protocol-message-formats-CopyData">
4082 <term>CopyData (F &amp; B)</term>
4083 <listitem>
4084 <variablelist>
4085 <varlistentry>
4086 <term>Byte1('d')</term>
4087 <listitem>
4088 <para>
4089 Identifies the message as <command>COPY</command> data.
4090 </para>
4091 </listitem>
4092 </varlistentry>
4094 <varlistentry>
4095 <term>Int32</term>
4096 <listitem>
4097 <para>
4098 Length of message contents in bytes, including self.
4099 </para>
4100 </listitem>
4101 </varlistentry>
4103 <varlistentry>
4104 <term>Byte<replaceable>n</replaceable></term>
4105 <listitem>
4106 <para>
4107 Data that forms part of a <command>COPY</command> data stream. Messages sent
4108 from the backend will always correspond to single data rows,
4109 but messages sent by frontends might divide the data stream
4110 arbitrarily.
4111 </para>
4112 </listitem>
4113 </varlistentry>
4114 </variablelist>
4115 </listitem>
4116 </varlistentry>
4118 <varlistentry id="protocol-message-formats-CopyDone">
4119 <term>CopyDone (F &amp; B)</term>
4120 <listitem>
4121 <variablelist>
4122 <varlistentry>
4123 <term>Byte1('c')</term>
4124 <listitem>
4125 <para>
4126 Identifies the message as a <command>COPY</command>-complete indicator.
4127 </para>
4128 </listitem>
4129 </varlistentry>
4131 <varlistentry>
4132 <term>Int32(4)</term>
4133 <listitem>
4134 <para>
4135 Length of message contents in bytes, including self.
4136 </para>
4137 </listitem>
4138 </varlistentry>
4139 </variablelist>
4140 </listitem>
4141 </varlistentry>
4143 <varlistentry id="protocol-message-formats-CopyFail">
4144 <term>CopyFail (F)</term>
4145 <listitem>
4146 <variablelist>
4147 <varlistentry>
4148 <term>Byte1('f')</term>
4149 <listitem>
4150 <para>
4151 Identifies the message as a <command>COPY</command>-failure indicator.
4152 </para>
4153 </listitem>
4154 </varlistentry>
4155 <varlistentry>
4156 <term>Int32</term>
4157 <listitem>
4158 <para>
4159 Length of message contents in bytes, including self.
4160 </para>
4161 </listitem>
4162 </varlistentry>
4164 <varlistentry>
4165 <term>String</term>
4166 <listitem>
4167 <para>
4168 An error message to report as the cause of failure.
4169 </para>
4170 </listitem>
4171 </varlistentry>
4172 </variablelist>
4173 </listitem>
4174 </varlistentry>
4176 <varlistentry id="protocol-message-formats-CopyInResponse">
4177 <term>CopyInResponse (B)</term>
4178 <listitem>
4179 <variablelist>
4180 <varlistentry>
4181 <term>Byte1('G')</term>
4182 <listitem>
4183 <para>
4184 Identifies the message as a Start Copy In response.
4185 The frontend must now send copy-in data (if not
4186 prepared to do so, send a CopyFail message).
4187 </para>
4188 </listitem>
4189 </varlistentry>
4191 <varlistentry>
4192 <term>Int32</term>
4193 <listitem>
4194 <para>
4195 Length of message contents in bytes, including self.
4196 </para>
4197 </listitem>
4198 </varlistentry>
4200 <varlistentry>
4201 <term>Int8</term>
4202 <listitem>
4203 <para>
4204 0 indicates the overall <command>COPY</command> format is textual (rows
4205 separated by newlines, columns separated by separator
4206 characters, etc).
4207 1 indicates the overall copy format is binary (similar
4208 to DataRow format).
4209 See <xref linkend="sql-copy"/>
4210 for more information.
4211 </para>
4212 </listitem>
4213 </varlistentry>
4215 <varlistentry>
4216 <term>Int16</term>
4217 <listitem>
4218 <para>
4219 The number of columns in the data to be copied
4220 (denoted <replaceable>N</replaceable> below).
4221 </para>
4222 </listitem>
4223 </varlistentry>
4225 <varlistentry>
4226 <term>Int16[<replaceable>N</replaceable>]</term>
4227 <listitem>
4228 <para>
4229 The format codes to be used for each column.
4230 Each must presently be zero (text) or one (binary).
4231 All must be zero if the overall copy format is textual.
4232 </para>
4233 </listitem>
4234 </varlistentry>
4235 </variablelist>
4236 </listitem>
4237 </varlistentry>
4239 <varlistentry id="protocol-message-formats-CopyOutResponse">
4240 <term>CopyOutResponse (B)</term>
4241 <listitem>
4242 <variablelist>
4243 <varlistentry>
4244 <term>Byte1('H')</term>
4245 <listitem>
4246 <para>
4247 Identifies the message as a Start Copy Out response.
4248 This message will be followed by copy-out data.
4249 </para>
4250 </listitem>
4251 </varlistentry>
4253 <varlistentry>
4254 <term>Int32</term>
4255 <listitem>
4256 <para>
4257 Length of message contents in bytes, including self.
4258 </para>
4259 </listitem>
4260 </varlistentry>
4262 <varlistentry>
4263 <term>Int8</term>
4264 <listitem>
4265 <para>
4266 0 indicates the overall <command>COPY</command> format
4267 is textual (rows separated by newlines, columns
4268 separated by separator characters, etc). 1 indicates
4269 the overall copy format is binary (similar to DataRow
4270 format). See <xref linkend="sql-copy"/> for more information.
4271 </para>
4272 </listitem>
4273 </varlistentry>
4275 <varlistentry>
4276 <term>Int16</term>
4277 <listitem>
4278 <para>
4279 The number of columns in the data to be copied
4280 (denoted <replaceable>N</replaceable> below).
4281 </para>
4282 </listitem>
4283 </varlistentry>
4285 <varlistentry>
4286 <term>Int16[<replaceable>N</replaceable>]</term>
4287 <listitem>
4288 <para>
4289 The format codes to be used for each column.
4290 Each must presently be zero (text) or one (binary).
4291 All must be zero if the overall copy format is textual.
4292 </para>
4293 </listitem>
4294 </varlistentry>
4295 </variablelist>
4296 </listitem>
4297 </varlistentry>
4299 <varlistentry id="protocol-message-formats-CopyBothResponse">
4300 <term>CopyBothResponse (B)</term>
4301 <listitem>
4302 <variablelist>
4303 <varlistentry>
4304 <term>Byte1('W')</term>
4305 <listitem>
4306 <para>
4307 Identifies the message as a Start Copy Both response.
4308 This message is used only for Streaming Replication.
4309 </para>
4310 </listitem>
4311 </varlistentry>
4313 <varlistentry>
4314 <term>Int32</term>
4315 <listitem>
4316 <para>
4317 Length of message contents in bytes, including self.
4318 </para>
4319 </listitem>
4320 </varlistentry>
4322 <varlistentry>
4323 <term>Int8</term>
4324 <listitem>
4325 <para>
4326 0 indicates the overall <command>COPY</command> format
4327 is textual (rows separated by newlines, columns
4328 separated by separator characters, etc). 1 indicates
4329 the overall copy format is binary (similar to DataRow
4330 format). See <xref linkend="sql-copy"/> for more information.
4331 </para>
4332 </listitem>
4333 </varlistentry>
4335 <varlistentry>
4336 <term>Int16</term>
4337 <listitem>
4338 <para>
4339 The number of columns in the data to be copied
4340 (denoted <replaceable>N</replaceable> below).
4341 </para>
4342 </listitem>
4343 </varlistentry>
4345 <varlistentry>
4346 <term>Int16[<replaceable>N</replaceable>]</term>
4347 <listitem>
4348 <para>
4349 The format codes to be used for each column.
4350 Each must presently be zero (text) or one (binary).
4351 All must be zero if the overall copy format is textual.
4352 </para>
4353 </listitem>
4354 </varlistentry>
4355 </variablelist>
4356 </listitem>
4357 </varlistentry>
4359 <varlistentry id="protocol-message-formats-DataRow">
4360 <term>DataRow (B)</term>
4361 <listitem>
4362 <variablelist>
4363 <varlistentry>
4364 <term>Byte1('D')</term>
4365 <listitem>
4366 <para>
4367 Identifies the message as a data row.
4368 </para>
4369 </listitem>
4370 </varlistentry>
4372 <varlistentry>
4373 <term>Int32</term>
4374 <listitem>
4375 <para>
4376 Length of message contents in bytes, including self.
4377 </para>
4378 </listitem>
4379 </varlistentry>
4381 <varlistentry>
4382 <term>Int16</term>
4383 <listitem>
4384 <para>
4385 The number of column values that follow (possibly zero).
4386 </para>
4387 </listitem>
4388 </varlistentry>
4389 </variablelist>
4391 <para>
4392 Next, the following pair of fields appear for each column:
4393 </para>
4395 <variablelist>
4396 <varlistentry>
4397 <term>Int32</term>
4398 <listitem>
4399 <para>
4400 The length of the column value, in bytes (this count
4401 does not include itself). Can be zero.
4402 As a special case, -1 indicates a NULL column value.
4403 No value bytes follow in the NULL case.
4404 </para>
4405 </listitem>
4406 </varlistentry>
4408 <varlistentry>
4409 <term>Byte<replaceable>n</replaceable></term>
4410 <listitem>
4411 <para>
4412 The value of the column, in the format indicated by the
4413 associated format code.
4414 <replaceable>n</replaceable> is the above length.
4415 </para>
4416 </listitem>
4417 </varlistentry>
4418 </variablelist>
4419 </listitem>
4420 </varlistentry>
4422 <varlistentry id="protocol-message-formats-Describe">
4423 <term>Describe (F)</term>
4424 <listitem>
4425 <variablelist>
4426 <varlistentry>
4427 <term>Byte1('D')</term>
4428 <listitem>
4429 <para>
4430 Identifies the message as a Describe command.
4431 </para>
4432 </listitem>
4433 </varlistentry>
4435 <varlistentry>
4436 <term>Int32</term>
4437 <listitem>
4438 <para>
4439 Length of message contents in bytes, including self.
4440 </para>
4441 </listitem>
4442 </varlistentry>
4444 <varlistentry>
4445 <term>Byte1</term>
4446 <listitem>
4447 <para>
4448 '<literal>S</literal>' to describe a prepared statement; or
4449 '<literal>P</literal>' to describe a portal.
4450 </para>
4451 </listitem>
4452 </varlistentry>
4454 <varlistentry>
4455 <term>String</term>
4456 <listitem>
4457 <para>
4458 The name of the prepared statement or portal to describe
4459 (an empty string selects the unnamed prepared statement
4460 or portal).
4461 </para>
4462 </listitem>
4463 </varlistentry>
4464 </variablelist>
4465 </listitem>
4466 </varlistentry>
4468 <varlistentry id="protocol-message-formats-EmptyQueryResponse">
4469 <term>EmptyQueryResponse (B)</term>
4470 <listitem>
4471 <variablelist>
4472 <varlistentry>
4473 <term>Byte1('I')</term>
4474 <listitem>
4475 <para>
4476 Identifies the message as a response to an empty query string.
4477 (This substitutes for CommandComplete.)
4478 </para>
4479 </listitem>
4480 </varlistentry>
4482 <varlistentry>
4483 <term>Int32(4)</term>
4484 <listitem>
4485 <para>
4486 Length of message contents in bytes, including self.
4487 </para>
4488 </listitem>
4489 </varlistentry>
4490 </variablelist>
4491 </listitem>
4492 </varlistentry>
4494 <varlistentry id="protocol-message-formats-ErrorResponse">
4495 <term>ErrorResponse (B)</term>
4496 <listitem>
4497 <variablelist>
4498 <varlistentry>
4499 <term>Byte1('E')</term>
4500 <listitem>
4501 <para>
4502 Identifies the message as an error.
4503 </para>
4504 </listitem>
4505 </varlistentry>
4507 <varlistentry>
4508 <term>Int32</term>
4509 <listitem>
4510 <para>
4511 Length of message contents in bytes, including self.
4512 </para>
4513 </listitem>
4514 </varlistentry>
4515 </variablelist>
4517 <para>
4518 The message body consists of one or more identified fields,
4519 followed by a zero byte as a terminator. Fields can appear in
4520 any order. For each field there is the following:
4521 </para>
4523 <variablelist>
4524 <varlistentry>
4525 <term>Byte1</term>
4526 <listitem>
4527 <para>
4528 A code identifying the field type; if zero, this is
4529 the message terminator and no string follows.
4530 The presently defined field types are listed in
4531 <xref linkend="protocol-error-fields"/>.
4532 Since more field types might be added in future,
4533 frontends should silently ignore fields of unrecognized
4534 type.
4535 </para>
4536 </listitem>
4537 </varlistentry>
4539 <varlistentry>
4540 <term>String</term>
4541 <listitem>
4542 <para>
4543 The field value.
4544 </para>
4545 </listitem>
4546 </varlistentry>
4547 </variablelist>
4548 </listitem>
4549 </varlistentry>
4551 <varlistentry id="protocol-message-formats-Execute">
4552 <term>Execute (F)</term>
4553 <listitem>
4554 <variablelist>
4555 <varlistentry>
4556 <term>Byte1('E')</term>
4557 <listitem>
4558 <para>
4559 Identifies the message as an Execute command.
4560 </para>
4561 </listitem>
4562 </varlistentry>
4564 <varlistentry>
4565 <term>Int32</term>
4566 <listitem>
4567 <para>
4568 Length of message contents in bytes, including self.
4569 </para>
4570 </listitem>
4571 </varlistentry>
4573 <varlistentry>
4574 <term>String</term>
4575 <listitem>
4576 <para>
4577 The name of the portal to execute
4578 (an empty string selects the unnamed portal).
4579 </para>
4580 </listitem>
4581 </varlistentry>
4583 <varlistentry>
4584 <term>Int32</term>
4585 <listitem>
4586 <para>
4587 Maximum number of rows to return, if portal contains
4588 a query that returns rows (ignored otherwise). Zero
4589 denotes <quote>no limit</quote>.
4590 </para>
4591 </listitem>
4592 </varlistentry>
4593 </variablelist>
4594 </listitem>
4595 </varlistentry>
4597 <varlistentry id="protocol-message-formats-Flush">
4598 <term>Flush (F)</term>
4599 <listitem>
4600 <variablelist>
4601 <varlistentry>
4602 <term>Byte1('H')</term>
4603 <listitem>
4604 <para>
4605 Identifies the message as a Flush command.
4606 </para>
4607 </listitem>
4608 </varlistentry>
4610 <varlistentry>
4611 <term>Int32(4)</term>
4612 <listitem>
4613 <para>
4614 Length of message contents in bytes, including self.
4615 </para>
4616 </listitem>
4617 </varlistentry>
4618 </variablelist>
4619 </listitem>
4620 </varlistentry>
4622 <varlistentry id="protocol-message-formats-FunctionCall">
4623 <term>FunctionCall (F)</term>
4624 <listitem>
4625 <variablelist>
4626 <varlistentry>
4627 <term>Byte1('F')</term>
4628 <listitem>
4629 <para>
4630 Identifies the message as a function call.
4631 </para>
4632 </listitem>
4633 </varlistentry>
4635 <varlistentry>
4636 <term>Int32</term>
4637 <listitem>
4638 <para>
4639 Length of message contents in bytes, including self.
4640 </para>
4641 </listitem>
4642 </varlistentry>
4644 <varlistentry>
4645 <term>Int32</term>
4646 <listitem>
4647 <para>
4648 Specifies the object ID of the function to call.
4649 </para>
4650 </listitem>
4651 </varlistentry>
4653 <varlistentry>
4654 <term>Int16</term>
4655 <listitem>
4656 <para>
4657 The number of argument format codes that follow
4658 (denoted <replaceable>C</replaceable> below).
4659 This can be zero to indicate that there are no arguments
4660 or that the arguments all use the default format (text);
4661 or one, in which case the specified format code is applied
4662 to all arguments; or it can equal the actual number of
4663 arguments.
4664 </para>
4665 </listitem>
4666 </varlistentry>
4668 <varlistentry>
4669 <term>Int16[<replaceable>C</replaceable>]</term>
4670 <listitem>
4671 <para>
4672 The argument format codes. Each must presently be
4673 zero (text) or one (binary).
4674 </para>
4675 </listitem>
4676 </varlistentry>
4678 <varlistentry>
4679 <term>Int16</term>
4680 <listitem>
4681 <para>
4682 Specifies the number of arguments being supplied to the
4683 function.
4684 </para>
4685 </listitem>
4686 </varlistentry>
4687 </variablelist>
4689 <para>
4690 Next, the following pair of fields appear for each argument:
4691 </para>
4693 <variablelist>
4694 <varlistentry>
4695 <term>Int32</term>
4696 <listitem>
4697 <para>
4698 The length of the argument value, in bytes (this count
4699 does not include itself). Can be zero.
4700 As a special case, -1 indicates a NULL argument value.
4701 No value bytes follow in the NULL case.
4702 </para>
4703 </listitem>
4704 </varlistentry>
4706 <varlistentry>
4707 <term>Byte<replaceable>n</replaceable></term>
4708 <listitem>
4709 <para>
4710 The value of the argument, in the format indicated by the
4711 associated format code.
4712 <replaceable>n</replaceable> is the above length.
4713 </para>
4714 </listitem>
4715 </varlistentry>
4716 </variablelist>
4718 <para>
4719 After the last argument, the following field appears:
4720 </para>
4722 <variablelist>
4723 <varlistentry>
4724 <term>Int16</term>
4725 <listitem>
4726 <para>
4727 The format code for the function result. Must presently be
4728 zero (text) or one (binary).
4729 </para>
4730 </listitem>
4731 </varlistentry>
4732 </variablelist>
4733 </listitem>
4734 </varlistentry>
4736 <varlistentry id="protocol-message-formats-FunctionCallResponse">
4737 <term>FunctionCallResponse (B)</term>
4738 <listitem>
4739 <variablelist>
4740 <varlistentry>
4741 <term>Byte1('V')</term>
4742 <listitem>
4743 <para>
4744 Identifies the message as a function call result.
4745 </para>
4746 </listitem>
4747 </varlistentry>
4749 <varlistentry>
4750 <term>Int32</term>
4751 <listitem>
4752 <para>
4753 Length of message contents in bytes, including self.
4754 </para>
4755 </listitem>
4756 </varlistentry>
4758 <varlistentry>
4759 <term>Int32</term>
4760 <listitem>
4761 <para>
4762 The length of the function result value, in bytes (this count
4763 does not include itself). Can be zero.
4764 As a special case, -1 indicates a NULL function result.
4765 No value bytes follow in the NULL case.
4766 </para>
4767 </listitem>
4768 </varlistentry>
4770 <varlistentry>
4771 <term>Byte<replaceable>n</replaceable></term>
4772 <listitem>
4773 <para>
4774 The value of the function result, in the format indicated by
4775 the associated format code.
4776 <replaceable>n</replaceable> is the above length.
4777 </para>
4778 </listitem>
4779 </varlistentry>
4780 </variablelist>
4781 </listitem>
4782 </varlistentry>
4784 <varlistentry id="protocol-message-formats-GSSENCRequest">
4785 <term>GSSENCRequest (F)</term>
4786 <listitem>
4787 <variablelist>
4788 <varlistentry>
4789 <term>Int32(8)</term>
4790 <listitem>
4791 <para>
4792 Length of message contents in bytes, including self.
4793 </para>
4794 </listitem>
4795 </varlistentry>
4797 <varlistentry>
4798 <term>Int32(80877104)</term>
4799 <listitem>
4800 <para>
4801 The <acronym>GSSAPI</acronym> Encryption request code. The value is chosen to contain
4802 <literal>1234</literal> in the most significant 16 bits, and <literal>5680</literal> in the
4803 least significant 16 bits. (To avoid confusion, this code
4804 must not be the same as any protocol version number.)
4805 </para>
4806 </listitem>
4807 </varlistentry>
4808 </variablelist>
4809 </listitem>
4810 </varlistentry>
4812 <varlistentry id="protocol-message-formats-GSSResponse">
4813 <term>GSSResponse (F)</term>
4814 <listitem>
4815 <variablelist>
4816 <varlistentry>
4817 <term>Byte1('p')</term>
4818 <listitem>
4819 <para>
4820 Identifies the message as a GSSAPI or SSPI response. Note that
4821 this is also used for SASL and password response messages.
4822 The exact message type can be deduced from the context.
4823 </para>
4824 </listitem>
4825 </varlistentry>
4827 <varlistentry>
4828 <term>Int32</term>
4829 <listitem>
4830 <para>
4831 Length of message contents in bytes, including self.
4832 </para>
4833 </listitem>
4834 </varlistentry>
4836 <varlistentry>
4837 <term>Byte<replaceable>n</replaceable></term>
4838 <listitem>
4839 <para>
4840 GSSAPI/SSPI specific message data.
4841 </para>
4842 </listitem>
4843 </varlistentry>
4844 </variablelist>
4845 </listitem>
4846 </varlistentry>
4848 <varlistentry id="protocol-message-formats-NegotiateProtocolVersion">
4849 <term>NegotiateProtocolVersion (B)</term>
4850 <listitem>
4851 <variablelist>
4852 <varlistentry>
4853 <term>Byte1('v')</term>
4854 <listitem>
4855 <para>
4856 Identifies the message as a protocol version negotiation
4857 message.
4858 </para>
4859 </listitem>
4860 </varlistentry>
4862 <varlistentry>
4863 <term>Int32</term>
4864 <listitem>
4865 <para>
4866 Length of message contents in bytes, including self.
4867 </para>
4868 </listitem>
4869 </varlistentry>
4871 <varlistentry>
4872 <term>Int32</term>
4873 <listitem>
4874 <para>
4875 Newest minor protocol version supported by the server
4876 for the major protocol version requested by the client.
4877 </para>
4878 </listitem>
4879 </varlistentry>
4881 <varlistentry>
4882 <term>Int32</term>
4883 <listitem>
4884 <para>
4885 Number of protocol options not recognized by the server.
4886 </para>
4887 </listitem>
4888 </varlistentry>
4889 </variablelist>
4891 <para>
4892 Then, for protocol option not recognized by the server, there
4893 is the following:
4894 </para>
4896 <variablelist>
4897 <varlistentry>
4898 <term>String</term>
4899 <listitem>
4900 <para>
4901 The option name.
4902 </para>
4903 </listitem>
4904 </varlistentry>
4905 </variablelist>
4906 </listitem>
4907 </varlistentry>
4909 <varlistentry id="protocol-message-formats-NoData">
4910 <term>NoData (B)</term>
4911 <listitem>
4912 <variablelist>
4913 <varlistentry>
4914 <term>Byte1('n')</term>
4915 <listitem>
4916 <para>
4917 Identifies the message as a no-data indicator.
4918 </para>
4919 </listitem>
4920 </varlistentry>
4922 <varlistentry>
4923 <term>Int32(4)</term>
4924 <listitem>
4925 <para>
4926 Length of message contents in bytes, including self.
4927 </para>
4928 </listitem>
4929 </varlistentry>
4930 </variablelist>
4931 </listitem>
4932 </varlistentry>
4934 <varlistentry id="protocol-message-formats-NoticeResponse">
4935 <term>NoticeResponse (B)</term>
4936 <listitem>
4937 <variablelist>
4938 <varlistentry>
4939 <term>Byte1('N')</term>
4940 <listitem>
4941 <para>
4942 Identifies the message as a notice.
4943 </para>
4944 </listitem>
4945 </varlistentry>
4947 <varlistentry>
4948 <term>Int32</term>
4949 <listitem>
4950 <para>
4951 Length of message contents in bytes, including self.
4952 </para>
4953 </listitem>
4954 </varlistentry>
4955 </variablelist>
4957 <para>
4958 The message body consists of one or more identified fields,
4959 followed by a zero byte as a terminator. Fields can appear in
4960 any order. For each field there is the following:
4961 </para>
4963 <variablelist>
4964 <varlistentry>
4965 <term>Byte1</term>
4966 <listitem>
4967 <para>
4968 A code identifying the field type; if zero, this is
4969 the message terminator and no string follows.
4970 The presently defined field types are listed in
4971 <xref linkend="protocol-error-fields"/>.
4972 Since more field types might be added in future,
4973 frontends should silently ignore fields of unrecognized
4974 type.
4975 </para>
4976 </listitem>
4977 </varlistentry>
4979 <varlistentry>
4980 <term>String</term>
4981 <listitem>
4982 <para>
4983 The field value.
4984 </para>
4985 </listitem>
4986 </varlistentry>
4987 </variablelist>
4988 </listitem>
4989 </varlistentry>
4991 <varlistentry id="protocol-message-formats-NotificationResponse">
4992 <term>NotificationResponse (B)</term>
4993 <listitem>
4994 <variablelist>
4995 <varlistentry>
4996 <term>Byte1('A')</term>
4997 <listitem>
4998 <para>
4999 Identifies the message as a notification response.
5000 </para>
5001 </listitem>
5002 </varlistentry>
5004 <varlistentry>
5005 <term>Int32</term>
5006 <listitem>
5007 <para>
5008 Length of message contents in bytes, including self.
5009 </para>
5010 </listitem>
5011 </varlistentry>
5013 <varlistentry>
5014 <term>Int32</term>
5015 <listitem>
5016 <para>
5017 The process ID of the notifying backend process.
5018 </para>
5019 </listitem>
5020 </varlistentry>
5022 <varlistentry>
5023 <term>String</term>
5024 <listitem>
5025 <para>
5026 The name of the channel that the notify has been raised on.
5027 </para>
5028 </listitem>
5029 </varlistentry>
5031 <varlistentry>
5032 <term>String</term>
5033 <listitem>
5034 <para>
5035 The <quote>payload</quote> string passed from the notifying process.
5036 </para>
5037 </listitem>
5038 </varlistentry>
5039 </variablelist>
5040 </listitem>
5041 </varlistentry>
5043 <varlistentry id="protocol-message-formats-ParameterDescription">
5044 <term>ParameterDescription (B)</term>
5045 <listitem>
5046 <variablelist>
5047 <varlistentry>
5048 <term>Byte1('t')</term>
5049 <listitem>
5050 <para>
5051 Identifies the message as a parameter description.
5052 </para>
5053 </listitem>
5054 </varlistentry>
5056 <varlistentry>
5057 <term>Int32</term>
5058 <listitem>
5059 <para>
5060 Length of message contents in bytes, including self.
5061 </para>
5062 </listitem>
5063 </varlistentry>
5065 <varlistentry>
5066 <term>Int16</term>
5067 <listitem>
5068 <para>
5069 The number of parameters used by the statement
5070 (can be zero).
5071 </para>
5072 </listitem>
5073 </varlistentry>
5074 </variablelist>
5076 <para>
5077 Then, for each parameter, there is the following:
5078 </para>
5080 <variablelist>
5081 <varlistentry>
5082 <term>Int32</term>
5083 <listitem>
5084 <para>
5085 Specifies the object ID of the parameter data type.
5086 </para>
5087 </listitem>
5088 </varlistentry>
5089 </variablelist>
5090 </listitem>
5091 </varlistentry>
5093 <varlistentry id="protocol-message-formats-ParameterStatus">
5094 <term>ParameterStatus (B)</term>
5095 <listitem>
5096 <variablelist>
5097 <varlistentry>
5098 <term>Byte1('S')</term>
5099 <listitem>
5100 <para>
5101 Identifies the message as a run-time parameter status report.
5102 </para>
5103 </listitem>
5104 </varlistentry>
5106 <varlistentry>
5107 <term>Int32</term>
5108 <listitem>
5109 <para>
5110 Length of message contents in bytes, including self.
5111 </para>
5112 </listitem>
5113 </varlistentry>
5115 <varlistentry>
5116 <term>String</term>
5117 <listitem>
5118 <para>
5119 The name of the run-time parameter being reported.
5120 </para>
5121 </listitem>
5122 </varlistentry>
5124 <varlistentry>
5125 <term>String</term>
5126 <listitem>
5127 <para>
5128 The current value of the parameter.
5129 </para>
5130 </listitem>
5131 </varlistentry>
5132 </variablelist>
5133 </listitem>
5134 </varlistentry>
5136 <varlistentry id="protocol-message-formats-Parse">
5137 <term>Parse (F)</term>
5138 <listitem>
5139 <variablelist>
5140 <varlistentry>
5141 <term>Byte1('P')</term>
5142 <listitem>
5143 <para>
5144 Identifies the message as a Parse command.
5145 </para>
5146 </listitem>
5147 </varlistentry>
5149 <varlistentry>
5150 <term>Int32</term>
5151 <listitem>
5152 <para>
5153 Length of message contents in bytes, including self.
5154 </para>
5155 </listitem>
5156 </varlistentry>
5158 <varlistentry>
5159 <term>String</term>
5160 <listitem>
5161 <para>
5162 The name of the destination prepared statement
5163 (an empty string selects the unnamed prepared statement).
5164 </para>
5165 </listitem>
5166 </varlistentry>
5168 <varlistentry>
5169 <term>String</term>
5170 <listitem>
5171 <para>
5172 The query string to be parsed.
5173 </para>
5174 </listitem>
5175 </varlistentry>
5177 <varlistentry>
5178 <term>Int16</term>
5179 <listitem>
5180 <para>
5181 The number of parameter data types specified
5182 (can be zero). Note that this is not an indication of
5183 the number of parameters that might appear in the
5184 query string, only the number that the frontend wants to
5185 prespecify types for.
5186 </para>
5187 </listitem>
5188 </varlistentry>
5189 </variablelist>
5191 <para>
5192 Then, for each parameter, there is the following:
5193 </para>
5195 <variablelist>
5196 <varlistentry>
5197 <term>Int32</term>
5198 <listitem>
5199 <para>
5200 Specifies the object ID of the parameter data type.
5201 Placing a zero here is equivalent to leaving the type
5202 unspecified.
5203 </para>
5204 </listitem>
5205 </varlistentry>
5206 </variablelist>
5207 </listitem>
5208 </varlistentry>
5210 <varlistentry id="protocol-message-formats-ParseComplete">
5211 <term>ParseComplete (B)</term>
5212 <listitem>
5213 <variablelist>
5214 <varlistentry>
5215 <term>Byte1('1')</term>
5216 <listitem>
5217 <para>
5218 Identifies the message as a Parse-complete indicator.
5219 </para>
5220 </listitem>
5221 </varlistentry>
5223 <varlistentry>
5224 <term>Int32(4)</term>
5225 <listitem>
5226 <para>
5227 Length of message contents in bytes, including self.
5228 </para>
5229 </listitem>
5230 </varlistentry>
5231 </variablelist>
5232 </listitem>
5233 </varlistentry>
5235 <varlistentry id="protocol-message-formats-PasswordMessage">
5236 <term>PasswordMessage (F)</term>
5237 <listitem>
5238 <variablelist>
5239 <varlistentry>
5240 <term>Byte1('p')</term>
5241 <listitem>
5242 <para>
5243 Identifies the message as a password response. Note that
5244 this is also used for GSSAPI, SSPI and SASL response messages.
5245 The exact message type can be deduced from the context.
5246 </para>
5247 </listitem>
5248 </varlistentry>
5250 <varlistentry>
5251 <term>Int32</term>
5252 <listitem>
5253 <para>
5254 Length of message contents in bytes, including self.
5255 </para>
5256 </listitem>
5257 </varlistentry>
5259 <varlistentry>
5260 <term>String</term>
5261 <listitem>
5262 <para>
5263 The password (encrypted, if requested).
5264 </para>
5265 </listitem>
5266 </varlistentry>
5267 </variablelist>
5268 </listitem>
5269 </varlistentry>
5271 <varlistentry id="protocol-message-formats-PortalSuspended">
5272 <term>PortalSuspended (B)</term>
5273 <listitem>
5274 <variablelist>
5275 <varlistentry>
5276 <term>Byte1('s')</term>
5277 <listitem>
5278 <para>
5279 Identifies the message as a portal-suspended indicator.
5280 Note this only appears if an Execute message's row-count limit
5281 was reached.
5282 </para>
5283 </listitem>
5284 </varlistentry>
5286 <varlistentry>
5287 <term>Int32(4)</term>
5288 <listitem>
5289 <para>
5290 Length of message contents in bytes, including self.
5291 </para>
5292 </listitem>
5293 </varlistentry>
5294 </variablelist>
5295 </listitem>
5296 </varlistentry>
5298 <varlistentry id="protocol-message-formats-Query">
5299 <term>Query (F)</term>
5300 <listitem>
5301 <variablelist>
5302 <varlistentry>
5303 <term>Byte1('Q')</term>
5304 <listitem>
5305 <para>
5306 Identifies the message as a simple query.
5307 </para>
5308 </listitem>
5309 </varlistentry>
5311 <varlistentry>
5312 <term>Int32</term>
5313 <listitem>
5314 <para>
5315 Length of message contents in bytes, including self.
5316 </para>
5317 </listitem>
5318 </varlistentry>
5320 <varlistentry>
5321 <term>String</term>
5322 <listitem>
5323 <para>
5324 The query string itself.
5325 </para>
5326 </listitem>
5327 </varlistentry>
5328 </variablelist>
5329 </listitem>
5330 </varlistentry>
5332 <varlistentry id="protocol-message-formats-ReadyForQuery">
5333 <term>ReadyForQuery (B)</term>
5334 <listitem>
5335 <variablelist>
5336 <varlistentry>
5337 <term>Byte1('Z')</term>
5338 <listitem>
5339 <para>
5340 Identifies the message type. ReadyForQuery is sent
5341 whenever the backend is ready for a new query cycle.
5342 </para>
5343 </listitem>
5344 </varlistentry>
5346 <varlistentry>
5347 <term>Int32(5)</term>
5348 <listitem>
5349 <para>
5350 Length of message contents in bytes, including self.
5351 </para>
5352 </listitem>
5353 </varlistentry>
5355 <varlistentry>
5356 <term>Byte1</term>
5357 <listitem>
5358 <para>
5359 Current backend transaction status indicator.
5360 Possible values are '<literal>I</literal>' if idle (not in
5361 a transaction block); '<literal>T</literal>' if in a transaction
5362 block; or '<literal>E</literal>' if in a failed transaction
5363 block (queries will be rejected until block is ended).
5364 </para>
5365 </listitem>
5366 </varlistentry>
5367 </variablelist>
5368 </listitem>
5369 </varlistentry>
5371 <varlistentry id="protocol-message-formats-RowDescription">
5372 <term>RowDescription (B)</term>
5373 <listitem>
5374 <variablelist>
5375 <varlistentry>
5376 <term>Byte1('T')</term>
5377 <listitem>
5378 <para>
5379 Identifies the message as a row description.
5380 </para>
5381 </listitem>
5382 </varlistentry>
5384 <varlistentry>
5385 <term>Int32</term>
5386 <listitem>
5387 <para>
5388 Length of message contents in bytes, including self.
5389 </para>
5390 </listitem>
5391 </varlistentry>
5393 <varlistentry>
5394 <term>Int16</term>
5395 <listitem>
5396 <para>
5397 Specifies the number of fields in a row (can be zero).
5398 </para>
5399 </listitem>
5400 </varlistentry>
5401 </variablelist>
5403 <para>
5404 Then, for each field, there is the following:
5405 </para>
5407 <variablelist>
5408 <varlistentry>
5409 <term>String</term>
5410 <listitem>
5411 <para>
5412 The field name.
5413 </para>
5414 </listitem>
5415 </varlistentry>
5417 <varlistentry>
5418 <term>Int32</term>
5419 <listitem>
5420 <para>
5421 If the field can be identified as a column of a specific
5422 table, the object ID of the table; otherwise zero.
5423 </para>
5424 </listitem>
5425 </varlistentry>
5427 <varlistentry>
5428 <term>Int16</term>
5429 <listitem>
5430 <para>
5431 If the field can be identified as a column of a specific
5432 table, the attribute number of the column; otherwise zero.
5433 </para>
5434 </listitem>
5435 </varlistentry>
5437 <varlistentry>
5438 <term>Int32</term>
5439 <listitem>
5440 <para>
5441 The object ID of the field's data type.
5442 </para>
5443 </listitem>
5444 </varlistentry>
5446 <varlistentry>
5447 <term>Int16</term>
5448 <listitem>
5449 <para>
5450 The data type size (see <varname>pg_type.typlen</varname>).
5451 Note that negative values denote variable-width types.
5452 </para>
5453 </listitem>
5454 </varlistentry>
5456 <varlistentry>
5457 <term>Int32</term>
5458 <listitem>
5459 <para>
5460 The type modifier (see <varname>pg_attribute.atttypmod</varname>).
5461 The meaning of the modifier is type-specific.
5462 </para>
5463 </listitem>
5464 </varlistentry>
5466 <varlistentry>
5467 <term>Int16</term>
5468 <listitem>
5469 <para>
5470 The format code being used for the field. Currently will
5471 be zero (text) or one (binary). In a RowDescription
5472 returned from the statement variant of Describe, the
5473 format code is not yet known and will always be zero.
5474 </para>
5475 </listitem>
5476 </varlistentry>
5477 </variablelist>
5478 </listitem>
5479 </varlistentry>
5481 <varlistentry id="protocol-message-formats-SASLInitialResponse">
5482 <term>SASLInitialResponse (F)</term>
5483 <listitem>
5484 <variablelist>
5485 <varlistentry>
5486 <term>Byte1('p')</term>
5487 <listitem>
5488 <para>
5489 Identifies the message as an initial SASL response. Note that
5490 this is also used for GSSAPI, SSPI and password response messages.
5491 The exact message type is deduced from the context.
5492 </para>
5493 </listitem>
5494 </varlistentry>
5496 <varlistentry>
5497 <term>Int32</term>
5498 <listitem>
5499 <para>
5500 Length of message contents in bytes, including self.
5501 </para>
5502 </listitem>
5503 </varlistentry>
5505 <varlistentry>
5506 <term>String</term>
5507 <listitem>
5508 <para>
5509 Name of the SASL authentication mechanism that the client
5510 selected.
5511 </para>
5512 </listitem>
5513 </varlistentry>
5515 <varlistentry>
5516 <term>Int32</term>
5517 <listitem>
5518 <para>
5519 Length of SASL mechanism specific "Initial Client Response" that
5520 follows, or -1 if there is no Initial Response.
5521 </para>
5522 </listitem>
5523 </varlistentry>
5525 <varlistentry>
5526 <term>Byte<replaceable>n</replaceable></term>
5527 <listitem>
5528 <para>
5529 SASL mechanism specific "Initial Response".
5530 </para>
5531 </listitem>
5532 </varlistentry>
5533 </variablelist>
5534 </listitem>
5535 </varlistentry>
5537 <varlistentry id="protocol-message-formats-SASLResponse">
5538 <term>SASLResponse (F)</term>
5539 <listitem>
5540 <variablelist>
5541 <varlistentry>
5542 <term>Byte1('p')</term>
5543 <listitem>
5544 <para>
5545 Identifies the message as a SASL response. Note that
5546 this is also used for GSSAPI, SSPI and password response messages.
5547 The exact message type can be deduced from the context.
5548 </para>
5549 </listitem>
5550 </varlistentry>
5552 <varlistentry>
5553 <term>Int32</term>
5554 <listitem>
5555 <para>
5556 Length of message contents in bytes, including self.
5557 </para>
5558 </listitem>
5559 </varlistentry>
5561 <varlistentry>
5562 <term>Byte<replaceable>n</replaceable></term>
5563 <listitem>
5564 <para>
5565 SASL mechanism specific message data.
5566 </para>
5567 </listitem>
5568 </varlistentry>
5569 </variablelist>
5570 </listitem>
5571 </varlistentry>
5573 <varlistentry id="protocol-message-formats-SSLRequest">
5574 <term>SSLRequest (F)</term>
5575 <listitem>
5576 <variablelist>
5577 <varlistentry>
5578 <term>Int32(8)</term>
5579 <listitem>
5580 <para>
5581 Length of message contents in bytes, including self.
5582 </para>
5583 </listitem>
5584 </varlistentry>
5586 <varlistentry>
5587 <term>Int32(80877103)</term>
5588 <listitem>
5589 <para>
5590 The <acronym>SSL</acronym> request code. The value is chosen to contain
5591 <literal>1234</literal> in the most significant 16 bits, and <literal>5679</literal> in the
5592 least significant 16 bits. (To avoid confusion, this code
5593 must not be the same as any protocol version number.)
5594 </para>
5595 </listitem>
5596 </varlistentry>
5597 </variablelist>
5598 </listitem>
5599 </varlistentry>
5601 <varlistentry id="protocol-message-formats-StartupMessage">
5602 <term>StartupMessage (F)</term>
5603 <listitem>
5604 <variablelist>
5605 <varlistentry>
5606 <term>Int32</term>
5607 <listitem>
5608 <para>
5609 Length of message contents in bytes, including self.
5610 </para>
5611 </listitem>
5612 </varlistentry>
5614 <varlistentry>
5615 <term>Int32(196608)</term>
5616 <listitem>
5617 <para>
5618 The protocol version number. The most significant 16 bits are
5619 the major version number (3 for the protocol described here).
5620 The least significant 16 bits are the minor version number
5621 (0 for the protocol described here).
5622 </para>
5623 </listitem>
5624 </varlistentry>
5625 </variablelist>
5627 <para>
5628 The protocol version number is followed by one or more pairs of
5629 parameter name and value strings. A zero byte is required as a
5630 terminator after the last name/value pair.
5631 Parameters can appear in any
5632 order. <literal>user</literal> is required, others are optional.
5633 Each parameter is specified as:
5634 </para>
5636 <variablelist>
5637 <varlistentry>
5638 <term>String</term>
5639 <listitem>
5640 <para>
5641 The parameter name. Currently recognized names are:
5643 <variablelist>
5644 <varlistentry>
5645 <term><literal>user</literal></term>
5646 <listitem>
5647 <para>
5648 The database user name to connect as. Required;
5649 there is no default.
5650 </para>
5651 </listitem>
5652 </varlistentry>
5654 <varlistentry>
5655 <term><literal>database</literal></term>
5656 <listitem>
5657 <para>
5658 The database to connect to. Defaults to the user name.
5659 </para>
5660 </listitem>
5661 </varlistentry>
5663 <varlistentry>
5664 <term><literal>options</literal></term>
5665 <listitem>
5666 <para>
5667 Command-line arguments for the backend. (This is
5668 deprecated in favor of setting individual run-time
5669 parameters.) Spaces within this string are
5670 considered to separate arguments, unless escaped with
5671 a backslash (<literal>\</literal>); write <literal>\\</literal> to
5672 represent a literal backslash.
5673 </para>
5674 </listitem>
5675 </varlistentry>
5677 <varlistentry>
5678 <term><literal>replication</literal></term>
5679 <listitem>
5680 <para>
5681 Used to connect in streaming replication mode, where
5682 a small set of replication commands can be issued
5683 instead of SQL statements. Value can be
5684 <literal>true</literal>, <literal>false</literal>, or
5685 <literal>database</literal>, and the default is
5686 <literal>false</literal>. See
5687 <xref linkend="protocol-replication"/> for details.
5688 </para>
5689 </listitem>
5690 </varlistentry>
5691 </variablelist>
5693 In addition to the above, other parameters may be listed.
5694 Parameter names beginning with <literal>_pq_.</literal> are
5695 reserved for use as protocol extensions, while others are
5696 treated as run-time parameters to be set at backend start
5697 time. Such settings will be applied during backend start
5698 (after parsing the command-line arguments if any) and will
5699 act as session defaults.
5700 </para>
5701 </listitem>
5702 </varlistentry>
5704 <varlistentry>
5705 <term>String</term>
5706 <listitem>
5707 <para>
5708 The parameter value.
5709 </para>
5710 </listitem>
5711 </varlistentry>
5712 </variablelist>
5713 </listitem>
5714 </varlistentry>
5716 <varlistentry id="protocol-message-formats-Sync">
5717 <term>Sync (F)</term>
5718 <listitem>
5719 <variablelist>
5720 <varlistentry>
5721 <term>Byte1('S')</term>
5722 <listitem>
5723 <para>
5724 Identifies the message as a Sync command.
5725 </para>
5726 </listitem>
5727 </varlistentry>
5729 <varlistentry>
5730 <term>Int32(4)</term>
5731 <listitem>
5732 <para>
5733 Length of message contents in bytes, including self.
5734 </para>
5735 </listitem>
5736 </varlistentry>
5737 </variablelist>
5738 </listitem>
5739 </varlistentry>
5741 <varlistentry id="protocol-message-formats-Terminate">
5742 <term>Terminate (F)</term>
5743 <listitem>
5744 <variablelist>
5745 <varlistentry>
5746 <term>Byte1('X')</term>
5747 <listitem>
5748 <para>
5749 Identifies the message as a termination.
5750 </para>
5751 </listitem>
5752 </varlistentry>
5754 <varlistentry>
5755 <term>Int32(4)</term>
5756 <listitem>
5757 <para>
5758 Length of message contents in bytes, including self.
5759 </para>
5760 </listitem>
5761 </varlistentry>
5762 </variablelist>
5763 </listitem>
5764 </varlistentry>
5765 </variablelist>
5766 </sect1>
5768 <sect1 id="protocol-error-fields">
5769 <title>Error and Notice Message Fields</title>
5771 <para>
5772 This section describes the fields that can appear in ErrorResponse and
5773 NoticeResponse messages. Each field type has a single-byte identification
5774 token. Note that any given field type should appear at most once per
5775 message.
5776 </para>
5778 <variablelist>
5779 <varlistentry>
5780 <term><literal>S</literal></term>
5781 <listitem>
5782 <para>
5783 Severity: the field contents are
5784 <literal>ERROR</literal>, <literal>FATAL</literal>, or
5785 <literal>PANIC</literal> (in an error message), or
5786 <literal>WARNING</literal>, <literal>NOTICE</literal>, <literal>DEBUG</literal>,
5787 <literal>INFO</literal>, or <literal>LOG</literal> (in a notice message),
5788 or a localized translation of one of these. Always present.
5789 </para>
5790 </listitem>
5791 </varlistentry>
5793 <varlistentry>
5794 <term><literal>V</literal></term>
5795 <listitem>
5796 <para>
5797 Severity: the field contents are
5798 <literal>ERROR</literal>, <literal>FATAL</literal>, or
5799 <literal>PANIC</literal> (in an error message), or
5800 <literal>WARNING</literal>, <literal>NOTICE</literal>, <literal>DEBUG</literal>,
5801 <literal>INFO</literal>, or <literal>LOG</literal> (in a notice message).
5802 This is identical to the <literal>S</literal> field except
5803 that the contents are never localized. This is present only in
5804 messages generated by <productname>PostgreSQL</productname> versions 9.6
5805 and later.
5806 </para>
5807 </listitem>
5808 </varlistentry>
5810 <varlistentry>
5811 <term><literal>C</literal></term>
5812 <listitem>
5813 <para>
5814 Code: the SQLSTATE code for the error (see <xref
5815 linkend="errcodes-appendix"/>). Not localizable. Always present.
5816 </para>
5817 </listitem>
5818 </varlistentry>
5820 <varlistentry>
5821 <term><literal>M</literal></term>
5822 <listitem>
5823 <para>
5824 Message: the primary human-readable error message.
5825 This should be accurate but terse (typically one line).
5826 Always present.
5827 </para>
5828 </listitem>
5829 </varlistentry>
5831 <varlistentry>
5832 <term><literal>D</literal></term>
5833 <listitem>
5834 <para>
5835 Detail: an optional secondary error message carrying more
5836 detail about the problem. Might run to multiple lines.
5837 </para>
5838 </listitem>
5839 </varlistentry>
5841 <varlistentry>
5842 <term><literal>H</literal></term>
5843 <listitem>
5844 <para>
5845 Hint: an optional suggestion what to do about the problem.
5846 This is intended to differ from Detail in that it offers advice
5847 (potentially inappropriate) rather than hard facts.
5848 Might run to multiple lines.
5849 </para>
5850 </listitem>
5851 </varlistentry>
5853 <varlistentry>
5854 <term><literal>P</literal></term>
5855 <listitem>
5856 <para>
5857 Position: the field value is a decimal ASCII integer, indicating
5858 an error cursor position as an index into the original query string.
5859 The first character has index 1, and positions are measured in
5860 characters not bytes.
5861 </para>
5862 </listitem>
5863 </varlistentry>
5865 <varlistentry>
5866 <term><literal>p</literal></term>
5867 <listitem>
5868 <para>
5869 Internal position: this is defined the same as the <literal>P</literal>
5870 field, but it is used when the cursor position refers to an internally
5871 generated command rather than the one submitted by the client.
5872 The <literal>q</literal> field will always appear when this field appears.
5873 </para>
5874 </listitem>
5875 </varlistentry>
5877 <varlistentry>
5878 <term><literal>q</literal></term>
5879 <listitem>
5880 <para>
5881 Internal query: the text of a failed internally-generated command.
5882 This could be, for example, an SQL query issued by a PL/pgSQL function.
5883 </para>
5884 </listitem>
5885 </varlistentry>
5887 <varlistentry>
5888 <term><literal>W</literal></term>
5889 <listitem>
5890 <para>
5891 Where: an indication of the context in which the error occurred.
5892 Presently this includes a call stack traceback of active
5893 procedural language functions and internally-generated queries.
5894 The trace is one entry per line, most recent first.
5895 </para>
5896 </listitem>
5897 </varlistentry>
5899 <varlistentry>
5900 <term><literal>s</literal></term>
5901 <listitem>
5902 <para>
5903 Schema name: if the error was associated with a specific database
5904 object, the name of the schema containing that object, if any.
5905 </para>
5906 </listitem>
5907 </varlistentry>
5909 <varlistentry>
5910 <term><literal>t</literal></term>
5911 <listitem>
5912 <para>
5913 Table name: if the error was associated with a specific table, the
5914 name of the table. (Refer to the schema name field for the name of
5915 the table's schema.)
5916 </para>
5917 </listitem>
5918 </varlistentry>
5920 <varlistentry>
5921 <term><literal>c</literal></term>
5922 <listitem>
5923 <para>
5924 Column name: if the error was associated with a specific table column,
5925 the name of the column. (Refer to the schema and table name fields to
5926 identify the table.)
5927 </para>
5928 </listitem>
5929 </varlistentry>
5931 <varlistentry>
5932 <term><literal>d</literal></term>
5933 <listitem>
5934 <para>
5935 Data type name: if the error was associated with a specific data type,
5936 the name of the data type. (Refer to the schema name field for the
5937 name of the data type's schema.)
5938 </para>
5939 </listitem>
5940 </varlistentry>
5942 <varlistentry>
5943 <term><literal>n</literal></term>
5944 <listitem>
5945 <para>
5946 Constraint name: if the error was associated with a specific
5947 constraint, the name of the constraint. Refer to fields listed above
5948 for the associated table or domain. (For this purpose, indexes are
5949 treated as constraints, even if they weren't created with constraint
5950 syntax.)
5951 </para>
5952 </listitem>
5953 </varlistentry>
5955 <varlistentry>
5956 <term><literal>F</literal></term>
5957 <listitem>
5958 <para>
5959 File: the file name of the source-code location where the error
5960 was reported.
5961 </para>
5962 </listitem>
5963 </varlistentry>
5965 <varlistentry>
5966 <term><literal>L</literal></term>
5967 <listitem>
5968 <para>
5969 Line: the line number of the source-code location where the error
5970 was reported.
5971 </para>
5972 </listitem>
5973 </varlistentry>
5975 <varlistentry>
5976 <term><literal>R</literal></term>
5977 <listitem>
5978 <para>
5979 Routine: the name of the source-code routine reporting the error.
5980 </para>
5981 </listitem>
5982 </varlistentry>
5983 </variablelist>
5985 <note>
5986 <para>
5987 The fields for schema name, table name, column name, data type name, and
5988 constraint name are supplied only for a limited number of error types;
5989 see <xref linkend="errcodes-appendix"/>. Frontends should not assume that
5990 the presence of any of these fields guarantees the presence of another
5991 field. Core error sources observe the interrelationships noted above, but
5992 user-defined functions may use these fields in other ways. In the same
5993 vein, clients should not assume that these fields denote contemporary
5994 objects in the current database.
5995 </para>
5996 </note>
5998 <para>
5999 The client is responsible for formatting displayed information to meet its
6000 needs; in particular it should break long lines as needed. Newline characters
6001 appearing in the error message fields should be treated as paragraph breaks,
6002 not line breaks.
6003 </para>
6004 </sect1>
6006 <sect1 id="protocol-logicalrep-message-formats">
6007 <title>Logical Replication Message Formats</title>
6009 <para>
6010 This section describes the detailed format of each logical replication
6011 message. These messages are either returned by the replication slot SQL
6012 interface or are sent by a walsender. In the case of a walsender, they are
6013 encapsulated inside replication protocol WAL messages as described in
6014 <xref linkend="protocol-replication"/>, and generally obey the same message
6015 flow as physical replication.
6016 </para>
6018 <variablelist>
6019 <varlistentry id="protocol-logicalrep-message-formats-Begin">
6020 <term>Begin</term>
6021 <listitem>
6022 <variablelist>
6023 <varlistentry>
6024 <term>Byte1('B')</term>
6025 <listitem>
6026 <para>
6027 Identifies the message as a begin message.
6028 </para>
6029 </listitem>
6030 </varlistentry>
6032 <varlistentry>
6033 <term>Int64 (XLogRecPtr)</term>
6034 <listitem>
6035 <para>
6036 The final LSN of the transaction.
6037 </para>
6038 </listitem>
6039 </varlistentry>
6041 <varlistentry>
6042 <term>Int64 (TimestampTz)</term>
6043 <listitem>
6044 <para>
6045 Commit timestamp of the transaction. The value is in number
6046 of microseconds since PostgreSQL epoch (2000-01-01).
6047 </para>
6048 </listitem>
6049 </varlistentry>
6051 <varlistentry>
6052 <term>Int32 (TransactionId)</term>
6053 <listitem>
6054 <para>
6055 Xid of the transaction.
6056 </para>
6057 </listitem>
6058 </varlistentry>
6059 </variablelist>
6060 </listitem>
6061 </varlistentry>
6063 <varlistentry id="protocol-logicalrep-message-formats-Message">
6064 <term>Message</term>
6065 <listitem>
6066 <variablelist>
6067 <varlistentry>
6068 <term>Byte1('M')</term>
6069 <listitem>
6070 <para>
6071 Identifies the message as a logical decoding message.
6072 </para>
6073 </listitem>
6074 </varlistentry>
6076 <varlistentry>
6077 <term>Int32 (TransactionId)</term>
6078 <listitem>
6079 <para>
6080 Xid of the transaction (only present for streamed transactions).
6081 This field is available since protocol version 2.
6082 </para>
6083 </listitem>
6084 </varlistentry>
6086 <varlistentry>
6087 <term>Int8</term>
6088 <listitem>
6089 <para>
6090 Flags; Either 0 for no flags or 1 if the logical decoding
6091 message is transactional.
6092 </para>
6093 </listitem>
6094 </varlistentry>
6096 <varlistentry>
6097 <term>Int64 (XLogRecPtr)</term>
6098 <listitem>
6099 <para>
6100 The LSN of the logical decoding message.
6101 </para>
6102 </listitem>
6103 </varlistentry>
6105 <varlistentry>
6106 <term>String</term>
6107 <listitem>
6108 <para>
6109 The prefix of the logical decoding message.
6110 </para>
6111 </listitem>
6112 </varlistentry>
6114 <varlistentry>
6115 <term>Int32</term>
6116 <listitem>
6117 <para>
6118 Length of the content.
6119 </para>
6120 </listitem>
6121 </varlistentry>
6123 <varlistentry>
6124 <term>Byte<replaceable>n</replaceable></term>
6125 <listitem>
6126 <para>
6127 The content of the logical decoding message.
6128 </para>
6129 </listitem>
6130 </varlistentry>
6131 </variablelist>
6132 </listitem>
6133 </varlistentry>
6135 <varlistentry id="protocol-logicalrep-message-formats-Commit">
6136 <term>Commit</term>
6137 <listitem>
6138 <variablelist>
6139 <varlistentry>
6140 <term>Byte1('C')</term>
6141 <listitem>
6142 <para>
6143 Identifies the message as a commit message.
6144 </para>
6145 </listitem>
6146 </varlistentry>
6148 <varlistentry>
6149 <term>Int8(0)</term>
6150 <listitem>
6151 <para>
6152 Flags; currently unused.
6153 </para>
6154 </listitem>
6155 </varlistentry>
6157 <varlistentry>
6158 <term>Int64 (XLogRecPtr)</term>
6159 <listitem>
6160 <para>
6161 The LSN of the commit.
6162 </para>
6163 </listitem>
6164 </varlistentry>
6166 <varlistentry>
6167 <term>Int64 (XLogRecPtr)</term>
6168 <listitem>
6169 <para>
6170 The end LSN of the transaction.
6171 </para>
6172 </listitem>
6173 </varlistentry>
6175 <varlistentry>
6176 <term>Int64 (TimestampTz)</term>
6177 <listitem>
6178 <para>
6179 Commit timestamp of the transaction. The value is in number
6180 of microseconds since PostgreSQL epoch (2000-01-01).
6181 </para>
6182 </listitem>
6183 </varlistentry>
6184 </variablelist>
6185 </listitem>
6186 </varlistentry>
6188 <varlistentry id="protocol-logicalrep-message-formats-Origin">
6189 <term>Origin</term>
6190 <listitem>
6191 <variablelist>
6192 <varlistentry>
6193 <term>Byte1('O')</term>
6194 <listitem>
6195 <para>
6196 Identifies the message as an origin message.
6197 </para>
6198 </listitem>
6199 </varlistentry>
6201 <varlistentry>
6202 <term>Int64 (XLogRecPtr)</term>
6203 <listitem>
6204 <para>
6205 The LSN of the commit on the origin server.
6206 </para>
6207 </listitem>
6208 </varlistentry>
6210 <varlistentry>
6211 <term>String</term>
6212 <listitem>
6213 <para>
6214 Name of the origin.
6215 </para>
6216 </listitem>
6217 </varlistentry>
6218 </variablelist>
6220 <para>
6221 Note that there can be multiple Origin messages inside a single transaction.
6222 </para>
6223 </listitem>
6224 </varlistentry>
6226 <varlistentry id="protocol-logicalrep-message-formats-Relation">
6227 <term>Relation</term>
6228 <listitem>
6229 <variablelist>
6230 <varlistentry>
6231 <term>Byte1('R')</term>
6232 <listitem>
6233 <para>
6234 Identifies the message as a relation message.
6235 </para>
6236 </listitem>
6237 </varlistentry>
6239 <varlistentry>
6240 <term>Int32 (TransactionId)</term>
6241 <listitem>
6242 <para>
6243 Xid of the transaction (only present for streamed transactions).
6244 This field is available since protocol version 2.
6245 </para>
6246 </listitem>
6247 </varlistentry>
6249 <varlistentry>
6250 <term>Int32 (Oid)</term>
6251 <listitem>
6252 <para>
6253 OID of the relation.
6254 </para>
6255 </listitem>
6256 </varlistentry>
6258 <varlistentry>
6259 <term>String</term>
6260 <listitem>
6261 <para>
6262 Namespace (empty string for <literal>pg_catalog</literal>).
6263 </para>
6264 </listitem>
6265 </varlistentry>
6267 <varlistentry>
6268 <term>String</term>
6269 <listitem>
6270 <para>
6271 Relation name.
6272 </para>
6273 </listitem>
6274 </varlistentry>
6276 <varlistentry>
6277 <term>Int8</term>
6278 <listitem>
6279 <para>
6280 Replica identity setting for the relation (same as
6281 <structfield>relreplident</structfield> in <structname>pg_class</structname>).
6282 </para>
6283 </listitem>
6284 </varlistentry>
6286 <varlistentry>
6287 <term>Int16</term>
6288 <listitem>
6289 <para>
6290 Number of columns.
6291 </para>
6292 </listitem>
6293 </varlistentry>
6294 </variablelist>
6296 <para>
6297 Next, the following message part appears for each column included in
6298 the publication (except generated columns):
6299 </para>
6301 <variablelist>
6302 <varlistentry>
6303 <term>Int8</term>
6304 <listitem>
6305 <para>
6306 Flags for the column. Currently can be either 0 for no flags
6307 or 1 which marks the column as part of the key.
6308 </para>
6309 </listitem>
6310 </varlistentry>
6312 <varlistentry>
6313 <term>String</term>
6314 <listitem>
6315 <para>
6316 Name of the column.
6317 </para>
6318 </listitem>
6319 </varlistentry>
6321 <varlistentry>
6322 <term>Int32 (Oid)</term>
6323 <listitem>
6324 <para>
6325 OID of the column's data type.
6326 </para>
6327 </listitem>
6328 </varlistentry>
6330 <varlistentry>
6331 <term>Int32</term>
6332 <listitem>
6333 <para>
6334 Type modifier of the column (<structfield>atttypmod</structfield>).
6335 </para>
6336 </listitem>
6337 </varlistentry>
6338 </variablelist>
6339 </listitem>
6340 </varlistentry>
6342 <varlistentry id="protocol-logicalrep-message-formats-Type">
6343 <term>Type</term>
6344 <listitem>
6345 <variablelist>
6346 <varlistentry>
6347 <term>Byte1('Y')</term>
6348 <listitem>
6349 <para>
6350 Identifies the message as a type message.
6351 </para>
6352 </listitem>
6353 </varlistentry>
6355 <varlistentry>
6356 <term>Int32 (TransactionId)</term>
6357 <listitem>
6358 <para>
6359 Xid of the transaction (only present for streamed transactions).
6360 This field is available since protocol version 2.
6361 </para>
6362 </listitem>
6363 </varlistentry>
6365 <varlistentry>
6366 <term>Int32 (Oid)</term>
6367 <listitem>
6368 <para>
6369 OID of the data type.
6370 </para>
6371 </listitem>
6372 </varlistentry>
6374 <varlistentry>
6375 <term>String</term>
6376 <listitem>
6377 <para>
6378 Namespace (empty string for <literal>pg_catalog</literal>).
6379 </para>
6380 </listitem>
6381 </varlistentry>
6383 <varlistentry>
6384 <term>String</term>
6385 <listitem>
6386 <para>
6387 Name of the data type.
6388 </para>
6389 </listitem>
6390 </varlistentry>
6391 </variablelist>
6392 </listitem>
6393 </varlistentry>
6395 <varlistentry id="protocol-logicalrep-message-formats-Insert">
6396 <term>Insert</term>
6397 <listitem>
6398 <variablelist>
6399 <varlistentry>
6400 <term>Byte1('I')</term>
6401 <listitem>
6402 <para>
6403 Identifies the message as an insert message.
6404 </para>
6405 </listitem>
6406 </varlistentry>
6408 <varlistentry>
6409 <term>Int32 (TransactionId)</term>
6410 <listitem>
6411 <para>
6412 Xid of the transaction (only present for streamed transactions).
6413 This field is available since protocol version 2.
6414 </para>
6415 </listitem>
6416 </varlistentry>
6418 <varlistentry>
6419 <term>Int32 (Oid)</term>
6420 <listitem>
6421 <para>
6422 OID of the relation corresponding to the ID in the relation
6423 message.
6424 </para>
6425 </listitem>
6426 </varlistentry>
6428 <varlistentry>
6429 <term>Byte1('N')</term>
6430 <listitem>
6431 <para>
6432 Identifies the following TupleData message as a new tuple.
6433 </para>
6434 </listitem>
6435 </varlistentry>
6437 <varlistentry>
6438 <term>TupleData</term>
6439 <listitem>
6440 <para>
6441 TupleData message part representing the contents of new tuple.
6442 </para>
6443 </listitem>
6444 </varlistentry>
6445 </variablelist>
6446 </listitem>
6447 </varlistentry>
6449 <varlistentry id="protocol-logicalrep-message-formats-Update">
6450 <term>Update</term>
6451 <listitem>
6452 <variablelist>
6453 <varlistentry>
6454 <term>Byte1('U')</term>
6455 <listitem>
6456 <para>
6457 Identifies the message as an update message.
6458 </para>
6459 </listitem>
6460 </varlistentry>
6462 <varlistentry>
6463 <term>Int32 (TransactionId)</term>
6464 <listitem>
6465 <para>
6466 Xid of the transaction (only present for streamed transactions).
6467 This field is available since protocol version 2.
6468 </para>
6469 </listitem>
6470 </varlistentry>
6472 <varlistentry>
6473 <term>Int32 (Oid)</term>
6474 <listitem>
6475 <para>
6476 OID of the relation corresponding to the ID in the relation
6477 message.
6478 </para>
6479 </listitem>
6480 </varlistentry>
6482 <varlistentry>
6483 <term>Byte1('K')</term>
6484 <listitem>
6485 <para>
6486 Identifies the following TupleData submessage as a key.
6487 This field is optional and is only present if
6488 the update changed data in any of the column(s) that are
6489 part of the REPLICA IDENTITY index.
6490 </para>
6491 </listitem>
6492 </varlistentry>
6494 <varlistentry>
6495 <term>Byte1('O')</term>
6496 <listitem>
6497 <para>
6498 Identifies the following TupleData submessage as an old tuple.
6499 This field is optional and is only present if table in which
6500 the update happened has REPLICA IDENTITY set to FULL.
6501 </para>
6502 </listitem>
6503 </varlistentry>
6505 <varlistentry>
6506 <term>TupleData</term>
6507 <listitem>
6508 <para>
6509 TupleData message part representing the contents of the old tuple
6510 or primary key. Only present if the previous 'O' or 'K' part
6511 is present.
6512 </para>
6513 </listitem>
6514 </varlistentry>
6516 <varlistentry>
6517 <term>Byte1('N')</term>
6518 <listitem>
6519 <para>
6520 Identifies the following TupleData message as a new tuple.
6521 </para>
6522 </listitem>
6523 </varlistentry>
6525 <varlistentry>
6526 <term>TupleData</term>
6527 <listitem>
6528 <para>
6529 TupleData message part representing the contents of a new tuple.
6530 </para>
6531 </listitem>
6532 </varlistentry>
6533 </variablelist>
6535 <para>
6536 The Update message may contain either a 'K' message part or an 'O' message part
6537 or neither of them, but never both of them.
6538 </para>
6539 </listitem>
6540 </varlistentry>
6542 <varlistentry id="protocol-logicalrep-message-formats-Delete">
6543 <term>Delete</term>
6544 <listitem>
6545 <variablelist>
6546 <varlistentry>
6547 <term>Byte1('D')</term>
6548 <listitem>
6549 <para>
6550 Identifies the message as a delete message.
6551 </para>
6552 </listitem>
6553 </varlistentry>
6555 <varlistentry>
6556 <term>Int32 (TransactionId)</term>
6557 <listitem>
6558 <para>
6559 Xid of the transaction (only present for streamed transactions).
6560 This field is available since protocol version 2.
6561 </para>
6562 </listitem>
6563 </varlistentry>
6565 <varlistentry>
6566 <term>Int32 (Oid)</term>
6567 <listitem>
6568 <para>
6569 OID of the relation corresponding to the ID in the relation
6570 message.
6571 </para>
6572 </listitem>
6573 </varlistentry>
6575 <varlistentry>
6576 <term>Byte1('K')</term>
6577 <listitem>
6578 <para>
6579 Identifies the following TupleData submessage as a key.
6580 This field is present if the table in which the delete has
6581 happened uses an index as REPLICA IDENTITY.
6582 </para>
6583 </listitem>
6584 </varlistentry>
6586 <varlistentry>
6587 <term>Byte1('O')</term>
6588 <listitem>
6589 <para>
6590 Identifies the following TupleData message as an old tuple.
6591 This field is present if the table in which the delete
6592 happened has REPLICA IDENTITY set to FULL.
6593 </para>
6594 </listitem>
6595 </varlistentry>
6597 <varlistentry>
6598 <term>TupleData</term>
6599 <listitem>
6600 <para>
6601 TupleData message part representing the contents of the old tuple
6602 or primary key, depending on the previous field.
6603 </para>
6604 </listitem>
6605 </varlistentry>
6606 </variablelist>
6608 <para>
6609 The Delete message may contain either a 'K' message part or an 'O' message part,
6610 but never both of them.
6611 </para>
6612 </listitem>
6613 </varlistentry>
6615 <varlistentry id="protocol-logicalrep-message-formats-Truncate">
6616 <term>Truncate</term>
6617 <listitem>
6618 <variablelist>
6619 <varlistentry>
6620 <term>Byte1('T')</term>
6621 <listitem>
6622 <para>
6623 Identifies the message as a truncate message.
6624 </para>
6625 </listitem>
6626 </varlistentry>
6628 <varlistentry>
6629 <term>Int32 (TransactionId)</term>
6630 <listitem>
6631 <para>
6632 Xid of the transaction (only present for streamed transactions).
6633 This field is available since protocol version 2.
6634 </para>
6635 </listitem>
6636 </varlistentry>
6638 <varlistentry>
6639 <term>Int32</term>
6640 <listitem>
6641 <para>
6642 Number of relations
6643 </para>
6644 </listitem>
6645 </varlistentry>
6647 <varlistentry>
6648 <term>Int8</term>
6649 <listitem>
6650 <para>
6651 Option bits for <command>TRUNCATE</command>:
6652 1 for <literal>CASCADE</literal>, 2 for <literal>RESTART IDENTITY</literal>
6653 </para>
6654 </listitem>
6655 </varlistentry>
6657 <varlistentry>
6658 <term>Int32 (Oid)</term>
6659 <listitem>
6660 <para>
6661 OID of the relation corresponding to the ID in the relation
6662 message. This field is repeated for each relation.
6663 </para>
6664 </listitem>
6665 </varlistentry>
6666 </variablelist>
6667 </listitem>
6668 </varlistentry>
6669 </variablelist>
6671 <para>
6672 The following messages (Stream Start, Stream Stop, Stream Commit, and
6673 Stream Abort) are available since protocol version 2.
6674 </para>
6676 <variablelist>
6677 <varlistentry id="protocol-logicalrep-message-formats-Stream-Start">
6678 <term>Stream Start</term>
6679 <listitem>
6680 <variablelist>
6681 <varlistentry>
6682 <term>Byte1('S')</term>
6683 <listitem>
6684 <para>
6685 Identifies the message as a stream start message.
6686 </para>
6687 </listitem>
6688 </varlistentry>
6690 <varlistentry>
6691 <term>Int32 (TransactionId)</term>
6692 <listitem>
6693 <para>
6694 Xid of the transaction.
6695 </para>
6696 </listitem>
6697 </varlistentry>
6699 <varlistentry>
6700 <term>Int8</term>
6701 <listitem>
6702 <para>
6703 A value of 1 indicates this is the first stream segment for
6704 this XID, 0 for any other stream segment.
6705 </para>
6706 </listitem>
6707 </varlistentry>
6708 </variablelist>
6709 </listitem>
6710 </varlistentry>
6712 <varlistentry id="protocol-logicalrep-message-formats-Stream-Stop">
6713 <term>Stream Stop</term>
6714 <listitem>
6715 <variablelist>
6716 <varlistentry>
6717 <term>Byte1('E')</term>
6718 <listitem>
6719 <para>
6720 Identifies the message as a stream stop message.
6721 </para>
6722 </listitem>
6723 </varlistentry>
6724 </variablelist>
6725 </listitem>
6726 </varlistentry>
6728 <varlistentry id="protocol-logicalrep-message-formats-Stream-Commit">
6729 <term>Stream Commit</term>
6730 <listitem>
6731 <variablelist>
6732 <varlistentry>
6733 <term>Byte1('c')</term>
6734 <listitem>
6735 <para>
6736 Identifies the message as a stream commit message.
6737 </para>
6738 </listitem>
6739 </varlistentry>
6741 <varlistentry>
6742 <term>Int32 (TransactionId)</term>
6743 <listitem>
6744 <para>
6745 Xid of the transaction.
6746 </para>
6747 </listitem>
6748 </varlistentry>
6750 <varlistentry>
6751 <term>Int8(0)</term>
6752 <listitem>
6753 <para>
6754 Flags; currently unused.
6755 </para>
6756 </listitem>
6757 </varlistentry>
6759 <varlistentry>
6760 <term>Int64 (XLogRecPtr)</term>
6761 <listitem>
6762 <para>
6763 The LSN of the commit.
6764 </para>
6765 </listitem>
6766 </varlistentry>
6768 <varlistentry>
6769 <term>Int64 (XLogRecPtr)</term>
6770 <listitem>
6771 <para>
6772 The end LSN of the transaction.
6773 </para>
6774 </listitem>
6775 </varlistentry>
6777 <varlistentry>
6778 <term>Int64 (TimestampTz)</term>
6779 <listitem>
6780 <para>
6781 Commit timestamp of the transaction. The value is in number
6782 of microseconds since PostgreSQL epoch (2000-01-01).
6783 </para>
6784 </listitem>
6785 </varlistentry>
6786 </variablelist>
6787 </listitem>
6788 </varlistentry>
6790 <varlistentry id="protocol-logicalrep-message-formats-Stream-Abort">
6791 <term>Stream Abort</term>
6792 <listitem>
6793 <variablelist>
6794 <varlistentry>
6795 <term>Byte1('A')</term>
6796 <listitem>
6797 <para>
6798 Identifies the message as a stream abort message.
6799 </para>
6800 </listitem>
6801 </varlistentry>
6803 <varlistentry>
6804 <term>Int32 (TransactionId)</term>
6805 <listitem>
6806 <para>
6807 Xid of the transaction.
6808 </para>
6809 </listitem>
6810 </varlistentry>
6812 <varlistentry>
6813 <term>Int32 (TransactionId)</term>
6814 <listitem>
6815 <para>
6816 Xid of the subtransaction (will be same as xid of the transaction for top-level
6817 transactions).
6818 </para>
6819 </listitem>
6820 </varlistentry>
6821 </variablelist>
6822 </listitem>
6823 </varlistentry>
6824 </variablelist>
6826 <para>
6827 The following messages (Begin Prepare, Prepare, Commit Prepared, Rollback Prepared, Stream Prepare)
6828 are available since protocol version 3.
6829 </para>
6831 <variablelist>
6832 <varlistentry id="protocol-logicalrep-message-formats-Begin-Prepare">
6833 <term>Begin Prepare</term>
6834 <listitem>
6835 <variablelist>
6836 <varlistentry>
6837 <term>Byte1('b')</term>
6838 <listitem>
6839 <para>
6840 Identifies the message as the beginning of a two-phase transaction message.
6841 </para>
6842 </listitem>
6843 </varlistentry>
6845 <varlistentry>
6846 <term>Int64 (XLogRecPtr)</term>
6847 <listitem>
6848 <para>
6849 The LSN of the prepare.
6850 </para>
6851 </listitem>
6852 </varlistentry>
6854 <varlistentry>
6855 <term>Int64 (XLogRecPtr)</term>
6856 <listitem>
6857 <para>
6858 The end LSN of the prepared transaction.
6859 </para>
6860 </listitem>
6861 </varlistentry>
6863 <varlistentry>
6864 <term>Int64 (TimestampTz)</term>
6865 <listitem>
6866 <para>
6867 Prepare timestamp of the transaction. The value is in number
6868 of microseconds since PostgreSQL epoch (2000-01-01).
6869 </para>
6870 </listitem>
6871 </varlistentry>
6873 <varlistentry>
6874 <term>Int32 (TransactionId)</term>
6875 <listitem>
6876 <para>
6877 Xid of the transaction.
6878 </para>
6879 </listitem>
6880 </varlistentry>
6882 <varlistentry>
6883 <term>String</term>
6884 <listitem>
6885 <para>
6886 The user defined GID of the two-phase transaction.
6887 </para>
6888 </listitem>
6889 </varlistentry>
6890 </variablelist>
6891 </listitem>
6892 </varlistentry>
6894 <varlistentry id="protocol-logicalrep-message-formats-Prepare">
6895 <term>Prepare</term>
6896 <listitem>
6897 <variablelist>
6898 <varlistentry>
6899 <term>Byte1('P')</term>
6900 <listitem>
6901 <para>
6902 Identifies the message as a two-phase prepared transaction message.
6903 </para>
6904 </listitem>
6905 </varlistentry>
6907 <varlistentry>
6908 <term>Int8(0)</term>
6909 <listitem>
6910 <para>
6911 Flags; currently unused.
6912 </para>
6913 </listitem>
6914 </varlistentry>
6916 <varlistentry>
6917 <term>Int64 (XLogRecPtr)</term>
6918 <listitem>
6919 <para>
6920 The LSN of the prepare.
6921 </para>
6922 </listitem>
6923 </varlistentry>
6925 <varlistentry>
6926 <term>Int64 (XLogRecPtr)</term>
6927 <listitem>
6928 <para>
6929 The end LSN of the prepared transaction.
6930 </para>
6931 </listitem>
6932 </varlistentry>
6934 <varlistentry>
6935 <term>Int64 (TimestampTz)</term>
6936 <listitem>
6937 <para>
6938 Prepare timestamp of the transaction. The value is in number
6939 of microseconds since PostgreSQL epoch (2000-01-01).
6940 </para>
6941 </listitem>
6942 </varlistentry>
6944 <varlistentry>
6945 <term>Int32 (TransactionId)</term>
6946 <listitem>
6947 <para>
6948 Xid of the transaction.
6949 </para>
6950 </listitem>
6951 </varlistentry>
6953 <varlistentry>
6954 <term>String</term>
6955 <listitem>
6956 <para>
6957 The user defined GID of the two-phase transaction.
6958 </para>
6959 </listitem>
6960 </varlistentry>
6961 </variablelist>
6962 </listitem>
6963 </varlistentry>
6965 <varlistentry id="protocol-logicalrep-message-formats-Commit-Prepared">
6966 <term>Commit Prepared</term>
6967 <listitem>
6968 <variablelist>
6969 <varlistentry>
6970 <term>Byte1('K')</term>
6971 <listitem>
6972 <para>
6973 Identifies the message as the commit of a two-phase transaction message.
6974 </para>
6975 </listitem>
6976 </varlistentry>
6978 <varlistentry>
6979 <term>Int8(0)</term>
6980 <listitem>
6981 <para>
6982 Flags; currently unused.
6983 </para>
6984 </listitem>
6985 </varlistentry>
6987 <varlistentry>
6988 <term>Int64 (XLogRecPtr)</term>
6989 <listitem>
6990 <para>
6991 The LSN of the commit prepared.
6992 </para>
6993 </listitem>
6994 </varlistentry>
6996 <varlistentry>
6997 <term>Int64 (XLogRecPtr)</term>
6998 <listitem>
6999 <para>
7000 The end LSN of the commit prepared transaction.
7001 </para>
7002 </listitem>
7003 </varlistentry>
7005 <varlistentry>
7006 <term>Int64 (TimestampTz)</term>
7007 <listitem>
7008 <para>
7009 Commit timestamp of the transaction. The value is in number
7010 of microseconds since PostgreSQL epoch (2000-01-01).
7011 </para>
7012 </listitem>
7013 </varlistentry>
7015 <varlistentry>
7016 <term>Int32 (TransactionId)</term>
7017 <listitem>
7018 <para>
7019 Xid of the transaction.
7020 </para>
7021 </listitem>
7022 </varlistentry>
7024 <varlistentry>
7025 <term>String</term>
7026 <listitem>
7027 <para>
7028 The user defined GID of the two-phase transaction.
7029 </para>
7030 </listitem>
7031 </varlistentry>
7032 </variablelist>
7033 </listitem>
7034 </varlistentry>
7036 <varlistentry id="protocol-logicalrep-message-formats-Rollback-Prepared">
7037 <term>Rollback Prepared</term>
7038 <listitem>
7039 <variablelist>
7040 <varlistentry>
7041 <term>Byte1('r')</term>
7042 <listitem>
7043 <para>
7044 Identifies the message as the rollback of a two-phase transaction message.
7045 </para>
7046 </listitem>
7047 </varlistentry>
7049 <varlistentry>
7050 <term>Int8(0)</term>
7051 <listitem>
7052 <para>
7053 Flags; currently unused.
7054 </para>
7055 </listitem>
7056 </varlistentry>
7058 <varlistentry>
7059 <term>Int64 (XLogRecPtr)</term>
7060 <listitem>
7061 <para>
7062 The end LSN of the prepared transaction.
7063 </para>
7064 </listitem>
7065 </varlistentry>
7067 <varlistentry>
7068 <term>Int64 (XLogRecPtr)</term>
7069 <listitem>
7070 <para>
7071 The end LSN of the rollback prepared transaction.
7072 </para>
7073 </listitem>
7074 </varlistentry>
7076 <varlistentry>
7077 <term>Int64 (TimestampTz)</term>
7078 <listitem>
7079 <para>
7080 Prepare timestamp of the transaction. The value is in number
7081 of microseconds since PostgreSQL epoch (2000-01-01).
7082 </para>
7083 </listitem>
7084 </varlistentry>
7086 <varlistentry>
7087 <term>Int64 (TimestampTz)</term>
7088 <listitem>
7089 <para>
7090 Rollback timestamp of the transaction. The value is in number
7091 of microseconds since PostgreSQL epoch (2000-01-01).
7092 </para>
7093 </listitem>
7094 </varlistentry>
7096 <varlistentry>
7097 <term>Int32 (TransactionId)</term>
7098 <listitem>
7099 <para>
7100 Xid of the transaction.
7101 </para>
7102 </listitem>
7103 </varlistentry>
7105 <varlistentry>
7106 <term>String</term>
7107 <listitem>
7108 <para>
7109 The user defined GID of the two-phase transaction.
7110 </para>
7111 </listitem>
7112 </varlistentry>
7113 </variablelist>
7114 </listitem>
7115 </varlistentry>
7117 <varlistentry id="protocol-logicalrep-message-formats-Stream-Prepare">
7118 <term>Stream Prepare</term>
7119 <listitem>
7120 <variablelist>
7121 <varlistentry>
7122 <term>Byte1('p')</term>
7123 <listitem>
7124 <para>
7125 Identifies the message as a two-phase stream prepare message.
7126 </para>
7127 </listitem>
7128 </varlistentry>
7130 <varlistentry>
7131 <term>Int8(0)</term>
7132 <listitem>
7133 <para>
7134 Flags; currently unused.
7135 </para>
7136 </listitem>
7137 </varlistentry>
7139 <varlistentry>
7140 <term>Int64 (XLogRecPtr)</term>
7141 <listitem>
7142 <para>
7143 The LSN of the prepare.
7144 </para>
7145 </listitem>
7146 </varlistentry>
7148 <varlistentry>
7149 <term>Int64 (XLogRecPtr)</term>
7150 <listitem>
7151 <para>
7152 The end LSN of the prepare transaction.
7153 </para>
7154 </listitem>
7155 </varlistentry>
7157 <varlistentry>
7158 <term>Int64 (TimestampTz)</term>
7159 <listitem>
7160 <para>
7161 Prepare timestamp of the transaction. The value is in number
7162 of microseconds since PostgreSQL epoch (2000-01-01).
7163 </para>
7164 </listitem>
7165 </varlistentry>
7167 <varlistentry>
7168 <term>Int32 (TransactionId)</term>
7169 <listitem>
7170 <para>
7171 Xid of the transaction.
7172 </para>
7173 </listitem>
7174 </varlistentry>
7176 <varlistentry>
7177 <term>String</term>
7178 <listitem>
7179 <para>
7180 The user defined GID of the two-phase transaction.
7181 </para>
7182 </listitem>
7183 </varlistentry>
7184 </variablelist>
7185 </listitem>
7186 </varlistentry>
7187 </variablelist>
7189 <para>
7190 The following message parts are shared by the above messages.
7191 </para>
7193 <variablelist>
7194 <varlistentry id="protocol-logicalrep-message-formats-TupleData">
7195 <term>TupleData</term>
7196 <listitem>
7197 <variablelist>
7198 <varlistentry>
7199 <term>Int16</term>
7200 <listitem>
7201 <para>
7202 Number of columns.
7203 </para>
7204 </listitem>
7205 </varlistentry>
7206 </variablelist>
7208 <para>
7209 Next, one of the following submessages appears for each column (except generated columns):
7211 <variablelist>
7212 <varlistentry>
7213 <term>Byte1('n')</term>
7214 <listitem>
7215 <para>
7216 Identifies the data as NULL value.
7217 </para>
7218 </listitem>
7219 </varlistentry>
7220 </variablelist>
7222 <variablelist>
7223 <varlistentry>
7224 <term>Byte1('u')</term>
7225 <listitem>
7226 <para>
7227 Identifies unchanged TOASTed value (the actual value is not
7228 sent).
7229 </para>
7230 </listitem>
7231 </varlistentry>
7232 </variablelist>
7234 <variablelist>
7235 <varlistentry>
7236 <term>Byte1('t')</term>
7237 <listitem>
7238 <para>
7239 Identifies the data as text formatted value.
7240 </para>
7241 </listitem>
7242 </varlistentry>
7243 </variablelist>
7245 <variablelist>
7246 <varlistentry>
7247 <term>Byte1('b')</term>
7248 <listitem>
7249 <para>
7250 Identifies the data as binary formatted value.
7251 </para>
7252 </listitem>
7253 </varlistentry>
7255 <varlistentry>
7256 <term>Int32</term>
7257 <listitem>
7258 <para>
7259 Length of the column value.
7260 </para>
7261 </listitem>
7262 </varlistentry>
7264 <varlistentry>
7265 <term>Byte<replaceable>n</replaceable></term>
7266 <listitem>
7267 <para>
7268 The value of the column, either in binary or in text format.
7269 (As specified in the preceding format byte).
7270 <replaceable>n</replaceable> is the above length.
7271 </para>
7272 </listitem>
7273 </varlistentry>
7274 </variablelist>
7275 </para>
7276 </listitem>
7277 </varlistentry>
7278 </variablelist>
7279 </sect1>
7281 <sect1 id="protocol-changes">
7282 <title>Summary of Changes since Protocol 2.0</title>
7284 <para>
7285 This section provides a quick checklist of changes, for the benefit of
7286 developers trying to update existing client libraries to protocol 3.0.
7287 </para>
7289 <para>
7290 The initial startup packet uses a flexible list-of-strings format
7291 instead of a fixed format. Notice that session default values for run-time
7292 parameters can now be specified directly in the startup packet. (Actually,
7293 you could do that before using the <literal>options</literal> field, but given the
7294 limited width of <literal>options</literal> and the lack of any way to quote
7295 whitespace in the values, it wasn't a very safe technique.)
7296 </para>
7298 <para>
7299 All messages now have a length count immediately following the message type
7300 byte (except for startup packets, which have no type byte). Also note that
7301 PasswordMessage now has a type byte.
7302 </para>
7304 <para>
7305 ErrorResponse and NoticeResponse ('<literal>E</literal>' and '<literal>N</literal>')
7306 messages now contain multiple fields, from which the client code can
7307 assemble an error message of the desired level of verbosity. Note that
7308 individual fields will typically not end with a newline, whereas the single
7309 string sent in the older protocol always did.
7310 </para>
7312 <para>
7313 The ReadyForQuery ('<literal>Z</literal>') message includes a transaction status
7314 indicator.
7315 </para>
7317 <para>
7318 The distinction between BinaryRow and DataRow message types is gone; the
7319 single DataRow message type serves for returning data in all formats.
7320 Note that the layout of DataRow has changed to make it easier to parse.
7321 Also, the representation of binary values has changed: it is no longer
7322 directly tied to the server's internal representation.
7323 </para>
7325 <para>
7326 There is a new <quote>extended query</quote> sub-protocol, which adds the frontend
7327 message types Parse, Bind, Execute, Describe, Close, Flush, and Sync, and the
7328 backend message types ParseComplete, BindComplete, PortalSuspended,
7329 ParameterDescription, NoData, and CloseComplete. Existing clients do not
7330 have to concern themselves with this sub-protocol, but making use of it
7331 might allow improvements in performance or functionality.
7332 </para>
7334 <para>
7335 <command>COPY</command> data is now encapsulated into CopyData and CopyDone messages. There
7336 is a well-defined way to recover from errors during <command>COPY</command>. The special
7337 <quote><literal>\.</literal></quote> last line is not needed anymore, and is not sent
7338 during <command>COPY OUT</command>.
7339 (It is still recognized as a terminator during <command>COPY IN</command>, but its use is
7340 deprecated and will eventually be removed.) Binary <command>COPY</command> is supported.
7341 The CopyInResponse and CopyOutResponse messages include fields indicating
7342 the number of columns and the format of each column.
7343 </para>
7345 <para>
7346 The layout of FunctionCall and FunctionCallResponse messages has changed.
7347 FunctionCall can now support passing NULL arguments to functions. It also
7348 can handle passing parameters and retrieving results in either text or
7349 binary format. There is no longer any reason to consider FunctionCall a
7350 potential security hole, since it does not offer direct access to internal
7351 server data representations.
7352 </para>
7354 <para>
7355 The backend sends ParameterStatus ('<literal>S</literal>') messages during connection
7356 startup for all parameters it considers interesting to the client library.
7357 Subsequently, a ParameterStatus message is sent whenever the active value
7358 changes for any of these parameters.
7359 </para>
7361 <para>
7362 The RowDescription ('<literal>T</literal>') message carries new table OID and column
7363 number fields for each column of the described row. It also shows the format
7364 code for each column.
7365 </para>
7367 <para>
7368 The CursorResponse ('<literal>P</literal>') message is no longer generated by
7369 the backend.
7370 </para>
7372 <para>
7373 The NotificationResponse ('<literal>A</literal>') message has an additional string
7374 field, which can carry a <quote>payload</quote> string passed
7375 from the <command>NOTIFY</command> event sender.
7376 </para>
7378 <para>
7379 The EmptyQueryResponse ('<literal>I</literal>') message used to include an empty
7380 string parameter; this has been removed.
7381 </para>
7382 </sect1>
7383 </chapter>