]> granicus.if.org Git - postgresql/blob - doc/src/sgml/protocol.sgml
Improvements to the replication protocol documentation.
[postgresql] / doc / src / sgml / protocol.sgml
1 <!-- doc/src/sgml/protocol.sgml -->
2
3 <chapter id="protocol">
4  <title>Frontend/Backend Protocol</title>
5
6  <indexterm zone="protocol">
7   <primary>protocol</primary>
8   <secondary>frontend-backend</secondary>
9  </indexterm>
10
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>
19
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
26   startup-request message tells the server which protocol version the
27   client is attempting to use, and then the server follows that protocol
28   if it is able.
29  </para>
30
31   <para>
32    In order to serve multiple clients efficiently, the server launches
33    a new <quote>backend</> process for each client.
34    In the current implementation, a new child
35    process is created immediately after an incoming connection is detected.
36    This is transparent to the protocol, however.  For purposes of the
37    protocol, the terms <quote>backend</> and <quote>server</> are
38    interchangeable; likewise <quote>frontend</> and <quote>client</>
39    are interchangeable.
40   </para>
41
42  <sect1 id="protocol-overview">
43   <title>Overview</title>
44
45   <para>
46    The protocol has separate phases for startup and normal operation.
47    In the startup phase, the frontend opens a connection to the server
48    and authenticates itself to the satisfaction of the server.  (This might
49    involve a single message, or multiple messages depending on the
50    authentication method being used.)  If all goes well, the server then sends
51    status information to the frontend, and finally enters normal operation.
52    Except for the initial startup-request message, this part of the
53    protocol is driven by the server.
54   </para>
55
56   <para>
57    During normal operation, the frontend sends queries and
58    other commands to the backend, and the backend sends back query results
59    and other responses.  There are a few cases (such as <command>NOTIFY</>)
60    wherein the
61    backend will send unsolicited messages, but for the most part this portion
62    of a session is driven by frontend requests.
63   </para>
64
65   <para>
66    Termination of the session is normally by frontend choice, but can be
67    forced by the backend in certain cases.  In any case, when the backend
68    closes the connection, it will roll back any open (incomplete) transaction
69    before exiting.
70   </para>
71
72   <para>
73    Within normal operation, SQL commands can be executed through either of
74    two sub-protocols.  In the <quote>simple query</> protocol, the frontend
75    just sends a textual query string, which is parsed and immediately
76    executed by the backend.  In the <quote>extended query</> protocol,
77    processing of queries is separated into multiple steps: parsing,
78    binding of parameter values, and execution.  This offers flexibility
79    and performance benefits, at the cost of extra complexity.
80   </para>
81
82   <para>
83    Normal operation has additional sub-protocols for special operations
84    such as <command>COPY</>.
85   </para>
86
87  <sect2 id="protocol-message-concepts">
88   <title>Messaging Overview</title>
89
90   <para>
91    All communication is through a stream of messages.  The first byte of a
92    message identifies the message type, and the next four bytes specify the
93    length of the rest of the message (this length count includes itself, but
94    not the message-type byte).  The remaining contents of the message are
95    determined by the message type.  For historical reasons, the very first
96    message sent by the client (the startup message) has no initial
97    message-type byte.
98   </para>
99
100   <para>
101    To avoid losing synchronization with the message stream, both servers and
102    clients typically read an entire message into a buffer (using the byte
103    count) before attempting to process its contents.  This allows easy
104    recovery if an error is detected while processing the contents.  In
105    extreme situations (such as not having enough memory to buffer the
106    message), the receiver can use the byte count to determine how much
107    input to skip before it resumes reading messages.
108   </para>
109
110   <para>
111    Conversely, both servers and clients must take care never to send an
112    incomplete message.  This is commonly done by marshaling the entire message
113    in a buffer before beginning to send it.  If a communications failure
114    occurs partway through sending or receiving a message, the only sensible
115    response is to abandon the connection, since there is little hope of
116    recovering message-boundary synchronization.
117   </para>
118  </sect2>
119
120   <sect2 id="protocol-query-concepts">
121    <title>Extended Query Overview</title>
122
123    <para>
124     In the extended-query protocol, execution of SQL commands is divided
125     into multiple steps.  The state retained between steps is represented
126     by two types of objects: <firstterm>prepared statements</> and
127     <firstterm>portals</>.  A prepared statement represents the result of
128     parsing and semantic analysis of a textual query string.
129     A prepared statement is not in itself ready to execute, because it might
130     lack specific values for <firstterm>parameters</>.  A portal represents
131     a ready-to-execute or already-partially-executed statement, with any
132     missing parameter values filled in.  (For <command>SELECT</> statements,
133     a portal is equivalent to an open cursor, but we choose to use a different
134     term since cursors don't handle non-<command>SELECT</> statements.)
135    </para>
136
137    <para>
138     The overall execution cycle consists of a <firstterm>parse</> step,
139     which creates a prepared statement from a textual query string; a
140     <firstterm>bind</> step, which creates a portal given a prepared
141     statement and values for any needed parameters; and an
142     <firstterm>execute</> step that runs a portal's query.  In the case of
143     a query that returns rows (<command>SELECT</>, <command>SHOW</>, etc),
144     the execute step can be told to fetch only
145     a limited number of rows, so that multiple execute steps might be needed
146     to complete the operation.
147    </para>
148
149    <para>
150     The backend can keep track of multiple prepared statements and portals
151     (but note that these exist only within a session, and are never shared
152     across sessions).  Existing prepared statements and portals are
153     referenced by names assigned when they were created.  In addition,
154     an <quote>unnamed</> prepared statement and portal exist.  Although these
155     behave largely the same as named objects, operations on them are optimized
156     for the case of executing a query only once and then discarding it,
157     whereas operations on named objects are optimized on the expectation
158     of multiple uses.
159    </para>
160   </sect2>
161
162   <sect2 id="protocol-format-codes">
163    <title>Formats and Format Codes</title>
164
165    <para>
166     Data of a particular data type might be transmitted in any of several
167     different <firstterm>formats</>.  As of <productname>PostgreSQL</> 7.4
168     the only supported formats are <quote>text</> and <quote>binary</>,
169     but the protocol makes provision for future extensions.  The desired
170     format for any value is specified by a <firstterm>format code</>.
171     Clients can specify a format code for each transmitted parameter value
172     and for each column of a query result.  Text has format code zero,
173     binary has format code one, and all other format codes are reserved
174     for future definition.
175    </para>
176
177    <para>
178     The text representation of values is whatever strings are produced
179     and accepted by the input/output conversion functions for the
180     particular data type.  In the transmitted representation, there is
181     no trailing null character; the frontend must add one to received
182     values if it wants to process them as C strings.
183     (The text format does not allow embedded nulls, by the way.)
184    </para>
185
186    <para>
187     Binary representations for integers use network byte order (most
188     significant byte first).  For other data types consult the documentation
189     or source code to learn about the binary representation.  Keep in mind
190     that binary representations for complex data types might change across
191     server versions; the text format is usually the more portable choice.
192    </para>
193   </sect2>
194  </sect1>
195
196  <sect1 id="protocol-flow">
197   <title>Message Flow</title>
198
199   <para>
200    This section describes the message flow and the semantics of each
201    message type.  (Details of the exact representation of each message
202    appear in <xref linkend="protocol-message-formats">.)  There are
203    several different sub-protocols depending on the state of the
204    connection: start-up, query, function call,
205    <command>COPY</command>, and termination.  There are also special
206    provisions for asynchronous operations (including notification
207    responses and command cancellation), which can occur at any time
208    after the start-up phase.
209   </para>
210
211   <sect2>
212    <title>Start-up</title>
213
214    <para>
215     To begin a session, a frontend opens a connection to the server and sends
216     a startup message.  This message includes the names of the user and of the
217     database the user wants to connect to; it also identifies the particular
218     protocol version to be used.  (Optionally, the startup message can include
219     additional settings for run-time parameters.)
220     The server then uses this information and
221     the contents of its configuration files (such as
222     <filename>pg_hba.conf</filename>) to determine
223     whether the connection is provisionally acceptable, and what additional
224     authentication is required (if any).
225    </para>
226
227    <para>
228     The server then sends an appropriate authentication request message,
229     to which the frontend must reply with an appropriate authentication
230     response message (such as a password).
231     For all authentication methods except GSSAPI and SSPI, there is at most
232     one request and one response. In some methods, no response
233     at all is needed from the frontend, and so no authentication request
234     occurs. For GSSAPI and SSPI, multiple exchanges of packets may be needed
235     to complete the authentication.
236    </para>
237
238    <para>
239     The authentication cycle ends with the server either rejecting the
240     connection attempt (ErrorResponse), or sending AuthenticationOk.
241    </para>
242
243    <para>
244     The possible messages from the server in this phase are:
245
246     <variablelist>
247      <varlistentry>
248       <term>ErrorResponse</term>
249       <listitem>
250        <para>
251         The connection attempt has been rejected.
252         The server then immediately closes the connection.
253        </para>
254       </listitem>
255      </varlistentry>
256
257      <varlistentry>
258       <term>AuthenticationOk</term>
259       <listitem>
260        <para>
261         The authentication exchange is successfully completed.
262        </para>
263       </listitem>
264      </varlistentry>
265
266      <varlistentry>
267       <term>AuthenticationKerberosV5</term>
268       <listitem>
269        <para>
270         The frontend must now take part in a Kerberos V5
271         authentication dialog (not described here, part of the
272         Kerberos specification) with the server.  If this is
273         successful, the server responds with an AuthenticationOk,
274         otherwise it responds with an ErrorResponse. This is no
275         longer supported. This is not supported any more.
276        </para>
277       </listitem>
278      </varlistentry>
279
280      <varlistentry>
281       <term>AuthenticationCleartextPassword</term>
282       <listitem>
283        <para>
284         The frontend must now send a PasswordMessage containing the
285         password in clear-text form.  If
286         this is the correct password, the server responds with an
287         AuthenticationOk, otherwise it responds with an ErrorResponse.
288        </para>
289       </listitem>
290      </varlistentry>
291
292      <varlistentry>
293       <term>AuthenticationMD5Password</term>
294       <listitem>
295        <para>
296         The frontend must now send a PasswordMessage containing the
297         password (with username) encrypted via MD5, then encrypted
298         again using the 4-byte random salt specified in the
299         AuthenticationMD5Password message.  If this is the correct
300         password, the server responds with an AuthenticationOk,
301         otherwise it responds with an ErrorResponse.  The actual
302         PasswordMessage can be computed in SQL as <literal>concat('md5',
303         md5(concat(md5(concat(password, username)), random-salt)))</>.
304         (Keep in mind the <function>md5()</> function returns its
305         result as a hex string.)
306        </para>
307       </listitem>
308      </varlistentry>
309
310      <varlistentry>
311       <term>AuthenticationSCMCredential</term>
312       <listitem>
313        <para>
314         This response is only possible for local Unix-domain connections
315         on platforms that support SCM credential messages.  The frontend
316         must issue an SCM credential message and then send a single data
317         byte.  (The contents of the data byte are uninteresting; it's
318         only used to ensure that the server waits long enough to receive
319         the credential message.)  If the credential is acceptable,
320         the server responds with an
321         AuthenticationOk, otherwise it responds with an ErrorResponse.
322         (This message type is only issued by pre-9.1 servers.  It may
323         eventually be removed from the protocol specification.)
324        </para>
325       </listitem>
326      </varlistentry>
327
328      <varlistentry>
329       <term>AuthenticationGSS</term>
330       <listitem>
331        <para>
332         The frontend must now initiate a GSSAPI negotiation. The frontend
333         will send a PasswordMessage with the first part of the GSSAPI
334         data stream in response to this. If further messages are needed,
335         the server will respond with AuthenticationGSSContinue.
336        </para>
337       </listitem>
338      </varlistentry>
339
340      <varlistentry>
341       <term>AuthenticationSSPI</term>
342       <listitem>
343        <para>
344         The frontend must now initiate a SSPI negotiation. The frontend
345         will send a PasswordMessage with the first part of the SSPI
346         data stream in response to this. If further messages are needed,
347         the server will respond with AuthenticationGSSContinue.
348        </para>
349       </listitem>
350
351      </varlistentry>
352      <varlistentry>
353       <term>AuthenticationGSSContinue</term>
354       <listitem>
355        <para>
356         This message contains the response data from the previous step
357         of GSSAPI or SSPI negotiation (AuthenticationGSS, AuthenticationSSPI
358         or a previous AuthenticationGSSContinue). If the GSSAPI
359         or SSPI data in this message
360         indicates more data is needed to complete the authentication,
361         the frontend must send that data as another PasswordMessage. If
362         GSSAPI or SSPI authentication is completed by this message, the server
363         will next send AuthenticationOk to indicate successful authentication
364         or ErrorResponse to indicate failure.
365        </para>
366       </listitem>
367      </varlistentry>
368
369     </variablelist>
370    </para>
371
372    <para>
373     If the frontend does not support the authentication method
374     requested by the server, then it should immediately close the
375     connection.
376    </para>
377
378    <para>
379     After having received AuthenticationOk, the frontend must wait
380     for further messages from the server.  In this phase a backend process
381     is being started, and the frontend is just an interested bystander.
382     It is still possible for the startup attempt
383     to fail (ErrorResponse), but in the normal case the backend will send
384     some ParameterStatus messages, BackendKeyData, and finally ReadyForQuery.
385    </para>
386
387    <para>
388     During this phase the backend will attempt to apply any additional
389     run-time parameter settings that were given in the startup message.
390     If successful, these values become session defaults.  An error causes
391     ErrorResponse and exit.
392    </para>
393
394    <para>
395     The possible messages from the backend in this phase are:
396
397     <variablelist>
398      <varlistentry>
399       <term>BackendKeyData</term>
400       <listitem>
401        <para>
402         This message provides secret-key data that the frontend must
403         save if it wants to be able to issue cancel requests later.
404         The frontend should not respond to this message, but should
405         continue listening for a ReadyForQuery message.
406        </para>
407       </listitem>
408      </varlistentry>
409
410      <varlistentry>
411       <term>ParameterStatus</term>
412       <listitem>
413        <para>
414         This message informs the frontend about the current (initial)
415          setting of backend parameters, such as <xref
416          linkend="guc-client-encoding"> or <xref linkend="guc-datestyle">.
417          The frontend can ignore this message, or record the settings
418          for its future use; see <xref linkend="protocol-async"> for
419          more details.  The frontend should not respond to this
420          message, but should continue listening for a ReadyForQuery
421          message.
422        </para>
423       </listitem>
424      </varlistentry>
425
426      <varlistentry>
427       <term>ReadyForQuery</term>
428       <listitem>
429        <para>
430         Start-up is completed.  The frontend can now issue commands.
431        </para>
432       </listitem>
433      </varlistentry>
434
435      <varlistentry>
436       <term>ErrorResponse</term>
437       <listitem>
438        <para>
439         Start-up failed.  The connection is closed after sending this
440         message.
441        </para>
442       </listitem>
443      </varlistentry>
444
445      <varlistentry>
446       <term>NoticeResponse</term>
447       <listitem>
448        <para>
449         A warning message has been issued.  The frontend should
450         display the message but continue listening for ReadyForQuery
451         or ErrorResponse.
452        </para>
453       </listitem>
454      </varlistentry>
455     </variablelist>
456    </para>
457
458    <para>
459     The ReadyForQuery message is the same one that the backend will
460     issue after each command cycle.  Depending on the coding needs of
461     the frontend, it is reasonable to consider ReadyForQuery as
462     starting a command cycle, or to consider ReadyForQuery as ending the
463     start-up phase and each subsequent command cycle.
464    </para>
465   </sect2>
466
467   <sect2>
468    <title>Simple Query</title>
469
470    <para>
471     A simple query cycle is initiated by the frontend sending a Query message
472     to the backend.  The message includes an SQL command (or commands)
473     expressed as a text string.
474     The backend then sends one or more response
475     messages depending on the contents of the query command string,
476     and finally a ReadyForQuery response message.  ReadyForQuery
477     informs the frontend that it can safely send a new command.
478     (It is not actually necessary for the frontend to wait for
479     ReadyForQuery before issuing another command, but the frontend must
480     then take responsibility for figuring out what happens if the earlier
481     command fails and already-issued later commands succeed.)
482    </para>
483
484    <para>
485     The possible response messages from the backend are:
486
487     <variablelist>
488      <varlistentry>
489       <term>CommandComplete</term>
490       <listitem>
491        <para>
492         An SQL command completed normally.
493        </para>
494       </listitem>
495      </varlistentry>
496
497      <varlistentry>
498       <term>CopyInResponse</term>
499       <listitem>
500        <para>
501         The backend is ready to copy data from the frontend to a
502         table; see <xref linkend="protocol-copy">.
503        </para>
504       </listitem>
505      </varlistentry>
506
507      <varlistentry>
508       <term>CopyOutResponse</term>
509       <listitem>
510        <para>
511         The backend is ready to copy data from a table to the
512         frontend; see <xref linkend="protocol-copy">.
513        </para>
514       </listitem>
515      </varlistentry>
516
517      <varlistentry>
518       <term>RowDescription</term>
519       <listitem>
520        <para>
521         Indicates that rows are about to be returned in response to
522         a <command>SELECT</command>, <command>FETCH</command>, etc query.
523         The contents of this message describe the column layout of the rows.
524         This will be followed by a DataRow message for each row being returned
525         to the frontend.
526        </para>
527       </listitem>
528      </varlistentry>
529
530      <varlistentry>
531       <term>DataRow</term>
532       <listitem>
533        <para>
534         One of the set of rows returned by
535         a <command>SELECT</command>, <command>FETCH</command>, etc query.
536        </para>
537       </listitem>
538      </varlistentry>
539
540      <varlistentry>
541       <term>EmptyQueryResponse</term>
542       <listitem>
543        <para>
544         An empty query string was recognized.
545        </para>
546       </listitem>
547      </varlistentry>
548
549      <varlistentry>
550       <term>ErrorResponse</term>
551       <listitem>
552        <para>
553         An error has occurred.
554        </para>
555       </listitem>
556      </varlistentry>
557
558      <varlistentry>
559       <term>ReadyForQuery</term>
560       <listitem>
561        <para>
562         Processing of the query string is complete.  A separate
563         message is sent to indicate this because the query string might
564         contain multiple SQL commands.  (CommandComplete marks the
565         end of processing one SQL command, not the whole string.)
566         ReadyForQuery will always be sent, whether processing
567         terminates successfully or with an error.
568        </para>
569       </listitem>
570      </varlistentry>
571
572      <varlistentry>
573       <term>NoticeResponse</term>
574       <listitem>
575        <para>
576         A warning message has been issued in relation to the query.
577         Notices are in addition to other responses, i.e., the backend
578         will continue processing the command.
579        </para>
580       </listitem>
581      </varlistentry>
582
583     </variablelist>
584    </para>
585
586    <para>
587     The response to a <command>SELECT</> query (or other queries that
588     return row sets, such as <command>EXPLAIN</> or <command>SHOW</>)
589     normally consists of RowDescription, zero or more
590     DataRow messages, and then CommandComplete.
591     <command>COPY</> to or from the frontend invokes special protocol
592     as described in <xref linkend="protocol-copy">.
593     All other query types normally produce only
594     a CommandComplete message.
595    </para>
596
597    <para>
598     Since a query string could contain several queries (separated by
599     semicolons), there might be several such response sequences before the
600     backend finishes processing the query string.  ReadyForQuery is issued
601     when the entire string has been processed and the backend is ready to
602     accept a new query string.
603    </para>
604
605    <para>
606     If a completely empty (no contents other than whitespace) query string
607     is received, the response is EmptyQueryResponse followed by ReadyForQuery.
608    </para>
609
610    <para>
611     In the event of an error, ErrorResponse is issued followed by
612     ReadyForQuery.  All further processing of the query string is aborted by
613     ErrorResponse (even if more queries remained in it).  Note that this
614     might occur partway through the sequence of messages generated by an
615     individual query.
616    </para>
617
618    <para>
619     In simple Query mode, the format of retrieved values is always text,
620     except when the given command is a <command>FETCH</> from a cursor
621     declared with the <literal>BINARY</> option.  In that case, the
622     retrieved values are in binary format.  The format codes given in
623     the RowDescription message tell which format is being used.
624    </para>
625
626    <para>
627     A frontend must be prepared to accept ErrorResponse and
628     NoticeResponse messages whenever it is expecting any other type of
629     message.  See also <xref linkend="protocol-async"> concerning messages
630     that the backend might generate due to outside events.
631    </para>
632
633    <para>
634     Recommended practice is to code frontends in a state-machine style
635     that will accept any message type at any time that it could make sense,
636     rather than wiring in assumptions about the exact sequence of messages.
637    </para>
638   </sect2>
639
640   <sect2 id="protocol-flow-ext-query">
641    <title>Extended Query</title>
642
643    <para>
644     The extended query protocol breaks down the above-described simple
645     query protocol into multiple steps.  The results of preparatory
646     steps can be re-used multiple times for improved efficiency.
647     Furthermore, additional features are available, such as the possibility
648     of supplying data values as separate parameters instead of having to
649     insert them directly into a query string.
650    </para>
651
652    <para>
653     In the extended protocol, the frontend first sends a Parse message,
654     which contains a textual query string, optionally some information
655     about data types of parameter placeholders, and the
656     name of a destination prepared-statement object (an empty string
657     selects the unnamed prepared statement).  The response is
658     either ParseComplete or ErrorResponse.  Parameter data types can be
659     specified by OID; if not given, the parser attempts to infer the
660     data types in the same way as it would do for untyped literal string
661     constants.
662    </para>
663
664    <note>
665     <para>
666      A parameter data type can be left unspecified by setting it to zero,
667      or by making the array of parameter type OIDs shorter than the
668      number of parameter symbols (<literal>$</><replaceable>n</>)
669      used in the query string.  Another special case is that a parameter's
670      type can be specified as <type>void</> (that is, the OID of the
671      <type>void</> pseudotype).  This is meant to allow parameter symbols
672      to be used for function parameters that are actually OUT parameters.
673      Ordinarily there is no context in which a <type>void</> parameter
674      could be used, but if such a parameter symbol appears in a function's
675      parameter list, it is effectively ignored.  For example, a function
676      call such as <literal>foo($1,$2,$3,$4)</> could match a function with
677      two IN and two OUT arguments, if <literal>$3</> and <literal>$4</>
678      are specified as having type <type>void</>.
679     </para>
680    </note>
681
682    <note>
683     <para>
684      The query string contained in a Parse message cannot include more
685      than one SQL statement; else a syntax error is reported.  This
686      restriction does not exist in the simple-query protocol, but it
687      does exist in the extended protocol, because allowing prepared
688      statements or portals to contain multiple commands would complicate
689      the protocol unduly.
690     </para>
691    </note>
692
693    <para>
694     If successfully created, a named prepared-statement object lasts till
695     the end of the current session, unless explicitly destroyed.  An unnamed
696     prepared statement lasts only until the next Parse statement specifying
697     the unnamed statement as destination is issued.  (Note that a simple
698     Query message also destroys the unnamed statement.)  Named prepared
699     statements must be explicitly closed before they can be redefined by
700     another Parse message, but this is not required for the unnamed statement.
701     Named prepared statements can also be created and accessed at the SQL
702     command level, using <command>PREPARE</> and <command>EXECUTE</>.
703    </para>
704
705    <para>
706     Once a prepared statement exists, it can be readied for execution using a
707     Bind message.  The Bind message gives the name of the source prepared
708     statement (empty string denotes the unnamed prepared statement), the name
709     of the destination portal (empty string denotes the unnamed portal), and
710     the values to use for any parameter placeholders present in the prepared
711     statement.  The
712     supplied parameter set must match those needed by the prepared statement.
713     (If you declared any <type>void</> parameters in the Parse message,
714     pass NULL values for them in the Bind message.)
715     Bind also specifies the format to use for any data returned
716     by the query; the format can be specified overall, or per-column.
717     The response is either BindComplete or ErrorResponse.
718    </para>
719
720    <note>
721     <para>
722      The choice between text and binary output is determined by the format
723      codes given in Bind, regardless of the SQL command involved.  The
724      <literal>BINARY</> attribute in cursor declarations is irrelevant when
725      using extended query protocol.
726     </para>
727    </note>
728
729    <para>
730     Query planning typically occurs when the Bind message is processed.
731     If the prepared statement has no parameters, or is executed repeatedly,
732     the server might save the created plan and re-use it during subsequent
733     Bind messages for the same prepared statement.  However, it will do so
734     only if it finds that a generic plan can be created that is not much
735     less efficient than a plan that depends on the specific parameter values
736     supplied.  This happens transparently so far as the protocol is concerned.
737    </para>
738
739    <para>
740     If successfully created, a named portal object lasts till the end of the
741     current transaction, unless explicitly destroyed.  An unnamed portal is
742     destroyed at the end of the transaction, or as soon as the next Bind
743     statement specifying the unnamed portal as destination is issued.  (Note
744     that a simple Query message also destroys the unnamed portal.)  Named
745     portals must be explicitly closed before they can be redefined by another
746     Bind message, but this is not required for the unnamed portal.
747     Named portals can also be created and accessed at the SQL
748     command level, using <command>DECLARE CURSOR</> and <command>FETCH</>.
749    </para>
750
751    <para>
752     Once a portal exists, it can be executed using an Execute message.
753     The Execute message specifies the portal name (empty string denotes the
754     unnamed portal) and
755     a maximum result-row count (zero meaning <quote>fetch all rows</>).
756     The result-row count is only meaningful for portals
757     containing commands that return row sets; in other cases the command is
758     always executed to completion, and the row count is ignored.
759     The possible
760     responses to Execute are the same as those described above for queries
761     issued via simple query protocol, except that Execute doesn't cause
762     ReadyForQuery or RowDescription to be issued.
763    </para>
764
765    <para>
766     If Execute terminates before completing the execution of a portal
767     (due to reaching a nonzero result-row count), it will send a
768     PortalSuspended message; the appearance of this message tells the frontend
769     that another Execute should be issued against the same portal to
770     complete the operation.  The CommandComplete message indicating
771     completion of the source SQL command is not sent until
772     the portal's execution is completed.  Therefore, an Execute phase is
773     always terminated by the appearance of exactly one of these messages:
774     CommandComplete, EmptyQueryResponse (if the portal was created from
775     an empty query string), ErrorResponse, or PortalSuspended.
776    </para>
777
778    <para>
779     At completion of each series of extended-query messages, the frontend
780     should issue a Sync message.  This parameterless message causes the
781     backend to close the current transaction if it's not inside a
782     <command>BEGIN</>/<command>COMMIT</> transaction block (<quote>close</>
783     meaning to commit if no error, or roll back if error).  Then a
784     ReadyForQuery response is issued.  The purpose of Sync is to provide
785     a resynchronization point for error recovery.  When an error is detected
786     while processing any extended-query message, the backend issues
787     ErrorResponse, then reads and discards messages until a Sync is reached,
788     then issues ReadyForQuery and returns to normal message processing.
789     (But note that no skipping occurs if an error is detected
790     <emphasis>while</> processing Sync &mdash; this ensures that there is one
791     and only one ReadyForQuery sent for each Sync.)
792    </para>
793
794    <note>
795     <para>
796      Sync does not cause a transaction block opened with <command>BEGIN</>
797      to be closed.  It is possible to detect this situation since the
798      ReadyForQuery message includes transaction status information.
799     </para>
800    </note>
801
802    <para>
803     In addition to these fundamental, required operations, there are several
804     optional operations that can be used with extended-query protocol.
805    </para>
806
807    <para>
808     The Describe message (portal variant) specifies the name of an existing
809     portal (or an empty string for the unnamed portal).  The response is a
810     RowDescription message describing the rows that will be returned by
811     executing the portal; or a NoData message if the portal does not contain a
812     query that will return rows; or ErrorResponse if there is no such portal.
813    </para>
814
815    <para>
816     The Describe message (statement variant) specifies the name of an existing
817     prepared statement (or an empty string for the unnamed prepared
818     statement).  The response is a ParameterDescription message describing the
819     parameters needed by the statement, followed by a RowDescription message
820     describing the rows that will be returned when the statement is eventually
821     executed (or a NoData message if the statement will not return rows).
822     ErrorResponse is issued if there is no such prepared statement.  Note that
823     since Bind has not yet been issued, the formats to be used for returned
824     columns are not yet known to the backend; the format code fields in the
825     RowDescription message will be zeroes in this case.
826    </para>
827
828    <tip>
829     <para>
830      In most scenarios the frontend should issue one or the other variant
831      of Describe before issuing Execute, to ensure that it knows how to
832      interpret the results it will get back.
833     </para>
834    </tip>
835
836    <para>
837     The Close message closes an existing prepared statement or portal
838     and releases resources.  It is not an error to issue Close against
839     a nonexistent statement or portal name.  The response is normally
840     CloseComplete, but could be ErrorResponse if some difficulty is
841     encountered while releasing resources.  Note that closing a prepared
842     statement implicitly closes any open portals that were constructed
843     from that statement.
844    </para>
845
846    <para>
847     The Flush message does not cause any specific output to be generated,
848     but forces the backend to deliver any data pending in its output
849     buffers.  A Flush must be sent after any extended-query command except
850     Sync, if the frontend wishes to examine the results of that command before
851     issuing more commands.  Without Flush, messages returned by the backend
852     will be combined into the minimum possible number of packets to minimize
853     network overhead.
854    </para>
855
856    <note>
857     <para>
858      The simple Query message is approximately equivalent to the series Parse,
859      Bind, portal Describe, Execute, Close, Sync, using the unnamed prepared
860      statement and portal objects and no parameters.  One difference is that
861      it will accept multiple SQL statements in the query string, automatically
862      performing the bind/describe/execute sequence for each one in succession.
863      Another difference is that it will not return ParseComplete, BindComplete,
864      CloseComplete, or NoData messages.
865     </para>
866    </note>
867   </sect2>
868
869   <sect2>
870    <title>Function Call</title>
871
872    <para>
873     The Function Call sub-protocol allows the client to request a direct
874     call of any function that exists in the database's
875     <structname>pg_proc</structname> system catalog.  The client must have
876     execute permission for the function.
877    </para>
878
879    <note>
880     <para>
881      The Function Call sub-protocol is a legacy feature that is probably best
882      avoided in new code.  Similar results can be accomplished by setting up
883      a prepared statement that does <literal>SELECT function($1, ...)</>.
884      The Function Call cycle can then be replaced with Bind/Execute.
885     </para>
886    </note>
887
888    <para>
889     A Function Call cycle is initiated by the frontend sending a
890     FunctionCall message to the backend.  The backend then sends one
891     or more response messages depending on the results of the function
892     call, and finally a ReadyForQuery response message.  ReadyForQuery
893     informs the frontend that it can safely send a new query or
894     function call.
895    </para>
896
897    <para>
898     The possible response messages from the backend are:
899
900     <variablelist>
901      <varlistentry>
902       <term>ErrorResponse</term>
903       <listitem>
904        <para>
905         An error has occurred.
906        </para>
907       </listitem>
908      </varlistentry>
909
910      <varlistentry>
911       <term>FunctionCallResponse</term>
912       <listitem>
913        <para>
914         The function call was completed and returned the result given
915         in the message.
916         (Note that the Function Call protocol can only handle a single
917         scalar result, not a row type or set of results.)
918        </para>
919       </listitem>
920      </varlistentry>
921
922      <varlistentry>
923       <term>ReadyForQuery</term>
924       <listitem>
925        <para>
926         Processing of the function call is complete.  ReadyForQuery
927         will always be sent, whether processing terminates
928         successfully or with an error.
929        </para>
930       </listitem>
931      </varlistentry>
932
933      <varlistentry>
934       <term>NoticeResponse</term>
935       <listitem>
936        <para>
937         A warning message has been issued in relation to the function
938         call.  Notices are in addition to other responses, i.e., the
939         backend will continue processing the command.
940        </para>
941       </listitem>
942      </varlistentry>
943     </variablelist>
944    </para>
945   </sect2>
946
947   <sect2 id="protocol-copy">
948    <title>COPY Operations</title>
949
950    <para>
951     The <command>COPY</> command allows high-speed bulk data transfer
952     to or from the server.  Copy-in and copy-out operations each switch
953     the connection into a distinct sub-protocol, which lasts until the
954     operation is completed.
955    </para>
956
957    <para>
958     Copy-in mode (data transfer to the server) is initiated when the
959     backend executes a <command>COPY FROM STDIN</> SQL statement.  The backend
960     sends a CopyInResponse message to the frontend.  The frontend should
961     then send zero or more CopyData messages, forming a stream of input
962     data.  (The message boundaries are not required to have anything to do
963     with row boundaries, although that is often a reasonable choice.)
964     The frontend can terminate the copy-in mode by sending either a CopyDone
965     message (allowing successful termination) or a CopyFail message (which
966     will cause the <command>COPY</> SQL statement to fail with an
967     error).  The backend then reverts to the command-processing mode it was
968     in before the <command>COPY</> started, which will be either simple or
969     extended query protocol.  It will next send either CommandComplete
970     (if successful) or ErrorResponse (if not).
971    </para>
972
973    <para>
974     In the event of a backend-detected error during copy-in mode (including
975     receipt of a CopyFail message), the backend will issue an ErrorResponse
976     message.  If the <command>COPY</> command was issued via an extended-query
977     message, the backend will now discard frontend messages until a Sync
978     message is received, then it will issue ReadyForQuery and return to normal
979     processing.  If the <command>COPY</> command was issued in a simple
980     Query message, the rest of that message is discarded and ReadyForQuery
981     is issued.  In either case, any subsequent CopyData, CopyDone, or CopyFail
982     messages issued by the frontend will simply be dropped.
983    </para>
984
985    <para>
986     The backend will ignore Flush and Sync messages received during copy-in
987     mode.  Receipt of any other non-copy message type constitutes an error
988     that will abort the copy-in state as described above.  (The exception for
989     Flush and Sync is for the convenience of client libraries that always
990     send Flush or Sync after an Execute message, without checking whether
991     the command to be executed is a <command>COPY FROM STDIN</>.)
992    </para>
993
994    <para>
995     Copy-out mode (data transfer from the server) is initiated when the
996     backend executes a <command>COPY TO STDOUT</> SQL statement.  The backend
997     sends a CopyOutResponse message to the frontend, followed by
998     zero or more CopyData messages (always one per row), followed by CopyDone.
999     The backend then reverts to the command-processing mode it was
1000     in before the <command>COPY</> started, and sends CommandComplete.
1001     The frontend cannot abort the transfer (except by closing the connection
1002     or issuing a Cancel request),
1003     but it can discard unwanted CopyData and CopyDone messages.
1004    </para>
1005
1006    <para>
1007     In the event of a backend-detected error during copy-out mode,
1008     the backend will issue an ErrorResponse message and revert to normal
1009     processing.  The frontend should treat receipt of ErrorResponse as
1010     terminating the copy-out mode.
1011    </para>
1012
1013    <para>
1014     It is possible for NoticeResponse and ParameterStatus messages to be
1015     interspersed between CopyData messages; frontends must handle these cases,
1016     and should be prepared for other asynchronous message types as well (see
1017     <xref linkend="protocol-async">).  Otherwise, any message type other than
1018     CopyData or CopyDone may be treated as terminating copy-out mode.
1019    </para>
1020
1021    <para>
1022     There is another Copy-related mode called copy-both, which allows
1023     high-speed bulk data transfer to <emphasis>and</> from the server.
1024     Copy-both mode is initiated when a backend in walsender mode
1025     executes a <command>START_REPLICATION</command> statement.  The
1026     backend sends a CopyBothResponse message to the frontend.  Both
1027     the backend and the frontend may then send CopyData messages
1028     until either end sends a CopyDone message. After the client
1029     sends a CopyDone message, the connection goes from copy-both mode to
1030     copy-out mode, and the client may not send any more CopyData messages.
1031     Similarly, when the server sends a CopyDone message, the connection
1032     goes into copy-in mode, and the server may not send any more CopyData
1033     messages. After both sides have sent a CopyDone message, the copy mode
1034     is terminated, and the backend reverts to the command-processing mode.
1035     In the event of a backend-detected error during copy-both mode,
1036     the backend will issue an ErrorResponse message, discard frontend messages
1037     until a Sync message is received, and then issue ReadyForQuery and return
1038     to normal processing.  The frontend should treat receipt of ErrorResponse
1039     as terminating the copy in both directions; no CopyDone should be sent
1040     in this case.  See <xref linkend="protocol-replication"> for more
1041     information on the subprotocol transmitted over copy-both mode.
1042    </para>
1043
1044    <para>
1045     The CopyInResponse, CopyOutResponse and CopyBothResponse messages
1046     include fields that inform the frontend of the number of columns
1047     per row and the format codes being used for each column.  (As of
1048     the present implementation, all columns in a given <command>COPY</>
1049     operation will use the same format, but the message design does not
1050     assume this.)
1051    </para>
1052
1053   </sect2>
1054
1055   <sect2 id="protocol-async">
1056    <title>Asynchronous Operations</title>
1057
1058    <para>
1059     There are several cases in which the backend will send messages that
1060     are not specifically prompted by the frontend's command stream.
1061     Frontends must be prepared to deal with these messages at any time,
1062     even when not engaged in a query.
1063     At minimum, one should check for these cases before beginning to
1064     read a query response.
1065    </para>
1066
1067    <para>
1068     It is possible for NoticeResponse messages to be generated due to
1069     outside activity; for example, if the database administrator commands
1070     a <quote>fast</> database shutdown, the backend will send a NoticeResponse
1071     indicating this fact before closing the connection.  Accordingly,
1072     frontends should always be prepared to accept and display NoticeResponse
1073     messages, even when the connection is nominally idle.
1074    </para>
1075
1076    <para>
1077     ParameterStatus messages will be generated whenever the active
1078     value changes for any of the parameters the backend believes the
1079     frontend should know about.  Most commonly this occurs in response
1080     to a <command>SET</> SQL command executed by the frontend, and
1081     this case is effectively synchronous &mdash; but it is also possible
1082     for parameter status changes to occur because the administrator
1083     changed a configuration file and then sent the
1084     <systemitem>SIGHUP</systemitem> signal to the server.  Also,
1085     if a <command>SET</command> command is rolled back, an appropriate
1086     ParameterStatus message will be generated to report the current
1087     effective value.
1088    </para>
1089
1090    <para>
1091     At present there is a hard-wired set of parameters for which
1092     ParameterStatus will be generated: they are
1093     <varname>server_version</>,
1094     <varname>server_encoding</>,
1095     <varname>client_encoding</>,
1096     <varname>application_name</>,
1097     <varname>is_superuser</>,
1098     <varname>session_authorization</>,
1099     <varname>DateStyle</>,
1100     <varname>IntervalStyle</>,
1101     <varname>TimeZone</>,
1102     <varname>integer_datetimes</>, and
1103     <varname>standard_conforming_strings</>.
1104     (<varname>server_encoding</>, <varname>TimeZone</>, and
1105     <varname>integer_datetimes</> were not reported by releases before 8.0;
1106     <varname>standard_conforming_strings</> was not reported by releases
1107     before 8.1;
1108     <varname>IntervalStyle</> was not reported by releases before 8.4;
1109     <varname>application_name</> was not reported by releases before 9.0.)
1110     Note that
1111     <varname>server_version</>,
1112     <varname>server_encoding</> and
1113     <varname>integer_datetimes</>
1114     are pseudo-parameters that cannot change after startup.
1115     This set might change in the future, or even become configurable.
1116     Accordingly, a frontend should simply ignore ParameterStatus for
1117     parameters that it does not understand or care about.
1118    </para>
1119
1120    <para>
1121     If a frontend issues a <command>LISTEN</command> command, then the
1122     backend will send a NotificationResponse message (not to be
1123     confused with NoticeResponse!)  whenever a
1124     <command>NOTIFY</command> command is executed for the same
1125     channel name.
1126    </para>
1127
1128    <note>
1129     <para>
1130      At present, NotificationResponse can only be sent outside a
1131      transaction, and thus it will not occur in the middle of a
1132      command-response series, though it might occur just before ReadyForQuery.
1133      It is unwise to design frontend logic that assumes that, however.
1134      Good practice is to be able to accept NotificationResponse at any
1135      point in the protocol.
1136     </para>
1137    </note>
1138   </sect2>
1139
1140   <sect2>
1141    <title>Canceling Requests in Progress</title>
1142
1143    <para>
1144     During the processing of a query, the frontend might request
1145     cancellation of the query.  The cancel request is not sent
1146     directly on the open connection to the backend for reasons of
1147     implementation efficiency: we don't want to have the backend
1148     constantly checking for new input from the frontend during query
1149     processing.  Cancel requests should be relatively infrequent, so
1150     we make them slightly cumbersome in order to avoid a penalty in
1151     the normal case.
1152    </para>
1153
1154    <para>
1155     To issue a cancel request, the frontend opens a new connection to
1156     the server and sends a CancelRequest message, rather than the
1157     StartupMessage message that would ordinarily be sent across a new
1158     connection.  The server will process this request and then close
1159     the connection.  For security reasons, no direct reply is made to
1160     the cancel request message.
1161    </para>
1162
1163    <para>
1164     A CancelRequest message will be ignored unless it contains the
1165     same key data (PID and secret key) passed to the frontend during
1166     connection start-up.  If the request matches the PID and secret
1167     key for a currently executing backend, the processing of the
1168     current query is aborted.  (In the existing implementation, this is
1169     done by sending a special signal to the backend process that is
1170     processing the query.)
1171    </para>
1172
1173    <para>
1174     The cancellation signal might or might not have any effect &mdash; for
1175     example, if it arrives after the backend has finished processing
1176     the query, then it will have no effect.  If the cancellation is
1177     effective, it results in the current command being terminated
1178     early with an error message.
1179    </para>
1180
1181    <para>
1182     The upshot of all this is that for reasons of both security and
1183     efficiency, the frontend has no direct way to tell whether a
1184     cancel request has succeeded.  It must continue to wait for the
1185     backend to respond to the query.  Issuing a cancel simply improves
1186     the odds that the current query will finish soon, and improves the
1187     odds that it will fail with an error message instead of
1188     succeeding.
1189    </para>
1190
1191    <para>
1192     Since the cancel request is sent across a new connection to the
1193     server and not across the regular frontend/backend communication
1194     link, it is possible for the cancel request to be issued by any
1195     process, not just the frontend whose query is to be canceled.
1196     This might provide additional flexibility when building
1197     multiple-process applications.  It also introduces a security
1198     risk, in that unauthorized persons might try to cancel queries.
1199     The security risk is addressed by requiring a dynamically
1200     generated secret key to be supplied in cancel requests.
1201    </para>
1202   </sect2>
1203
1204   <sect2>
1205    <title>Termination</title>
1206
1207    <para>
1208     The normal, graceful termination procedure is that the frontend
1209     sends a Terminate message and immediately closes the connection.
1210     On receipt of this message, the backend closes the connection and
1211     terminates.
1212    </para>
1213
1214    <para>
1215     In rare cases (such as an administrator-commanded database shutdown)
1216     the backend might disconnect without any frontend request to do so.
1217     In such cases the backend will attempt to send an error or notice message
1218     giving the reason for the disconnection before it closes the connection.
1219    </para>
1220
1221    <para>
1222     Other termination scenarios arise from various failure cases, such as core
1223     dump at one end or the other, loss of the communications link, loss of
1224     message-boundary synchronization, etc.  If either frontend or backend sees
1225     an unexpected closure of the connection, it should clean
1226     up and terminate.  The frontend has the option of launching a new backend
1227     by recontacting the server if it doesn't want to terminate itself.
1228     Closing the connection is also advisable if an unrecognizable message type
1229     is received, since this probably indicates loss of message-boundary sync.
1230    </para>
1231
1232    <para>
1233     For either normal or abnormal termination, any open transaction is
1234     rolled back, not committed.  One should note however that if a
1235     frontend disconnects while a non-<command>SELECT</command> query
1236     is being processed, the backend will probably finish the query
1237     before noticing the disconnection.  If the query is outside any
1238     transaction block (<command>BEGIN</> ... <command>COMMIT</>
1239     sequence) then its results might be committed before the
1240     disconnection is recognized.
1241    </para>
1242   </sect2>
1243
1244   <sect2>
1245    <title><acronym>SSL</acronym> Session Encryption</title>
1246
1247    <para>
1248     If <productname>PostgreSQL</> was built with
1249     <acronym>SSL</acronym> support, frontend/backend communications
1250     can be encrypted using <acronym>SSL</acronym>.  This provides
1251     communication security in environments where attackers might be
1252     able to capture the session traffic. For more information on
1253     encrypting <productname>PostgreSQL</productname> sessions with
1254     <acronym>SSL</acronym>, see <xref linkend="ssl-tcp">.
1255    </para>
1256
1257    <para>
1258     To initiate an <acronym>SSL</acronym>-encrypted connection, the
1259     frontend initially sends an SSLRequest message rather than a
1260     StartupMessage.  The server then responds with a single byte
1261     containing <literal>S</> or <literal>N</>, indicating that it is
1262     willing or unwilling to perform <acronym>SSL</acronym>,
1263     respectively.  The frontend might close the connection at this point
1264     if it is dissatisfied with the response.  To continue after
1265     <literal>S</>, perform an <acronym>SSL</acronym> startup handshake
1266     (not described here, part of the <acronym>SSL</acronym>
1267     specification) with the server.  If this is successful, continue
1268     with sending the usual StartupMessage.  In this case the
1269     StartupMessage and all subsequent data will be
1270     <acronym>SSL</acronym>-encrypted.  To continue after
1271     <literal>N</>, send the usual StartupMessage and proceed without
1272     encryption.
1273    </para>
1274
1275    <para>
1276     The frontend should also be prepared to handle an ErrorMessage
1277     response to SSLRequest from the server.  This would only occur if
1278     the server predates the addition of <acronym>SSL</acronym> support
1279     to <productname>PostgreSQL</>.  (Such servers are now very ancient,
1280     and likely do not exist in the wild anymore.)
1281     In this case the connection must
1282     be closed, but the frontend might choose to open a fresh connection
1283     and proceed without requesting <acronym>SSL</acronym>.
1284    </para>
1285
1286    <para>
1287     An initial SSLRequest can also be used in a connection that is being
1288     opened to send a CancelRequest message.
1289    </para>
1290
1291    <para>
1292     While the protocol itself does not provide a way for the server to
1293     force <acronym>SSL</acronym> encryption, the administrator can
1294     configure the server to reject unencrypted sessions as a byproduct
1295     of authentication checking.
1296    </para>
1297   </sect2>
1298  </sect1>
1299
1300 <sect1 id="protocol-replication">
1301 <title>Streaming Replication Protocol</title>
1302
1303 <para>
1304 To initiate streaming replication, the frontend sends the
1305 <literal>replication</> parameter in the startup message. A boolean value
1306 of <literal>true</> tells the backend to go into walsender mode, wherein a
1307 small set of replication commands can be issued instead of SQL statements. Only
1308 the simple query protocol can be used in walsender mode.
1309 Passing <literal>database</> as the value instructs walsender to connect to
1310 the database specified in the <literal>dbname</> parameter, which will allow
1311 the connection to be used for logical replication from that database.
1312 </para>
1313 <para>
1314  For the purpose of testing replication commands, you can make a replication
1315  connection via <application>psql</application> or any other <literal>libpq</literal>-using
1316  tool with a connection string including the <literal>replication</literal> option,
1317  e.g.:
1318  <programlisting>
1319   psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
1320  </programlisting>
1321  However it is often more useful to use
1322  <application>pg_receivexlog</application> (for physical replication) or
1323  <application>pg_recvlogical</application> (for logical replication).
1324 </para>
1325
1326 <para>
1327 The commands accepted in walsender mode are:
1328 <variablelist>
1329   <varlistentry>
1330     <term>IDENTIFY_SYSTEM</term>
1331     <listitem>
1332      <para>
1333       Requests the server to identify itself. Server replies with a result
1334       set of a single row, containing four fields:
1335      </para>
1336
1337      <para>
1338       <variablelist>
1339       <varlistentry>
1340       <term>
1341        systemid
1342       </term>
1343       <listitem>
1344       <para>
1345        The unique system identifier identifying the cluster. This
1346        can be used to check that the base backup used to initialize the
1347        standby came from the same cluster.
1348       </para>
1349       </listitem>
1350       </varlistentry>
1351
1352       <varlistentry>
1353       <term>
1354        timeline
1355       </term>
1356       <listitem>
1357       <para>
1358        Current TimelineID. Also useful to check that the standby is
1359        consistent with the master.
1360       </para>
1361       </listitem>
1362       </varlistentry>
1363
1364       <varlistentry>
1365       <term>
1366        xlogpos
1367       </term>
1368       <listitem>
1369       <para>
1370        Current xlog write location. Useful to get a known location in the
1371        transaction log where streaming can start.
1372       </para>
1373       </listitem>
1374       </varlistentry>
1375
1376       <varlistentry>
1377       <term>
1378        dbname
1379       </term>
1380       <listitem>
1381       <para>
1382        Database connected to or NULL.
1383       </para>
1384       </listitem>
1385       </varlistentry>
1386
1387       </variablelist>
1388      </para>
1389     </listitem>
1390   </varlistentry>
1391
1392   <varlistentry>
1393     <term>TIMELINE_HISTORY <replaceable class="parameter">tli</replaceable></term>
1394     <listitem>
1395      <para>
1396       Requests the server to send over the timeline history file for timeline
1397       <replaceable class="parameter">tli</replaceable>.  Server replies with a
1398       result set of a single row, containing two fields:
1399      </para>
1400
1401      <para>
1402       <variablelist>
1403       <varlistentry>
1404       <term>
1405        filename
1406       </term>
1407       <listitem>
1408       <para>
1409        Filename of the timeline history file, e.g 00000002.history.
1410       </para>
1411       </listitem>
1412       </varlistentry>
1413
1414       <varlistentry>
1415       <term>
1416        content
1417       </term>
1418       <listitem>
1419       <para>
1420        Contents of the timeline history file.
1421       </para>
1422       </listitem>
1423       </varlistentry>
1424
1425       </variablelist>
1426      </para>
1427     </listitem>
1428   </varlistentry>
1429
1430   <varlistentry>
1431     <term>CREATE_REPLICATION_SLOT <replaceable class="parameter">slotname</> { <literal>PHYSICAL</> | <literal>LOGICAL</> <replaceable class="parameter">output_plugin</> } <indexterm><primary>CREATE_REPLICATION_SLOT</primary></indexterm></term>
1432     <listitem>
1433      <para>
1434       Create a physical or logical replication
1435       slot. See <xref linkend="streaming-replication-slots"> for more about
1436       replication slots.
1437      </para>
1438      <variablelist>
1439       <varlistentry>
1440        <term><replaceable class="parameter">slotname</></term>
1441        <listitem>
1442          <para>
1443           The name of the slot to create. Must be a valid replication slot
1444           name (see <xref linkend="streaming-replication-slots-manipulation">).
1445          </para>
1446        </listitem>
1447       </varlistentry>
1448
1449       <varlistentry>
1450        <term><replaceable class="parameter">output_plugin</></term>
1451        <listitem>
1452          <para>
1453           The name of the output plugin used for logical decoding
1454           (see <xref linkend="logicaldecoding-output-plugin">).
1455          </para>
1456        </listitem>
1457       </varlistentry>
1458      </variablelist>
1459     </listitem>
1460   </varlistentry>
1461
1462   <varlistentry>
1463     <term>START_REPLICATION [<literal>SLOT</literal> <replaceable class="parameter">slotname</>] [<literal>PHYSICAL</literal>] <replaceable class="parameter">XXX/XXX</> [<literal>TIMELINE</literal> <replaceable class="parameter">tli</>]</term>
1464     <listitem>
1465      <para>
1466       Instructs server to start streaming WAL, starting at
1467       WAL position <replaceable class="parameter">XXX/XXX</>.
1468       If <literal>TIMELINE</literal> option is specified,
1469       streaming starts on timeline <replaceable class="parameter">tli</>;
1470       otherwise, the server's current timeline is selected. The server can
1471       reply with an error, e.g. if the requested section of WAL has already
1472       been recycled. On success, server responds with a CopyBothResponse
1473       message, and then starts to stream WAL to the frontend.
1474      </para>
1475
1476      <para>
1477       If the client requests a timeline that's not the latest, but is part of
1478       the history of the server, the server will stream all the WAL on that
1479       timeline starting from the requested startpoint, up to the point where
1480       the server switched to another timeline. If the client requests
1481       streaming at exactly the end of an old timeline, the server responds
1482       immediately with CommandComplete without entering COPY mode.
1483      </para>
1484
1485      <para>
1486       After streaming all the WAL on a timeline that is not the latest one,
1487       the server will end streaming by exiting the COPY mode. When the client
1488       acknowledges this by also exiting COPY mode, the server sends a result
1489       set with one row and two columns, indicating the next timeline in this
1490       server's history. The first column is the next timeline's ID, and the
1491       second column is the XLOG position where the switch happened. Usually,
1492       the switch position is the end of the WAL that was streamed, but there
1493       are corner cases where the server can send some WAL from the old
1494       timeline that it has not itself replayed before promoting. Finally, the
1495       server sends CommandComplete message, and is ready to accept a new
1496       command.
1497      </para>
1498
1499      <para>
1500       WAL data is sent as a series of CopyData messages.  (This allows
1501       other information to be intermixed; in particular the server can send
1502       an ErrorResponse message if it encounters a failure after beginning
1503       to stream.)  The payload of each CopyData message from server to the
1504       client contains a message of one of the following formats:
1505      </para>
1506
1507      <para>
1508       If a slot's name is provided
1509       via <replaceable class="parameter">slotname</>, it will be updated
1510       as replication progresses so that the server knows which WAL segments -
1511       and if <varname>hot_standby_feedback</> is on which transactions -
1512       are still needed by the standby.
1513      </para>
1514
1515      <para>
1516       <variablelist>
1517       <varlistentry>
1518       <term>
1519           XLogData (B)
1520       </term>
1521       <listitem>
1522       <para>
1523       <variablelist>
1524       <varlistentry>
1525       <term>
1526           Byte1('w')
1527       </term>
1528       <listitem>
1529       <para>
1530           Identifies the message as WAL data.
1531       </para>
1532       </listitem>
1533       </varlistentry>
1534       <varlistentry>
1535       <term>
1536           Int64
1537       </term>
1538       <listitem>
1539       <para>
1540           The starting point of the WAL data in this message.
1541       </para>
1542       </listitem>
1543       </varlistentry>
1544       <varlistentry>
1545       <term>
1546           Int64
1547       </term>
1548       <listitem>
1549       <para>
1550           The current end of WAL on the server.
1551       </para>
1552       </listitem>
1553       </varlistentry>
1554       <varlistentry>
1555       <term>
1556           Int64
1557       </term>
1558       <listitem>
1559       <para>
1560           The server's system clock at the time of transmission, as
1561           microseconds since midnight on 2000-01-01.
1562       </para>
1563       </listitem>
1564       </varlistentry>
1565       <varlistentry>
1566       <term>
1567           Byte<replaceable>n</replaceable>
1568       </term>
1569       <listitem>
1570       <para>
1571           A section of the WAL data stream.
1572       </para>
1573       <para>
1574           A single WAL record is never split across two XLogData messages.
1575           When a WAL record crosses a WAL page boundary, and is therefore
1576           already split using continuation records, it can be split at the page
1577           boundary. In other words, the first main WAL record and its
1578           continuation records can be sent in different XLogData messages.
1579       </para>
1580       </listitem>
1581       </varlistentry>
1582       </variablelist>
1583       </para>
1584       </listitem>
1585       </varlistentry>
1586       <varlistentry>
1587       <term>
1588           Primary keepalive message (B)
1589       </term>
1590       <listitem>
1591       <para>
1592       <variablelist>
1593       <varlistentry>
1594       <term>
1595           Byte1('k')
1596       </term>
1597       <listitem>
1598       <para>
1599           Identifies the message as a sender keepalive.
1600       </para>
1601       </listitem>
1602       </varlistentry>
1603       <varlistentry>
1604       <term>
1605           Int64
1606       </term>
1607       <listitem>
1608       <para>
1609           The current end of WAL on the server.
1610       </para>
1611       </listitem>
1612       </varlistentry>
1613       <varlistentry>
1614       <term>
1615           Int64
1616       </term>
1617       <listitem>
1618       <para>
1619           The server's system clock at the time of transmission, as
1620           microseconds since midnight on 2000-01-01.
1621       </para>
1622       </listitem>
1623       </varlistentry>
1624       <varlistentry>
1625       <term>
1626           Byte1
1627       </term>
1628       <listitem>
1629       <para>
1630           1 means that the client should reply to this message as soon as
1631           possible, to avoid a timeout disconnect. 0 otherwise.
1632       </para>
1633       </listitem>
1634       </varlistentry>
1635       </variablelist>
1636       </para>
1637       </listitem>
1638       </varlistentry>
1639       </variablelist>
1640      </para>
1641
1642      <para>
1643        The receiving process can send replies back to the sender at any time,
1644        using one of the following message formats (also in the payload of a
1645        CopyData message):
1646      </para>
1647
1648      <para>
1649       <variablelist>
1650       <varlistentry>
1651       <term>
1652           Standby status update (F)
1653       </term>
1654       <listitem>
1655       <para>
1656       <variablelist>
1657       <varlistentry>
1658       <term>
1659           Byte1('r')
1660       </term>
1661       <listitem>
1662       <para>
1663           Identifies the message as a receiver status update.
1664       </para>
1665       </listitem>
1666       </varlistentry>
1667       <varlistentry>
1668       <term>
1669           Int64
1670       </term>
1671       <listitem>
1672       <para>
1673           The location of the last WAL byte + 1 received and written to disk
1674           in the standby.
1675       </para>
1676       </listitem>
1677       </varlistentry>
1678       <varlistentry>
1679       <term>
1680           Int64
1681       </term>
1682       <listitem>
1683       <para>
1684           The location of the last WAL byte + 1 flushed to disk in
1685           the standby.
1686       </para>
1687       </listitem>
1688       </varlistentry>
1689       <varlistentry>
1690       <term>
1691           Int64
1692       </term>
1693       <listitem>
1694       <para>
1695           The location of the last WAL byte + 1 applied in the standby.
1696       </para>
1697       </listitem>
1698       </varlistentry>
1699       <varlistentry>
1700       <term>
1701           Int64
1702       </term>
1703       <listitem>
1704       <para>
1705           The client's system clock at the time of transmission, as
1706           microseconds since midnight on 2000-01-01.
1707       </para>
1708       </listitem>
1709       </varlistentry>
1710       <varlistentry>
1711       <term>
1712           Byte1
1713       </term>
1714       <listitem>
1715       <para>
1716           If 1, the client requests the server to reply to this message
1717           immediately. This can be used to ping the server, to test if
1718           the connection is still healthy.
1719       </para>
1720       </listitem>
1721       </varlistentry>
1722       </variablelist>
1723       </para>
1724       </listitem>
1725       </varlistentry>
1726       </variablelist>
1727      </para>
1728
1729      <para>
1730       <variablelist>
1731       <varlistentry>
1732       <term>
1733           Hot Standby feedback message (F)
1734       </term>
1735       <listitem>
1736       <para>
1737       <variablelist>
1738       <varlistentry>
1739       <term>
1740           Byte1('h')
1741       </term>
1742       <listitem>
1743       <para>
1744           Identifies the message as a Hot Standby feedback message.
1745       </para>
1746       </listitem>
1747       </varlistentry>
1748       <varlistentry>
1749       <term>
1750           Int64
1751       </term>
1752       <listitem>
1753       <para>
1754           The client's system clock at the time of transmission, as
1755           microseconds since midnight on 2000-01-01.
1756       </para>
1757       </listitem>
1758       </varlistentry>
1759       <varlistentry>
1760       <term>
1761           Int32
1762       </term>
1763       <listitem>
1764       <para>
1765           The standby's current xmin. This may be 0, if the standby is
1766           sending notification that Hot Standby feedback will no longer
1767           be sent on this connection. Later non-zero messages may
1768           reinitiate the feedback mechanism.
1769       </para>
1770       </listitem>
1771       </varlistentry>
1772       <varlistentry>
1773       <term>
1774           Int32
1775       </term>
1776       <listitem>
1777       <para>
1778           The standby's current epoch.
1779       </para>
1780       </listitem>
1781       </varlistentry>
1782       </variablelist>
1783       </para>
1784       </listitem>
1785       </varlistentry>
1786       </variablelist>
1787      </para>
1788     </listitem>
1789   </varlistentry>
1790   <varlistentry>
1791     <term>START_REPLICATION <literal>SLOT</literal> <replaceable class="parameter">slotname</> <literal>LOGICAL</literal> <replaceable class="parameter">XXX/XXX</> [ ( <replaceable>option_name</replaceable> [<replaceable>option_value</replaceable>] [, ... ] ) ]</term>
1792     <listitem>
1793      <para>
1794       Instructs server to start streaming WAL for logical replication, starting
1795       at WAL position <replaceable class="parameter">XXX/XXX</>. The server can
1796       reply with an error, e.g. if the requested section of WAL has already
1797       been recycled. On success, server responds with a CopyBothResponse
1798       message, and then starts to stream WAL to the frontend.
1799      </para>
1800
1801      <para>
1802       The messages inside the CopyBothResponse messages are of the same format
1803       documented for <literal>START_REPLICATION ... PHYSICAL</literal>.
1804      </para>
1805
1806      <para>
1807       The output plugin associated with the selected slot is used
1808       to process the output for streaming.
1809      </para>
1810
1811      <variablelist>
1812       <varlistentry>
1813        <term><literal>SLOT</literal> <replaceable class="parameter">slotname</></term>
1814        <listitem>
1815          <para>
1816           The name of the slot to stream changes from. This parameter is required,
1817           and must correspond to an existing logical replication slot created
1818           with <literal>CREATE_REPLICATION_SLOT</literal> in
1819           <literal>LOGICAL</literal> mode.
1820          </para>
1821        </listitem>
1822       </varlistentry>
1823       <varlistentry>
1824        <term><replaceable class="parameter">XXX/XXX</></term>
1825        <listitem>
1826         <para>
1827          The WAL position to begin streaming at.
1828         </para>
1829        </listitem>
1830       </varlistentry>
1831       <varlistentry>
1832        <term><replaceable class="parameter">option_name</></term>
1833        <listitem>
1834         <para>
1835          The name of an option passed to the slot's logical decoding plugin.
1836         </para>
1837        </listitem>
1838       </varlistentry>
1839       <varlistentry>
1840        <term><replaceable class="parameter">option_value</></term>
1841        <listitem>
1842         <para>
1843          Optional value, in the form of a string constant, associated with the
1844          specified option.
1845         </para>
1846        </listitem>
1847       </varlistentry>
1848      </variablelist>
1849     </listitem>
1850   </varlistentry>
1851
1852   <varlistentry>
1853     <term>DROP_REPLICATION_SLOT <replaceable class="parameter">slotname</></term>
1854     <listitem>
1855      <para>
1856       Drops a replication slot, freeing any reserved server-side resources. If
1857       the slot is currently in use by an active connection, this command fails.
1858      </para>
1859      <variablelist>
1860       <varlistentry>
1861        <term><replaceable class="parameter">slotname</></term>
1862        <listitem>
1863          <para>
1864           The name of the slot to drop.
1865          </para>
1866        </listitem>
1867       </varlistentry>
1868      </variablelist>
1869     </listitem>
1870   </varlistentry>
1871
1872   <varlistentry>
1873     <term>BASE_BACKUP [<literal>LABEL</literal> <replaceable>'label'</replaceable>] [<literal>PROGRESS</literal>] [<literal>FAST</literal>] [<literal>WAL</literal>] [<literal>NOWAIT</literal>] [<literal>MAX_RATE</literal> <replaceable>rate</replaceable>]</term>
1874     <listitem>
1875      <para>
1876       Instructs the server to start streaming a base backup.
1877       The system will automatically be put in backup mode before the backup
1878       is started, and taken out of it when the backup is complete. The
1879       following options are accepted:
1880       <variablelist>
1881        <varlistentry>
1882         <term><literal>LABEL</literal> <replaceable>'label'</replaceable></term>
1883         <listitem>
1884          <para>
1885           Sets the label of the backup. If none is specified, a backup label
1886           of <literal>base backup</literal> will be used. The quoting rules
1887           for the label are the same as a standard SQL string with
1888           <xref linkend="guc-standard-conforming-strings"> turned on.
1889          </para>
1890         </listitem>
1891        </varlistentry>
1892
1893        <varlistentry>
1894         <term><literal>PROGRESS</></term>
1895         <listitem>
1896          <para>
1897           Request information required to generate a progress report. This will
1898           send back an approximate size in the header of each tablespace, which
1899           can be used to calculate how far along the stream is done. This is
1900           calculated by enumerating all the file sizes once before the transfer
1901           is even started, and may as such have a negative impact on the
1902           performance - in particular it may take longer before the first data
1903           is streamed. Since the database files can change during the backup,
1904           the size is only approximate and may both grow and shrink between
1905           the time of approximation and the sending of the actual files.
1906          </para>
1907         </listitem>
1908        </varlistentry>
1909
1910        <varlistentry>
1911         <term><literal>FAST</></term>
1912         <listitem>
1913          <para>
1914           Request a fast checkpoint.
1915          </para>
1916         </listitem>
1917        </varlistentry>
1918
1919        <varlistentry>
1920         <term><literal>WAL</literal></term>
1921         <listitem>
1922          <para>
1923           Include the necessary WAL segments in the backup. This will include
1924           all the files between start and stop backup in the
1925           <filename>pg_xlog</filename> directory of the base directory tar
1926           file.
1927          </para>
1928         </listitem>
1929        </varlistentry>
1930
1931        <varlistentry>
1932         <term><literal>NOWAIT</literal></term>
1933         <listitem>
1934          <para>
1935           By default, the backup will wait until the last required xlog
1936           segment has been archived, or emit a warning if log archiving is
1937           not enabled. Specifying <literal>NOWAIT</literal> disables both
1938           the waiting and the warning, leaving the client responsible for
1939           ensuring the required log is available.
1940          </para>
1941         </listitem>
1942        </varlistentry>
1943
1944        <varlistentry>
1945         <term><literal>MAX_RATE</literal> <replaceable>rate</></term>
1946         <listitem>
1947          <para>
1948           Limit (throttle) the maximum amount of data transferred from server
1949           to client per unit of time.  The expected unit is kilobytes per second.
1950           If this option is specified, the value must either be equal to zero
1951           or it must fall within the range from 32 kB through 1 GB (inclusive).
1952           If zero is passed or the option is not specified, no restriction is
1953           imposed on the transfer.
1954          </para>
1955         </listitem>
1956        </varlistentry>
1957       </variablelist>
1958      </para>
1959      <para>
1960       When the backup is started, the server will first send two
1961       ordinary result sets, followed by one or more CopyResponse
1962       results.
1963      </para>
1964      <para>
1965       The first ordinary result set contains the starting position of the
1966       backup, in a single row with two columns. The first column contains
1967       the start position given in XLogRecPtr format, and the second column
1968       contains the corresponding timeline ID.
1969      </para>
1970      <para>
1971       The second ordinary result set has one row for each tablespace.
1972       The fields in this row are:
1973       <variablelist>
1974        <varlistentry>
1975         <term>spcoid</term>
1976         <listitem>
1977          <para>
1978           The oid of the tablespace, or <literal>NULL</> if it's the base
1979           directory.
1980          </para>
1981         </listitem>
1982        </varlistentry>
1983        <varlistentry>
1984         <term>spclocation</term>
1985         <listitem>
1986          <para>
1987           The full path of the tablespace directory, or <literal>NULL</>
1988           if it's the base directory.
1989          </para>
1990         </listitem>
1991        </varlistentry>
1992        <varlistentry>
1993         <term>size</term>
1994         <listitem>
1995          <para>
1996           The approximate size of the tablespace, if progress report has
1997           been requested; otherwise it's <literal>NULL</>.
1998          </para>
1999         </listitem>
2000        </varlistentry>
2001       </variablelist>
2002      </para>
2003      <para>
2004       After the second regular result set, one or more CopyResponse results
2005       will be sent, one for PGDATA and one for each additional tablespace other
2006       than <literal>pg_default</> and <literal>pg_global</>. The data in
2007       the CopyResponse results will be a tar format (following the
2008       <quote>ustar interchange format</> specified in the POSIX 1003.1-2008
2009       standard) dump of the tablespace contents, except that the two trailing
2010       blocks of zeroes specified in the standard are omitted.
2011       After the tar data is complete, a final ordinary result set will be sent,
2012       containing the WAL end position of the backup, in the same format as
2013       the start position.
2014      </para>
2015
2016      <para>
2017       The tar archive for the data directory and each tablespace will contain
2018       all files in the directories, regardless of whether they are
2019       <productname>PostgreSQL</> files or other files added to the same
2020       directory. The only excluded files are:
2021       <itemizedlist spacing="compact" mark="bullet">
2022        <listitem>
2023         <para>
2024          <filename>postmaster.pid</>
2025         </para>
2026        </listitem>
2027        <listitem>
2028         <para>
2029          <filename>postmaster.opts</>
2030         </para>
2031        </listitem>
2032        <listitem>
2033         <para>
2034          various temporary files created during the operation of the PostgreSQL server
2035         </para>
2036        </listitem>
2037        <listitem>
2038         <para>
2039          <filename>pg_xlog</>, including subdirectories. If the backup is run
2040          with WAL files included, a synthesized version of <filename>pg_xlog</filename> will be
2041          included, but it will only contain the files necessary for the
2042          backup to work, not the rest of the contents.
2043         </para>
2044        </listitem>
2045        <listitem>
2046         <para>
2047          <filename>pg_replslot</> is copied as an empty directory.
2048         </para>
2049        </listitem>
2050        <listitem>
2051         <para>
2052          Files other than regular files and directories, such as symbolic
2053          links and special device files, are skipped.  (Symbolic links
2054          in <filename>pg_tblspc</filename> are maintained.)
2055         </para>
2056        </listitem>
2057       </itemizedlist>
2058       Owner, group and file mode are set if the underlying file system on
2059       the server supports it.
2060      </para>
2061      <para>
2062       Once all tablespaces have been sent, a final regular result set will
2063       be sent. This result set contains the end position of the
2064       backup, given in XLogRecPtr format as a single column in a single row.
2065      </para>
2066     </listitem>
2067   </varlistentry>
2068 </variablelist>
2069
2070 </para>
2071
2072 </sect1>
2073
2074 <sect1 id="protocol-message-types">
2075 <title>Message Data Types</title>
2076
2077 <para>
2078 This section describes the base data types used in messages.
2079
2080 <variablelist>
2081
2082 <varlistentry>
2083 <term>
2084         Int<replaceable>n</replaceable>(<replaceable>i</replaceable>)
2085 </term>
2086 <listitem>
2087 <para>
2088                 An <replaceable>n</replaceable>-bit integer in network byte
2089                 order (most significant byte first).
2090                 If <replaceable>i</replaceable> is specified it
2091                 is the exact value that will appear, otherwise the value
2092                 is variable.  Eg. Int16, Int32(42).
2093 </para>
2094 </listitem>
2095 </varlistentry>
2096
2097 <varlistentry>
2098 <term>
2099         Int<replaceable>n</replaceable>[<replaceable>k</replaceable>]
2100 </term>
2101 <listitem>
2102 <para>
2103                 An array of <replaceable>k</replaceable>
2104                 <replaceable>n</replaceable>-bit integers, each in network
2105                 byte order.  The array length <replaceable>k</replaceable>
2106                 is always determined by an earlier field in the message.
2107                 Eg. Int16[M].
2108 </para>
2109 </listitem>
2110 </varlistentry>
2111
2112 <varlistentry>
2113 <term>
2114         String(<replaceable>s</replaceable>)
2115 </term>
2116 <listitem>
2117 <para>
2118                 A null-terminated string (C-style string).  There is no
2119                 specific length limitation on strings.
2120                 If <replaceable>s</replaceable> is specified it is the exact
2121                 value that will appear, otherwise the value is variable.
2122                 Eg. String, String("user").
2123 </para>
2124
2125 <note>
2126 <para>
2127 <emphasis>There is no predefined limit</emphasis> on the length of a string
2128 that can be returned by the backend.  Good coding strategy for a frontend
2129 is to use an expandable buffer so that anything that fits in memory can be
2130 accepted.  If that's not feasible, read the full string and discard trailing
2131 characters that don't fit into your fixed-size buffer.
2132 </para>
2133 </note>
2134 </listitem>
2135 </varlistentry>
2136
2137 <varlistentry>
2138 <term>
2139         Byte<replaceable>n</replaceable>(<replaceable>c</replaceable>)
2140 </term>
2141 <listitem>
2142 <para>
2143                 Exactly <replaceable>n</replaceable> bytes.  If the field
2144                 width <replaceable>n</replaceable> is not a constant, it is
2145                 always determinable from an earlier field in the message.
2146                 If <replaceable>c</replaceable> is specified it is the exact
2147                 value.  Eg. Byte2, Byte1('\n').
2148 </para>
2149 </listitem>
2150 </varlistentry>
2151
2152 </variablelist>
2153 </para>
2154 </sect1>
2155
2156 <sect1 id="protocol-message-formats">
2157 <title>Message Formats</title>
2158
2159 <para>
2160 This section describes the detailed format of each message.  Each is marked to
2161 indicate that it can be sent by a frontend (F), a backend (B), or both
2162 (F &amp; B).
2163 Notice that although each message includes a byte count at the beginning,
2164 the message format is defined so that the message end can be found without
2165 reference to the byte count.  This aids validity checking.  (The CopyData
2166 message is an exception, because it forms part of a data stream; the contents
2167 of any individual CopyData message cannot be interpretable on their own.)
2168 </para>
2169
2170 <variablelist>
2171
2172
2173 <varlistentry>
2174 <term>
2175 AuthenticationOk (B)
2176 </term>
2177 <listitem>
2178 <para>
2179
2180 <variablelist>
2181 <varlistentry>
2182 <term>
2183         Byte1('R')
2184 </term>
2185 <listitem>
2186 <para>
2187                 Identifies the message as an authentication request.
2188 </para>
2189 </listitem>
2190 </varlistentry>
2191 <varlistentry>
2192 <term>
2193         Int32(8)
2194 </term>
2195 <listitem>
2196 <para>
2197                 Length of message contents in bytes, including self.
2198 </para>
2199 </listitem>
2200 </varlistentry>
2201 <varlistentry>
2202 <term>
2203         Int32(0)
2204 </term>
2205 <listitem>
2206 <para>
2207                 Specifies that the authentication was successful.
2208 </para>
2209 </listitem>
2210 </varlistentry>
2211 </variablelist>
2212
2213 </para>
2214 </listitem>
2215 </varlistentry>
2216
2217
2218 <varlistentry>
2219 <term>
2220 AuthenticationKerberosV5 (B)
2221 </term>
2222 <listitem>
2223 <para>
2224
2225 <variablelist>
2226 <varlistentry>
2227 <term>
2228         Byte1('R')
2229 </term>
2230 <listitem>
2231 <para>
2232                 Identifies the message as an authentication request.
2233 </para>
2234 </listitem>
2235 </varlistentry>
2236 <varlistentry>
2237 <term>
2238         Int32(8)
2239 </term>
2240 <listitem>
2241 <para>
2242                 Length of message contents in bytes, including self.
2243 </para>
2244 </listitem>
2245 </varlistentry>
2246 <varlistentry>
2247 <term>
2248         Int32(2)
2249 </term>
2250 <listitem>
2251 <para>
2252                 Specifies that Kerberos V5 authentication is required.
2253 </para>
2254 </listitem>
2255 </varlistentry>
2256 </variablelist>
2257 </para>
2258 </listitem>
2259 </varlistentry>
2260
2261
2262 <varlistentry>
2263 <term>
2264 AuthenticationCleartextPassword (B)
2265 </term>
2266 <listitem>
2267 <para>
2268
2269 <variablelist>
2270 <varlistentry>
2271 <term>
2272         Byte1('R')
2273 </term>
2274 <listitem>
2275 <para>
2276                 Identifies the message as an authentication request.
2277 </para>
2278 </listitem>
2279 </varlistentry>
2280 <varlistentry>
2281 <term>
2282         Int32(8)
2283 </term>
2284 <listitem>
2285 <para>
2286                 Length of message contents in bytes, including self.
2287 </para>
2288 </listitem>
2289 </varlistentry>
2290 <varlistentry>
2291 <term>
2292         Int32(3)
2293 </term>
2294 <listitem>
2295 <para>
2296                 Specifies that a clear-text password is required.
2297 </para>
2298 </listitem>
2299 </varlistentry>
2300 </variablelist>
2301 </para>
2302 </listitem>
2303 </varlistentry>
2304
2305
2306 <varlistentry>
2307 <term>
2308 AuthenticationMD5Password (B)
2309 </term>
2310 <listitem>
2311 <para>
2312
2313 <variablelist>
2314 <varlistentry>
2315 <term>
2316         Byte1('R')
2317 </term>
2318 <listitem>
2319 <para>
2320                 Identifies the message as an authentication request.
2321 </para>
2322 </listitem>
2323 </varlistentry>
2324 <varlistentry>
2325 <term>
2326         Int32(12)
2327 </term>
2328 <listitem>
2329 <para>
2330                 Length of message contents in bytes, including self.
2331 </para>
2332 </listitem>
2333 </varlistentry>
2334 <varlistentry>
2335 <term>
2336         Int32(5)
2337 </term>
2338 <listitem>
2339 <para>
2340                 Specifies that an MD5-encrypted password is required.
2341 </para>
2342 </listitem>
2343 </varlistentry>
2344 <varlistentry>
2345 <term>
2346         Byte4
2347 </term>
2348 <listitem>
2349 <para>
2350                 The salt to use when encrypting the password.
2351 </para>
2352 </listitem>
2353 </varlistentry>
2354 </variablelist>
2355
2356 </para>
2357 </listitem>
2358 </varlistentry>
2359
2360
2361 <varlistentry>
2362 <term>
2363 AuthenticationSCMCredential (B)
2364 </term>
2365 <listitem>
2366 <para>
2367
2368 <variablelist>
2369 <varlistentry>
2370 <term>
2371         Byte1('R')
2372 </term>
2373 <listitem>
2374 <para>
2375                 Identifies the message as an authentication request.
2376 </para>
2377 </listitem>
2378 </varlistentry>
2379 <varlistentry>
2380 <term>
2381         Int32(8)
2382 </term>
2383 <listitem>
2384 <para>
2385                 Length of message contents in bytes, including self.
2386 </para>
2387 </listitem>
2388 </varlistentry>
2389 <varlistentry>
2390 <term>
2391         Int32(6)
2392 </term>
2393 <listitem>
2394 <para>
2395                 Specifies that an SCM credentials message is required.
2396 </para>
2397 </listitem>
2398 </varlistentry>
2399 </variablelist>
2400
2401 </para>
2402 </listitem>
2403 </varlistentry>
2404
2405
2406 <varlistentry>
2407 <term>
2408 AuthenticationGSS (B)
2409 </term>
2410 <listitem>
2411 <para>
2412
2413 <variablelist>
2414 <varlistentry>
2415 <term>
2416         Byte1('R')
2417 </term>
2418 <listitem>
2419 <para>
2420                 Identifies the message as an authentication request.
2421 </para>
2422 </listitem>
2423 </varlistentry>
2424 <varlistentry>
2425 <term>
2426         Int32(8)
2427 </term>
2428 <listitem>
2429 <para>
2430                 Length of message contents in bytes, including self.
2431 </para>
2432 </listitem>
2433 </varlistentry>
2434 <varlistentry>
2435 <term>
2436         Int32(7)
2437 </term>
2438 <listitem>
2439 <para>
2440                 Specifies that GSSAPI authentication is required.
2441 </para>
2442 </listitem>
2443 </varlistentry>
2444 </variablelist>
2445
2446 </para>
2447 </listitem>
2448 </varlistentry>
2449
2450
2451 <varlistentry>
2452 <term>
2453 AuthenticationSSPI (B)
2454 </term>
2455 <listitem>
2456 <para>
2457
2458 <variablelist>
2459 <varlistentry>
2460 <term>
2461         Byte1('R')
2462 </term>
2463 <listitem>
2464 <para>
2465                 Identifies the message as an authentication request.
2466 </para>
2467 </listitem>
2468 </varlistentry>
2469 <varlistentry>
2470 <term>
2471         Int32(8)
2472 </term>
2473 <listitem>
2474 <para>
2475                 Length of message contents in bytes, including self.
2476 </para>
2477 </listitem>
2478 </varlistentry>
2479 <varlistentry>
2480 <term>
2481         Int32(9)
2482 </term>
2483 <listitem>
2484 <para>
2485                 Specifies that SSPI authentication is required.
2486 </para>
2487 </listitem>
2488 </varlistentry>
2489 </variablelist>
2490
2491 </para>
2492 </listitem>
2493 </varlistentry>
2494 <varlistentry>
2495 <term>
2496 AuthenticationGSSContinue (B)
2497 </term>
2498 <listitem>
2499 <para>
2500
2501 <variablelist>
2502 <varlistentry>
2503 <term>
2504         Byte1('R')
2505 </term>
2506 <listitem>
2507 <para>
2508                 Identifies the message as an authentication request.
2509 </para>
2510 </listitem>
2511 </varlistentry>
2512 <varlistentry>
2513 <term>
2514         Int32
2515 </term>
2516 <listitem>
2517 <para>
2518                 Length of message contents in bytes, including self.
2519 </para>
2520 </listitem>
2521 </varlistentry>
2522 <varlistentry>
2523 <term>
2524         Int32(8)
2525 </term>
2526 <listitem>
2527 <para>
2528                 Specifies that this message contains GSSAPI or SSPI data.
2529 </para>
2530 </listitem>
2531 </varlistentry>
2532 <varlistentry>
2533 <term>
2534         Byte<replaceable>n</replaceable>
2535 </term>
2536 <listitem>
2537 <para>
2538                 GSSAPI or SSPI authentication data.
2539 </para>
2540 </listitem>
2541 </varlistentry>
2542 </variablelist>
2543
2544 </para>
2545 </listitem>
2546 </varlistentry>
2547
2548
2549 <varlistentry>
2550 <term>
2551 BackendKeyData (B)
2552 </term>
2553 <listitem>
2554 <para>
2555
2556 <variablelist>
2557 <varlistentry>
2558 <term>
2559         Byte1('K')
2560 </term>
2561 <listitem>
2562 <para>
2563                 Identifies the message as cancellation key data.
2564                 The frontend must save these values if it wishes to be
2565                 able to issue CancelRequest messages later.
2566 </para>
2567 </listitem>
2568 </varlistentry>
2569 <varlistentry>
2570 <term>
2571         Int32(12)
2572 </term>
2573 <listitem>
2574 <para>
2575                 Length of message contents in bytes, including self.
2576 </para>
2577 </listitem>
2578 </varlistentry>
2579 <varlistentry>
2580 <term>
2581         Int32
2582 </term>
2583 <listitem>
2584 <para>
2585                 The process ID of this backend.
2586 </para>
2587 </listitem>
2588 </varlistentry>
2589 <varlistentry>
2590 <term>
2591         Int32
2592 </term>
2593 <listitem>
2594 <para>
2595                 The secret key of this backend.
2596 </para>
2597 </listitem>
2598 </varlistentry>
2599 </variablelist>
2600
2601 </para>
2602 </listitem>
2603 </varlistentry>
2604
2605
2606 <varlistentry>
2607 <term>
2608 Bind (F)
2609 </term>
2610 <listitem>
2611 <para>
2612
2613 <variablelist>
2614 <varlistentry>
2615 <term>
2616         Byte1('B')
2617 </term>
2618 <listitem>
2619 <para>
2620                 Identifies the message as a Bind command.
2621 </para>
2622 </listitem>
2623 </varlistentry>
2624 <varlistentry>
2625 <term>
2626         Int32
2627 </term>
2628 <listitem>
2629 <para>
2630                 Length of message contents in bytes, including self.
2631 </para>
2632 </listitem>
2633 </varlistentry>
2634 <varlistentry>
2635 <term>
2636         String
2637 </term>
2638 <listitem>
2639 <para>
2640                 The name of the destination portal
2641                 (an empty string selects the unnamed portal).
2642 </para>
2643 </listitem>
2644 </varlistentry>
2645 <varlistentry>
2646 <term>
2647         String
2648 </term>
2649 <listitem>
2650 <para>
2651                 The name of the source prepared statement
2652                 (an empty string selects the unnamed prepared statement).
2653 </para>
2654 </listitem>
2655 </varlistentry>
2656 <varlistentry>
2657 <term>
2658         Int16
2659 </term>
2660 <listitem>
2661 <para>
2662                 The number of parameter format codes that follow
2663                 (denoted <replaceable>C</> below).
2664                 This can be zero to indicate that there are no parameters
2665                 or that the parameters all use the default format (text);
2666                 or one, in which case the specified format code is applied
2667                 to all parameters; or it can equal the actual number of
2668                 parameters.
2669 </para>
2670 </listitem>
2671 </varlistentry>
2672 <varlistentry>
2673 <term>
2674         Int16[<replaceable>C</>]
2675 </term>
2676 <listitem>
2677 <para>
2678                 The parameter format codes.  Each must presently be
2679                 zero (text) or one (binary).
2680 </para>
2681 </listitem>
2682 </varlistentry>
2683 <varlistentry>
2684 <term>
2685         Int16
2686 </term>
2687 <listitem>
2688 <para>
2689                 The number of parameter values that follow (possibly zero).
2690                 This must match the number of parameters needed by the query.
2691 </para>
2692 </listitem>
2693 </varlistentry>
2694 </variablelist>
2695         Next, the following pair of fields appear for each parameter:
2696 <variablelist>
2697 <varlistentry>
2698 <term>
2699         Int32
2700 </term>
2701 <listitem>
2702 <para>
2703                 The length of the parameter value, in bytes (this count
2704                 does not include itself).  Can be zero.
2705                 As a special case, -1 indicates a NULL parameter value.
2706                 No value bytes follow in the NULL case.
2707 </para>
2708 </listitem>
2709 </varlistentry>
2710 <varlistentry>
2711 <term>
2712         Byte<replaceable>n</replaceable>
2713 </term>
2714 <listitem>
2715 <para>
2716                 The value of the parameter, in the format indicated by the
2717                 associated format code.
2718                 <replaceable>n</replaceable> is the above length.
2719 </para>
2720 </listitem>
2721 </varlistentry>
2722 </variablelist>
2723         After the last parameter, the following fields appear:
2724 <variablelist>
2725 <varlistentry>
2726 <term>
2727         Int16
2728 </term>
2729 <listitem>
2730 <para>
2731                 The number of result-column format codes that follow
2732                 (denoted <replaceable>R</> below).
2733                 This can be zero to indicate that there are no result columns
2734                 or that the result columns should all use the default format
2735                 (text);
2736                 or one, in which case the specified format code is applied
2737                 to all result columns (if any); or it can equal the actual
2738                 number of result columns of the query.
2739 </para>
2740 </listitem>
2741 </varlistentry>
2742 <varlistentry>
2743 <term>
2744         Int16[<replaceable>R</>]
2745 </term>
2746 <listitem>
2747 <para>
2748                 The result-column format codes.  Each must presently be
2749                 zero (text) or one (binary).
2750 </para>
2751 </listitem>
2752 </varlistentry>
2753 </variablelist>
2754 </para>
2755 </listitem>
2756 </varlistentry>
2757
2758
2759 <varlistentry>
2760 <term>
2761 BindComplete (B)
2762 </term>
2763 <listitem>
2764 <para>
2765
2766 <variablelist>
2767 <varlistentry>
2768 <term>
2769         Byte1('2')
2770 </term>
2771 <listitem>
2772 <para>
2773                 Identifies the message as a Bind-complete indicator.
2774 </para>
2775 </listitem>
2776 </varlistentry>
2777 <varlistentry>
2778 <term>
2779         Int32(4)
2780 </term>
2781 <listitem>
2782 <para>
2783                 Length of message contents in bytes, including self.
2784 </para>
2785 </listitem>
2786 </varlistentry>
2787 </variablelist>
2788
2789 </para>
2790 </listitem>
2791 </varlistentry>
2792
2793
2794 <varlistentry>
2795 <term>
2796 CancelRequest (F)
2797 </term>
2798 <listitem>
2799 <para>
2800
2801 <variablelist>
2802 <varlistentry>
2803 <term>
2804         Int32(16)
2805 </term>
2806 <listitem>
2807 <para>
2808                 Length of message contents in bytes, including self.
2809 </para>
2810 </listitem>
2811 </varlistentry>
2812 <varlistentry>
2813 <term>
2814         Int32(80877102)
2815 </term>
2816 <listitem>
2817 <para>
2818                 The cancel request code.  The value is chosen to contain
2819                 <literal>1234</> in the most significant 16 bits, and <literal>5678</> in the
2820                 least 16 significant bits.  (To avoid confusion, this code
2821                 must not be the same as any protocol version number.)
2822 </para>
2823 </listitem>
2824 </varlistentry>
2825 <varlistentry>
2826 <term>
2827         Int32
2828 </term>
2829 <listitem>
2830 <para>
2831                 The process ID of the target backend.
2832 </para>
2833 </listitem>
2834 </varlistentry>
2835 <varlistentry>
2836 <term>
2837         Int32
2838 </term>
2839 <listitem>
2840 <para>
2841                 The secret key for the target backend.
2842 </para>
2843 </listitem>
2844 </varlistentry>
2845 </variablelist>
2846
2847 </para>
2848 </listitem>
2849 </varlistentry>
2850
2851
2852 <varlistentry>
2853 <term>
2854 Close (F)
2855 </term>
2856 <listitem>
2857 <para>
2858
2859 <variablelist>
2860 <varlistentry>
2861 <term>
2862         Byte1('C')
2863 </term>
2864 <listitem>
2865 <para>
2866                 Identifies the message as a Close command.
2867 </para>
2868 </listitem>
2869 </varlistentry>
2870 <varlistentry>
2871 <term>
2872         Int32
2873 </term>
2874 <listitem>
2875 <para>
2876                 Length of message contents in bytes, including self.
2877 </para>
2878 </listitem>
2879 </varlistentry>
2880 <varlistentry>
2881 <term>
2882         Byte1
2883 </term>
2884 <listitem>
2885 <para>
2886                 '<literal>S</>' to close a prepared statement; or
2887                 '<literal>P</>' to close a portal.
2888 </para>
2889 </listitem>
2890 </varlistentry>
2891 <varlistentry>
2892 <term>
2893         String
2894 </term>
2895 <listitem>
2896 <para>
2897                 The name of the prepared statement or portal to close
2898                 (an empty string selects the unnamed prepared statement
2899                 or portal).
2900 </para>
2901 </listitem>
2902 </varlistentry>
2903 </variablelist>
2904 </para>
2905 </listitem>
2906 </varlistentry>
2907
2908
2909 <varlistentry>
2910 <term>
2911 CloseComplete (B)
2912 </term>
2913 <listitem>
2914 <para>
2915
2916 <variablelist>
2917 <varlistentry>
2918 <term>
2919         Byte1('3')
2920 </term>
2921 <listitem>
2922 <para>
2923                 Identifies the message as a Close-complete indicator.
2924 </para>
2925 </listitem>
2926 </varlistentry>
2927 <varlistentry>
2928 <term>
2929         Int32(4)
2930 </term>
2931 <listitem>
2932 <para>
2933                 Length of message contents in bytes, including self.
2934 </para>
2935 </listitem>
2936 </varlistentry>
2937 </variablelist>
2938
2939 </para>
2940 </listitem>
2941 </varlistentry>
2942
2943
2944 <varlistentry>
2945 <term>
2946 CommandComplete (B)
2947 </term>
2948 <listitem>
2949 <para>
2950
2951 <variablelist>
2952 <varlistentry>
2953 <term>
2954         Byte1('C')
2955 </term>
2956 <listitem>
2957 <para>
2958                 Identifies the message as a command-completed response.
2959 </para>
2960 </listitem>
2961 </varlistentry>
2962 <varlistentry>
2963 <term>
2964         Int32
2965 </term>
2966 <listitem>
2967 <para>
2968                 Length of message contents in bytes, including self.
2969 </para>
2970 </listitem>
2971 </varlistentry>
2972 <varlistentry>
2973 <term>
2974         String
2975 </term>
2976 <listitem>
2977        <para>
2978         The command tag.  This is usually a single
2979         word that identifies which SQL command was completed.
2980        </para>
2981
2982        <para>
2983         For an <command>INSERT</command> command, the tag is
2984         <literal>INSERT <replaceable>oid</replaceable>
2985         <replaceable>rows</replaceable></literal>, where
2986         <replaceable>rows</replaceable> is the number of rows
2987         inserted. <replaceable>oid</replaceable> is the object ID
2988         of the inserted row if <replaceable>rows</replaceable> is 1
2989         and the target table has OIDs;
2990         otherwise <replaceable>oid</replaceable> is 0.
2991        </para>
2992
2993        <para>
2994         For a <command>DELETE</command> command, the tag is
2995         <literal>DELETE <replaceable>rows</replaceable></literal> where
2996         <replaceable>rows</replaceable> is the number of rows deleted.
2997        </para>
2998
2999        <para>
3000         For an <command>UPDATE</command> command, the tag is
3001         <literal>UPDATE <replaceable>rows</replaceable></literal> where
3002         <replaceable>rows</replaceable> is the number of rows updated.
3003        </para>
3004
3005        <para>
3006         For a <command>SELECT</command> or <command>CREATE TABLE AS</command>
3007         command, the tag is <literal>SELECT <replaceable>rows</replaceable></literal>
3008         where <replaceable>rows</replaceable> is the number of rows retrieved.
3009        </para>
3010
3011        <para>
3012         For a <command>MOVE</command> command, the tag is
3013         <literal>MOVE <replaceable>rows</replaceable></literal> where
3014         <replaceable>rows</replaceable> is the number of rows the
3015         cursor's position has been changed by.
3016        </para>
3017
3018        <para>
3019         For a <command>FETCH</command> command, the tag is
3020         <literal>FETCH <replaceable>rows</replaceable></literal> where
3021         <replaceable>rows</replaceable> is the number of rows that
3022         have been retrieved from the cursor.
3023        </para>
3024
3025        <para>
3026         For a <command>COPY</command> command, the tag is
3027         <literal>COPY <replaceable>rows</replaceable></literal> where
3028         <replaceable>rows</replaceable> is the number of rows copied.
3029         (Note: the row count appears only in
3030         <productname>PostgreSQL</productname> 8.2 and later.)
3031        </para>
3032
3033 </listitem>
3034 </varlistentry>
3035 </variablelist>
3036
3037 </para>
3038 </listitem>
3039 </varlistentry>
3040
3041
3042 <varlistentry>
3043 <term>
3044 CopyData (F &amp; B)
3045 </term>
3046 <listitem>
3047 <para>
3048 <variablelist>
3049 <varlistentry>
3050 <term>
3051         Byte1('d')
3052 </term>
3053 <listitem>
3054 <para>
3055                 Identifies the message as <command>COPY</command> data.
3056 </para>
3057 </listitem>
3058 </varlistentry>
3059 <varlistentry>
3060 <term>
3061         Int32
3062 </term>
3063 <listitem>
3064 <para>
3065                 Length of message contents in bytes, including self.
3066 </para>
3067 </listitem>
3068 </varlistentry>
3069 <varlistentry>
3070 <term>
3071         Byte<replaceable>n</replaceable>
3072 </term>
3073 <listitem>
3074 <para>
3075                 Data that forms part of a <command>COPY</command> data stream.  Messages sent
3076                 from the backend will always correspond to single data rows,
3077                 but messages sent by frontends might divide the data stream
3078                 arbitrarily.
3079 </para>
3080 </listitem>
3081 </varlistentry>
3082 </variablelist>
3083 </para>
3084 </listitem>
3085 </varlistentry>
3086
3087
3088 <varlistentry>
3089 <term>
3090 CopyDone (F &amp; B)
3091 </term>
3092 <listitem>
3093 <para>
3094
3095 <variablelist>
3096 <varlistentry>
3097 <term>
3098         Byte1('c')
3099 </term>
3100 <listitem>
3101 <para>
3102                 Identifies the message as a <command>COPY</command>-complete indicator.
3103 </para>
3104 </listitem>
3105 </varlistentry>
3106 <varlistentry>
3107 <term>
3108         Int32(4)
3109 </term>
3110 <listitem>
3111 <para>
3112                 Length of message contents in bytes, including self.
3113 </para>
3114 </listitem>
3115 </varlistentry>
3116 </variablelist>
3117
3118 </para>
3119 </listitem>
3120 </varlistentry>
3121
3122
3123 <varlistentry>
3124 <term>
3125 CopyFail (F)
3126 </term>
3127 <listitem>
3128 <para>
3129
3130 <variablelist>
3131 <varlistentry>
3132 <term>
3133         Byte1('f')
3134 </term>
3135 <listitem>
3136 <para>
3137                 Identifies the message as a <command>COPY</command>-failure indicator.
3138 </para>
3139 </listitem>
3140 </varlistentry>
3141 <varlistentry>
3142 <term>
3143         Int32
3144 </term>
3145 <listitem>
3146 <para>
3147                 Length of message contents in bytes, including self.
3148 </para>
3149 </listitem>
3150 </varlistentry>
3151 <varlistentry>
3152 <term>
3153         String
3154 </term>
3155 <listitem>
3156 <para>
3157                 An error message to report as the cause of failure.
3158 </para>
3159 </listitem>
3160 </varlistentry>
3161 </variablelist>
3162
3163 </para>
3164 </listitem>
3165 </varlistentry>
3166
3167
3168 <varlistentry>
3169 <term>
3170 CopyInResponse (B)
3171 </term>
3172 <listitem>
3173 <para>
3174
3175 <variablelist>
3176 <varlistentry>
3177 <term>
3178         Byte1('G')
3179 </term>
3180 <listitem>
3181 <para>
3182                 Identifies the message as a Start Copy In response.
3183                 The frontend must now send copy-in data (if not
3184                 prepared to do so, send a CopyFail message).
3185 </para>
3186 </listitem>
3187 </varlistentry>
3188 <varlistentry>
3189 <term>
3190         Int32
3191 </term>
3192 <listitem>
3193 <para>
3194                 Length of message contents in bytes, including self.
3195 </para>
3196 </listitem>
3197 </varlistentry>
3198 <varlistentry>
3199 <term>
3200         Int8
3201 </term>
3202 <listitem>
3203 <para>
3204                 0 indicates the overall <command>COPY</command> format is textual (rows
3205                 separated by newlines, columns separated by separator
3206                 characters, etc).
3207                 1 indicates the overall copy format is binary (similar
3208                 to DataRow format).
3209                 See <xref linkend="sql-copy">
3210                 for more information.
3211 </para>
3212 </listitem>
3213 </varlistentry>
3214 <varlistentry>
3215 <term>
3216         Int16
3217 </term>
3218 <listitem>
3219 <para>
3220                 The number of columns in the data to be copied
3221                 (denoted <replaceable>N</> below).
3222 </para>
3223 </listitem>
3224 </varlistentry>
3225 <varlistentry>
3226 <term>
3227         Int16[<replaceable>N</>]
3228 </term>
3229 <listitem>
3230 <para>
3231                 The format codes to be used for each column.
3232                 Each must presently be zero (text) or one (binary).
3233                 All must be zero if the overall copy format is textual.
3234 </para>
3235 </listitem>
3236 </varlistentry>
3237 </variablelist>
3238
3239 </para>
3240 </listitem>
3241 </varlistentry>
3242
3243
3244 <varlistentry>
3245 <term>
3246 CopyOutResponse (B)
3247 </term>
3248 <listitem>
3249 <para>
3250
3251 <variablelist>
3252 <varlistentry>
3253 <term>
3254         Byte1('H')
3255 </term>
3256 <listitem>
3257 <para>
3258                 Identifies the message as a Start Copy Out response.
3259                 This message will be followed by copy-out data.
3260 </para>
3261 </listitem>
3262 </varlistentry>
3263 <varlistentry>
3264 <term>
3265         Int32
3266 </term>
3267 <listitem>
3268 <para>
3269                 Length of message contents in bytes, including self.
3270 </para>
3271 </listitem>
3272 </varlistentry>
3273 <varlistentry>
3274 <term>
3275         Int8
3276 </term>
3277 <listitem>
3278 <para>
3279                 0 indicates the overall <command>COPY</command> format
3280                 is textual (rows separated by newlines, columns
3281                 separated by separator characters, etc). 1 indicates
3282                 the overall copy format is binary (similar to DataRow
3283                 format). See <xref linkend="sql-copy"> for more information.
3284 </para>
3285 </listitem>
3286 </varlistentry>
3287 <varlistentry>
3288 <term>
3289         Int16
3290 </term>
3291 <listitem>
3292 <para>
3293                 The number of columns in the data to be copied
3294                 (denoted <replaceable>N</> below).
3295 </para>
3296 </listitem>
3297 </varlistentry>
3298 <varlistentry>
3299 <term>
3300         Int16[<replaceable>N</>]
3301 </term>
3302 <listitem>
3303 <para>
3304                 The format codes to be used for each column.
3305                 Each must presently be zero (text) or one (binary).
3306                 All must be zero if the overall copy format is textual.
3307 </para>
3308 </listitem>
3309 </varlistentry>
3310 </variablelist>
3311
3312 </para>
3313 </listitem>
3314 </varlistentry>
3315
3316
3317 <varlistentry>
3318 <term>
3319 CopyBothResponse (B)
3320 </term>
3321 <listitem>
3322 <para>
3323
3324 <variablelist>
3325 <varlistentry>
3326 <term>
3327         Byte1('W')
3328 </term>
3329 <listitem>
3330 <para>
3331                 Identifies the message as a Start Copy Both response.
3332                 This message is used only for Streaming Replication.
3333 </para>
3334 </listitem>
3335 </varlistentry>
3336 <varlistentry>
3337 <term>
3338         Int32
3339 </term>
3340 <listitem>
3341 <para>
3342                 Length of message contents in bytes, including self.
3343 </para>
3344 </listitem>
3345 </varlistentry>
3346 <varlistentry>
3347 <term>
3348         Int8
3349 </term>
3350 <listitem>
3351 <para>
3352                 0 indicates the overall <command>COPY</command> format
3353                 is textual (rows separated by newlines, columns
3354                 separated by separator characters, etc). 1 indicates
3355                 the overall copy format is binary (similar to DataRow
3356                 format). See <xref linkend="sql-copy"> for more information.
3357 </para>
3358 </listitem>
3359 </varlistentry>
3360 <varlistentry>
3361 <term>
3362         Int16
3363 </term>
3364 <listitem>
3365 <para>
3366                 The number of columns in the data to be copied
3367                 (denoted <replaceable>N</> below).
3368 </para>
3369 </listitem>
3370 </varlistentry>
3371 <varlistentry>
3372 <term>
3373         Int16[<replaceable>N</>]
3374 </term>
3375 <listitem>
3376 <para>
3377                 The format codes to be used for each column.
3378                 Each must presently be zero (text) or one (binary).
3379                 All must be zero if the overall copy format is textual.
3380 </para>
3381 </listitem>
3382 </varlistentry>
3383 </variablelist>
3384
3385 </para>
3386 </listitem>
3387 </varlistentry>
3388
3389
3390 <varlistentry>
3391 <term>
3392 DataRow (B)
3393 </term>
3394 <listitem>
3395 <para>
3396 <variablelist>
3397 <varlistentry>
3398 <term>
3399         Byte1('D')
3400 </term>
3401 <listitem>
3402 <para>
3403                 Identifies the message as a data row.
3404 </para>
3405 </listitem>
3406 </varlistentry>
3407 <varlistentry>
3408 <term>
3409         Int32
3410 </term>
3411 <listitem>
3412 <para>
3413                 Length of message contents in bytes, including self.
3414 </para>
3415 </listitem>
3416 </varlistentry>
3417 <varlistentry>
3418 <term>
3419         Int16
3420 </term>
3421 <listitem>
3422 <para>
3423                 The number of column values that follow (possibly zero).
3424 </para>
3425 </listitem>
3426 </varlistentry>
3427 </variablelist>
3428         Next, the following pair of fields appear for each column:
3429 <variablelist>
3430 <varlistentry>
3431 <term>
3432         Int32
3433 </term>
3434 <listitem>
3435 <para>
3436                 The length of the column value, in bytes (this count
3437                 does not include itself).  Can be zero.
3438                 As a special case, -1 indicates a NULL column value.
3439                 No value bytes follow in the NULL case.
3440 </para>
3441 </listitem>
3442 </varlistentry>
3443 <varlistentry>
3444 <term>
3445         Byte<replaceable>n</replaceable>
3446 </term>
3447 <listitem>
3448 <para>
3449                 The value of the column, in the format indicated by the
3450                 associated format code.
3451                 <replaceable>n</replaceable> is the above length.
3452 </para>
3453 </listitem>
3454 </varlistentry>
3455 </variablelist>
3456
3457 </para>
3458 </listitem>
3459 </varlistentry>
3460
3461
3462 <varlistentry>
3463 <term>
3464 Describe (F)
3465 </term>
3466 <listitem>
3467 <para>
3468
3469 <variablelist>
3470 <varlistentry>
3471 <term>
3472         Byte1('D')
3473 </term>
3474 <listitem>
3475 <para>
3476                 Identifies the message as a Describe command.
3477 </para>
3478 </listitem>
3479 </varlistentry>
3480 <varlistentry>
3481 <term>
3482         Int32
3483 </term>
3484 <listitem>
3485 <para>
3486                 Length of message contents in bytes, including self.
3487 </para>
3488 </listitem>
3489 </varlistentry>
3490 <varlistentry>
3491 <term>
3492         Byte1
3493 </term>
3494 <listitem>
3495 <para>
3496                 '<literal>S</>' to describe a prepared statement; or
3497                 '<literal>P</>' to describe a portal.
3498 </para>
3499 </listitem>
3500 </varlistentry>
3501 <varlistentry>
3502 <term>
3503         String
3504 </term>
3505 <listitem>
3506 <para>
3507                 The name of the prepared statement or portal to describe
3508                 (an empty string selects the unnamed prepared statement
3509                 or portal).
3510 </para>
3511 </listitem>
3512 </varlistentry>
3513 </variablelist>
3514 </para>
3515 </listitem>
3516 </varlistentry>
3517
3518
3519 <varlistentry>
3520 <term>
3521 EmptyQueryResponse (B)
3522 </term>
3523 <listitem>
3524 <para>
3525
3526 <variablelist>
3527 <varlistentry>
3528 <term>
3529         Byte1('I')
3530 </term>
3531 <listitem>
3532 <para>
3533                 Identifies the message as a response to an empty query string.
3534                 (This substitutes for CommandComplete.)
3535 </para>
3536 </listitem>
3537 </varlistentry>
3538 <varlistentry>
3539 <term>
3540         Int32(4)
3541 </term>
3542 <listitem>
3543 <para>
3544                 Length of message contents in bytes, including self.
3545 </para>
3546 </listitem>
3547 </varlistentry>
3548 </variablelist>
3549
3550 </para>
3551 </listitem>
3552 </varlistentry>
3553
3554
3555 <varlistentry>
3556 <term>
3557 ErrorResponse (B)
3558 </term>
3559 <listitem>
3560 <para>
3561
3562 <variablelist>
3563 <varlistentry>
3564 <term>
3565         Byte1('E')
3566 </term>
3567 <listitem>
3568 <para>
3569                 Identifies the message as an error.
3570 </para>
3571 </listitem>
3572 </varlistentry>
3573 <varlistentry>
3574 <term>
3575         Int32
3576 </term>
3577 <listitem>
3578 <para>
3579                 Length of message contents in bytes, including self.
3580 </para>
3581 </listitem>
3582 </varlistentry>
3583 </variablelist>
3584         The message body consists of one or more identified fields,
3585         followed by a zero byte as a terminator.  Fields can appear in
3586         any order.  For each field there is the following:
3587 <variablelist>
3588 <varlistentry>
3589 <term>
3590         Byte1
3591 </term>
3592 <listitem>
3593 <para>
3594                 A code identifying the field type; if zero, this is
3595                 the message terminator and no string follows.
3596                 The presently defined field types are listed in
3597                 <xref linkend="protocol-error-fields">.
3598                 Since more field types might be added in future,
3599                 frontends should silently ignore fields of unrecognized
3600                 type.
3601 </para>
3602 </listitem>
3603 </varlistentry>
3604 <varlistentry>
3605 <term>
3606         String
3607 </term>
3608 <listitem>
3609 <para>
3610                 The field value.
3611 </para>
3612 </listitem>
3613 </varlistentry>
3614 </variablelist>
3615
3616 </para>
3617 </listitem>
3618 </varlistentry>
3619
3620
3621 <varlistentry>
3622 <term>
3623 Execute (F)
3624 </term>
3625 <listitem>
3626 <para>
3627
3628 <variablelist>
3629 <varlistentry>
3630 <term>
3631         Byte1('E')
3632 </term>
3633 <listitem>
3634 <para>
3635                 Identifies the message as an Execute command.
3636 </para>
3637 </listitem>
3638 </varlistentry>
3639 <varlistentry>
3640 <term>
3641         Int32
3642 </term>
3643 <listitem>
3644 <para>
3645                 Length of message contents in bytes, including self.
3646 </para>
3647 </listitem>
3648 </varlistentry>
3649 <varlistentry>
3650 <term>
3651         String
3652 </term>
3653 <listitem>
3654 <para>
3655                 The name of the portal to execute
3656                 (an empty string selects the unnamed portal).
3657 </para>
3658 </listitem>
3659 </varlistentry>
3660 <varlistentry>
3661 <term>
3662         Int32
3663 </term>
3664 <listitem>
3665 <para>
3666                 Maximum number of rows to return, if portal contains
3667                 a query that returns rows (ignored otherwise).  Zero
3668                 denotes <quote>no limit</>.
3669 </para>
3670 </listitem>
3671 </varlistentry>
3672 </variablelist>
3673 </para>
3674 </listitem>
3675 </varlistentry>
3676
3677
3678 <varlistentry>
3679 <term>
3680 Flush (F)
3681 </term>
3682 <listitem>
3683 <para>
3684
3685 <variablelist>
3686 <varlistentry>
3687 <term>
3688         Byte1('H')
3689 </term>
3690 <listitem>
3691 <para>
3692                 Identifies the message as a Flush command.
3693 </para>
3694 </listitem>
3695 </varlistentry>
3696 <varlistentry>
3697 <term>
3698         Int32(4)
3699 </term>
3700 <listitem>
3701 <para>
3702                 Length of message contents in bytes, including self.
3703 </para>
3704 </listitem>
3705 </varlistentry>
3706 </variablelist>
3707
3708 </para>
3709 </listitem>
3710 </varlistentry>
3711
3712
3713 <varlistentry>
3714 <term>
3715 FunctionCall (F)
3716 </term>
3717 <listitem>
3718 <para>
3719
3720 <variablelist>
3721 <varlistentry>
3722 <term>
3723         Byte1('F')
3724 </term>
3725 <listitem>
3726 <para>
3727                 Identifies the message as a function call.
3728 </para>
3729 </listitem>
3730 </varlistentry>
3731 <varlistentry>
3732 <term>
3733         Int32
3734 </term>
3735 <listitem>
3736 <para>
3737                 Length of message contents in bytes, including self.
3738 </para>
3739 </listitem>
3740 </varlistentry>
3741 <varlistentry>
3742 <term>
3743         Int32
3744 </term>
3745 <listitem>
3746 <para>
3747                 Specifies the object ID of the function to call.
3748 </para>
3749 </listitem>
3750 </varlistentry>
3751 <varlistentry>
3752 <term>
3753         Int16
3754 </term>
3755 <listitem>
3756 <para>
3757                 The number of argument format codes that follow
3758                 (denoted <replaceable>C</> below).
3759                 This can be zero to indicate that there are no arguments
3760                 or that the arguments all use the default format (text);
3761                 or one, in which case the specified format code is applied
3762                 to all arguments; or it can equal the actual number of
3763                 arguments.
3764 </para>
3765 </listitem>
3766 </varlistentry>
3767 <varlistentry>
3768 <term>
3769         Int16[<replaceable>C</>]
3770 </term>
3771 <listitem>
3772 <para>
3773                 The argument format codes.  Each must presently be
3774                 zero (text) or one (binary).
3775 </para>
3776 </listitem>
3777 </varlistentry>
3778 <varlistentry>
3779 <term>
3780         Int16
3781 </term>
3782 <listitem>
3783 <para>
3784                 Specifies the number of arguments being supplied to the
3785                 function.
3786 </para>
3787 </listitem>
3788 </varlistentry>
3789 </variablelist>
3790         Next, the following pair of fields appear for each argument:
3791 <variablelist>
3792 <varlistentry>
3793 <term>
3794         Int32
3795 </term>
3796 <listitem>
3797 <para>
3798                 The length of the argument value, in bytes (this count
3799                 does not include itself).  Can be zero.
3800                 As a special case, -1 indicates a NULL argument value.
3801                 No value bytes follow in the NULL case.
3802 </para>
3803 </listitem>
3804 </varlistentry>
3805 <varlistentry>
3806 <term>
3807         Byte<replaceable>n</replaceable>
3808 </term>
3809 <listitem>
3810 <para>
3811                 The value of the argument, in the format indicated by the
3812                 associated format code.
3813                 <replaceable>n</replaceable> is the above length.
3814 </para>
3815 </listitem>
3816 </varlistentry>
3817 </variablelist>
3818         After the last argument, the following field appears:
3819 <variablelist>
3820 <varlistentry>
3821 <term>
3822         Int16
3823 </term>
3824 <listitem>
3825 <para>
3826                 The format code for the function result. Must presently be
3827                 zero (text) or one (binary).
3828 </para>
3829 </listitem>
3830 </varlistentry>
3831 </variablelist>
3832
3833 </para>
3834 </listitem>
3835 </varlistentry>
3836
3837
3838 <varlistentry>
3839 <term>
3840 FunctionCallResponse (B)
3841 </term>
3842 <listitem>
3843 <para>
3844
3845 <variablelist>
3846 <varlistentry>
3847 <term>
3848         Byte1('V')
3849 </term>
3850 <listitem>
3851 <para>
3852                 Identifies the message as a function call result.
3853 </para>
3854 </listitem>
3855 </varlistentry>
3856 <varlistentry>
3857 <term>
3858         Int32
3859 </term>
3860 <listitem>
3861 <para>
3862                 Length of message contents in bytes, including self.
3863 </para>
3864 </listitem>
3865 </varlistentry>
3866 <varlistentry>
3867 <term>
3868         Int32
3869 </term>
3870 <listitem>
3871 <para>
3872                 The length of the function result value, in bytes (this count
3873                 does not include itself).  Can be zero.
3874                 As a special case, -1 indicates a NULL function result.
3875                 No value bytes follow in the NULL case.
3876 </para>
3877 </listitem>
3878 </varlistentry>
3879 <varlistentry>
3880 <term>
3881         Byte<replaceable>n</replaceable>
3882 </term>
3883 <listitem>
3884 <para>
3885                 The value of the function result, in the format indicated by
3886                 the associated format code.
3887                 <replaceable>n</replaceable> is the above length.
3888 </para>
3889 </listitem>
3890 </varlistentry>
3891 </variablelist>
3892
3893 </para>
3894 </listitem>
3895 </varlistentry>
3896
3897
3898 <varlistentry>
3899 <term>
3900 NoData (B)
3901 </term>
3902 <listitem>
3903 <para>
3904
3905 <variablelist>
3906 <varlistentry>
3907 <term>
3908         Byte1('n')
3909 </term>
3910 <listitem>
3911 <para>
3912                 Identifies the message as a no-data indicator.
3913 </para>
3914 </listitem>
3915 </varlistentry>
3916 <varlistentry>
3917 <term>
3918         Int32(4)
3919 </term>
3920 <listitem>
3921 <para>
3922                 Length of message contents in bytes, including self.
3923 </para>
3924 </listitem>
3925 </varlistentry>
3926 </variablelist>
3927
3928 </para>
3929 </listitem>
3930 </varlistentry>
3931
3932
3933 <varlistentry>
3934 <term>
3935 NoticeResponse (B)
3936 </term>
3937 <listitem>
3938 <para>
3939
3940 <variablelist>
3941 <varlistentry>
3942 <term>
3943         Byte1('N')
3944 </term>
3945 <listitem>
3946 <para>
3947                 Identifies the message as a notice.
3948 </para>
3949 </listitem>
3950 </varlistentry>
3951 <varlistentry>
3952 <term>
3953         Int32
3954 </term>
3955 <listitem>
3956 <para>
3957                 Length of message contents in bytes, including self.
3958 </para>
3959 </listitem>
3960 </varlistentry>
3961 </variablelist>
3962         The message body consists of one or more identified fields,
3963         followed by a zero byte as a terminator.  Fields can appear in
3964         any order.  For each field there is the following:
3965 <variablelist>
3966 <varlistentry>
3967 <term>
3968         Byte1
3969 </term>
3970 <listitem>
3971 <para>
3972                 A code identifying the field type; if zero, this is
3973                 the message terminator and no string follows.
3974                 The presently defined field types are listed in
3975                 <xref linkend="protocol-error-fields">.
3976                 Since more field types might be added in future,
3977                 frontends should silently ignore fields of unrecognized
3978                 type.
3979 </para>
3980 </listitem>
3981 </varlistentry>
3982 <varlistentry>
3983 <term>
3984         String
3985 </term>
3986 <listitem>
3987 <para>
3988                 The field value.
3989 </para>
3990 </listitem>
3991 </varlistentry>
3992 </variablelist>
3993
3994 </para>
3995 </listitem>
3996 </varlistentry>
3997
3998
3999 <varlistentry>
4000 <term>
4001 NotificationResponse (B)
4002 </term>
4003 <listitem>
4004 <para>
4005
4006 <variablelist>
4007 <varlistentry>
4008 <term>
4009         Byte1('A')
4010 </term>
4011 <listitem>
4012 <para>
4013                 Identifies the message as a notification response.
4014 </para>
4015 </listitem>
4016 </varlistentry>
4017 <varlistentry>
4018 <term>
4019         Int32
4020 </term>
4021 <listitem>
4022 <para>
4023                 Length of message contents in bytes, including self.
4024 </para>
4025 </listitem>
4026 </varlistentry>
4027 <varlistentry>
4028 <term>
4029         Int32
4030 </term>
4031 <listitem>
4032 <para>
4033                 The process ID of the notifying backend process.
4034 </para>
4035 </listitem>
4036 </varlistentry>
4037 <varlistentry>
4038 <term>
4039         String
4040 </term>
4041 <listitem>
4042 <para>
4043                 The name of the channel that the notify has been raised on.
4044 </para>
4045 </listitem>
4046 </varlistentry>
4047 <varlistentry>
4048 <term>
4049         String
4050 </term>
4051 <listitem>
4052 <para>
4053                 The <quote>payload</> string passed from the notifying process.
4054 </para>
4055 </listitem>
4056 </varlistentry>
4057 </variablelist>
4058
4059 </para>
4060 </listitem>
4061 </varlistentry>
4062
4063
4064 <varlistentry>
4065 <term>
4066 ParameterDescription (B)
4067 </term>
4068 <listitem>
4069 <para>
4070
4071 <variablelist>
4072 <varlistentry>
4073 <term>
4074         Byte1('t')
4075 </term>
4076 <listitem>
4077 <para>
4078                 Identifies the message as a parameter description.
4079 </para>
4080 </listitem>
4081 </varlistentry>
4082 <varlistentry>
4083 <term>
4084         Int32
4085 </term>
4086 <listitem>
4087 <para>
4088                 Length of message contents in bytes, including self.
4089 </para>
4090 </listitem>
4091 </varlistentry>
4092 <varlistentry>
4093 <term>
4094         Int16
4095 </term>
4096 <listitem>
4097 <para>
4098                 The number of parameters used by the statement
4099                 (can be zero).
4100 </para>
4101 </listitem>
4102 </varlistentry>
4103 </variablelist>
4104         Then, for each parameter, there is the following:
4105 <variablelist>
4106 <varlistentry>
4107 <term>
4108         Int32
4109 </term>
4110 <listitem>
4111 <para>
4112                 Specifies the object ID of the parameter data type.
4113 </para>
4114 </listitem>
4115 </varlistentry>
4116 </variablelist>
4117 </para>
4118 </listitem>
4119 </varlistentry>
4120
4121
4122 <varlistentry>
4123 <term>
4124 ParameterStatus (B)
4125 </term>
4126 <listitem>
4127 <para>
4128
4129 <variablelist>
4130 <varlistentry>
4131 <term>
4132         Byte1('S')
4133 </term>
4134 <listitem>
4135 <para>
4136                 Identifies the message as a run-time parameter status report.
4137 </para>
4138 </listitem>
4139 </varlistentry>
4140 <varlistentry>
4141 <term>
4142         Int32
4143 </term>
4144 <listitem>
4145 <para>
4146                 Length of message contents in bytes, including self.
4147 </para>
4148 </listitem>
4149 </varlistentry>
4150 <varlistentry>
4151 <term>
4152         String
4153 </term>
4154 <listitem>
4155 <para>
4156                 The name of the run-time parameter being reported.
4157 </para>
4158 </listitem>
4159 </varlistentry>
4160 <varlistentry>
4161 <term>
4162         String
4163 </term>
4164 <listitem>
4165 <para>
4166                 The current value of the parameter.
4167 </para>
4168 </listitem>
4169 </varlistentry>
4170 </variablelist>
4171 </para>
4172 </listitem>
4173 </varlistentry>
4174
4175
4176 <varlistentry>
4177 <term>
4178 Parse (F)
4179 </term>
4180 <listitem>
4181 <para>
4182
4183 <variablelist>
4184 <varlistentry>
4185 <term>
4186         Byte1('P')
4187 </term>
4188 <listitem>
4189 <para>
4190                 Identifies the message as a Parse command.
4191 </para>
4192 </listitem>
4193 </varlistentry>
4194 <varlistentry>
4195 <term>
4196         Int32
4197 </term>
4198 <listitem>
4199 <para>
4200                 Length of message contents in bytes, including self.
4201 </para>
4202 </listitem>
4203 </varlistentry>
4204 <varlistentry>
4205 <term>
4206         String
4207 </term>
4208 <listitem>
4209 <para>
4210                 The name of the destination prepared statement
4211                 (an empty string selects the unnamed prepared statement).
4212 </para>
4213 </listitem>
4214 </varlistentry>
4215 <varlistentry>
4216 <term>
4217         String
4218 </term>
4219 <listitem>
4220 <para>
4221                 The query string to be parsed.
4222 </para>
4223 </listitem>
4224 </varlistentry>
4225 <varlistentry>
4226 <term>
4227         Int16
4228 </term>
4229 <listitem>
4230 <para>
4231                 The number of parameter data types specified
4232                 (can be zero).  Note that this is not an indication of
4233                 the number of parameters that might appear in the
4234                 query string, only the number that the frontend wants to
4235                 prespecify types for.
4236 </para>
4237 </listitem>
4238 </varlistentry>
4239 </variablelist>
4240         Then, for each parameter, there is the following:
4241 <variablelist>
4242 <varlistentry>
4243 <term>
4244         Int32
4245 </term>
4246 <listitem>
4247 <para>
4248                 Specifies the object ID of the parameter data type.
4249                 Placing a zero here is equivalent to leaving the type
4250                 unspecified.
4251 </para>
4252 </listitem>
4253 </varlistentry>
4254 </variablelist>
4255 </para>
4256 </listitem>
4257 </varlistentry>
4258
4259
4260 <varlistentry>
4261 <term>
4262 ParseComplete (B)
4263 </term>
4264 <listitem>
4265 <para>
4266
4267 <variablelist>
4268 <varlistentry>
4269 <term>
4270         Byte1('1')
4271 </term>
4272 <listitem>
4273 <para>
4274                 Identifies the message as a Parse-complete indicator.
4275 </para>
4276 </listitem>
4277 </varlistentry>
4278 <varlistentry>
4279 <term>
4280         Int32(4)
4281 </term>
4282 <listitem>
4283 <para>
4284                 Length of message contents in bytes, including self.
4285 </para>
4286 </listitem>
4287 </varlistentry>
4288 </variablelist>
4289
4290 </para>
4291 </listitem>
4292 </varlistentry>
4293
4294
4295 <varlistentry>
4296 <term>
4297 PasswordMessage (F)
4298 </term>
4299 <listitem>
4300 <para>
4301
4302 <variablelist>
4303 <varlistentry>
4304 <term>
4305         Byte1('p')
4306 </term>
4307 <listitem>
4308 <para>
4309                 Identifies the message as a password response. Note that
4310                 this is also used for GSSAPI and SSPI response messages
4311                 (which is really a design error, since the contained data
4312                 is not a null-terminated string in that case, but can be
4313                 arbitrary binary data).
4314 </para>
4315 </listitem>
4316 </varlistentry>
4317 <varlistentry>
4318 <term>
4319         Int32
4320 </term>
4321 <listitem>
4322 <para>
4323                 Length of message contents in bytes, including self.
4324 </para>
4325 </listitem>
4326 </varlistentry>
4327 <varlistentry>
4328 <term>
4329         String
4330 </term>
4331 <listitem>
4332 <para>
4333                 The password (encrypted, if requested).
4334 </para>
4335 </listitem>
4336 </varlistentry>
4337 </variablelist>
4338 </para>
4339 </listitem>
4340 </varlistentry>
4341
4342
4343 <varlistentry>
4344 <term>
4345 PortalSuspended (B)
4346 </term>
4347 <listitem>
4348 <para>
4349
4350 <variablelist>
4351 <varlistentry>
4352 <term>
4353         Byte1('s')
4354 </term>
4355 <listitem>
4356 <para>
4357                 Identifies the message as a portal-suspended indicator.
4358                 Note this only appears if an Execute message's row-count limit
4359                 was reached.
4360 </para>
4361 </listitem>
4362 </varlistentry>
4363 <varlistentry>
4364 <term>
4365         Int32(4)
4366 </term>
4367 <listitem>
4368 <para>
4369                 Length of message contents in bytes, including self.
4370 </para>
4371 </listitem>
4372 </varlistentry>
4373 </variablelist>
4374
4375 </para>
4376 </listitem>
4377 </varlistentry>
4378
4379
4380 <varlistentry>
4381 <term>
4382 Query (F)
4383 </term>
4384 <listitem>
4385 <para>
4386
4387 <variablelist>
4388 <varlistentry>
4389 <term>
4390         Byte1('Q')
4391 </term>
4392 <listitem>
4393 <para>
4394                 Identifies the message as a simple query.
4395 </para>
4396 </listitem>
4397 </varlistentry>
4398 <varlistentry>
4399 <term>
4400         Int32
4401 </term>
4402 <listitem>
4403 <para>
4404                 Length of message contents in bytes, including self.
4405 </para>
4406 </listitem>
4407 </varlistentry>
4408 <varlistentry>
4409 <term>
4410         String
4411 </term>
4412 <listitem>
4413 <para>
4414                 The query string itself.
4415 </para>
4416 </listitem>
4417 </varlistentry>
4418 </variablelist>
4419
4420 </para>
4421 </listitem>
4422 </varlistentry>
4423
4424
4425 <varlistentry>
4426 <term>
4427 ReadyForQuery (B)
4428 </term>
4429 <listitem>
4430 <para>
4431
4432 <variablelist>
4433 <varlistentry>
4434 <term>
4435         Byte1('Z')
4436 </term>
4437 <listitem>
4438 <para>
4439                 Identifies the message type.  ReadyForQuery is sent
4440                 whenever the backend is ready for a new query cycle.
4441 </para>
4442 </listitem>
4443 </varlistentry>
4444 <varlistentry>
4445 <term>
4446         Int32(5)
4447 </term>
4448 <listitem>
4449 <para>
4450                 Length of message contents in bytes, including self.
4451 </para>
4452 </listitem>
4453 </varlistentry>
4454 <varlistentry>
4455 <term>
4456         Byte1
4457 </term>
4458 <listitem>
4459 <para>
4460                 Current backend transaction status indicator.
4461                 Possible values are '<literal>I</>' if idle (not in
4462                 a transaction block); '<literal>T</>' if in a transaction
4463                 block; or '<literal>E</>' if in a failed transaction
4464                 block (queries will be rejected until block is ended).
4465 </para>
4466 </listitem>
4467 </varlistentry>
4468 </variablelist>
4469
4470 </para>
4471 </listitem>
4472 </varlistentry>
4473
4474
4475 <varlistentry>
4476 <term>
4477 RowDescription (B)
4478 </term>
4479 <listitem>
4480 <para>
4481
4482 <variablelist>
4483 <varlistentry>
4484 <term>
4485         Byte1('T')
4486 </term>
4487 <listitem>
4488 <para>
4489                 Identifies the message as a row description.
4490 </para>
4491 </listitem>
4492 </varlistentry>
4493 <varlistentry>
4494 <term>
4495         Int32
4496 </term>
4497 <listitem>
4498 <para>
4499                 Length of message contents in bytes, including self.
4500 </para>
4501 </listitem>
4502 </varlistentry>
4503 <varlistentry>
4504 <term>
4505         Int16
4506 </term>
4507 <listitem>
4508 <para>
4509                 Specifies the number of fields in a row (can be zero).
4510 </para>
4511 </listitem>
4512 </varlistentry>
4513 </variablelist>
4514         Then, for each field, there is the following:
4515 <variablelist>
4516 <varlistentry>
4517 <term>
4518         String
4519 </term>
4520 <listitem>
4521 <para>
4522                 The field name.
4523 </para>
4524 </listitem>
4525 </varlistentry>
4526 <varlistentry>
4527 <term>
4528         Int32
4529 </term>
4530 <listitem>
4531 <para>
4532                 If the field can be identified as a column of a specific
4533                 table, the object ID of the table; otherwise zero.
4534 </para>
4535 </listitem>
4536 </varlistentry>
4537 <varlistentry>
4538 <term>
4539         Int16
4540 </term>
4541 <listitem>
4542 <para>
4543                 If the field can be identified as a column of a specific
4544                 table, the attribute number of the column; otherwise zero.
4545 </para>
4546 </listitem>
4547 </varlistentry>
4548 <varlistentry>
4549 <term>
4550         Int32
4551 </term>
4552 <listitem>
4553 <para>
4554                 The object ID of the field's data type.
4555 </para>
4556 </listitem>
4557 </varlistentry>
4558 <varlistentry>
4559 <term>
4560         Int16
4561 </term>
4562 <listitem>
4563 <para>
4564                 The data type size (see <varname>pg_type.typlen</>).
4565                 Note that negative values denote variable-width types.
4566 </para>
4567 </listitem>
4568 </varlistentry>
4569 <varlistentry>
4570 <term>
4571         Int32
4572 </term>
4573 <listitem>
4574 <para>
4575                 The type modifier (see <varname>pg_attribute.atttypmod</>).
4576                 The meaning of the modifier is type-specific.
4577 </para>
4578 </listitem>
4579 </varlistentry>
4580 <varlistentry>
4581 <term>
4582         Int16
4583 </term>
4584 <listitem>
4585 <para>
4586                 The format code being used for the field.  Currently will
4587                 be zero (text) or one (binary).  In a RowDescription
4588                 returned from the statement variant of Describe, the
4589                 format code is not yet known and will always be zero.
4590 </para>
4591 </listitem>
4592 </varlistentry>
4593 </variablelist>
4594
4595 </para>
4596 </listitem>
4597 </varlistentry>
4598
4599
4600 <varlistentry>
4601 <term>
4602 SSLRequest (F)
4603 </term>
4604 <listitem>
4605 <para>
4606
4607 <variablelist>
4608 <varlistentry>
4609 <term>
4610         Int32(8)
4611 </term>
4612 <listitem>
4613 <para>
4614                 Length of message contents in bytes, including self.
4615 </para>
4616 </listitem>
4617 </varlistentry>
4618 <varlistentry>
4619 <term>
4620         Int32(80877103)
4621 </term>
4622 <listitem>
4623 <para>
4624                 The <acronym>SSL</acronym> request code.  The value is chosen to contain
4625                 <literal>1234</> in the most significant 16 bits, and <literal>5679</> in the
4626                 least 16 significant bits.  (To avoid confusion, this code
4627                 must not be the same as any protocol version number.)
4628 </para>
4629 </listitem>
4630 </varlistentry>
4631 </variablelist>
4632
4633 </para>
4634 </listitem>
4635 </varlistentry>
4636
4637
4638 <varlistentry>
4639 <term>
4640 StartupMessage (F)
4641 </term>
4642 <listitem>
4643 <para>
4644
4645 <variablelist>
4646 <varlistentry>
4647 <term>
4648         Int32
4649 </term>
4650 <listitem>
4651 <para>
4652                 Length of message contents in bytes, including self.
4653 </para>
4654 </listitem>
4655 </varlistentry>
4656 <varlistentry>
4657 <term>
4658         Int32(196608)
4659 </term>
4660 <listitem>
4661 <para>
4662                 The protocol version number.  The most significant 16 bits are
4663                 the major version number (3 for the protocol described here).
4664                 The least significant 16 bits are the minor version number
4665                 (0 for the protocol described here).
4666 </para>
4667 </listitem>
4668 </varlistentry>
4669 </variablelist>
4670         The protocol version number is followed by one or more pairs of
4671         parameter name and value strings.  A zero byte is required as a
4672         terminator after the last name/value pair.
4673         Parameters can appear in any
4674         order.  <literal>user</> is required, others are optional.
4675         Each parameter is specified as:
4676 <variablelist>
4677 <varlistentry>
4678 <term>
4679         String
4680 </term>
4681 <listitem>
4682 <para>
4683                 The parameter name.  Currently recognized names are:
4684
4685 <variablelist>
4686 <varlistentry>
4687 <term>
4688                 <literal>user</>
4689 </term>
4690 <listitem>
4691 <para>
4692                         The database user name to connect as.  Required;
4693                         there is no default.
4694 </para>
4695 </listitem>
4696 </varlistentry>
4697 <varlistentry>
4698 <term>
4699                 <literal>database</>
4700 </term>
4701 <listitem>
4702 <para>
4703                         The database to connect to.  Defaults to the user name.
4704 </para>
4705 </listitem>
4706 </varlistentry>
4707 <varlistentry>
4708 <term>
4709                 <literal>options</>
4710 </term>
4711 <listitem>
4712 <para>
4713                         Command-line arguments for the backend.  (This is
4714                         deprecated in favor of setting individual run-time
4715                         parameters.)
4716 </para>
4717 </listitem>
4718 </varlistentry>
4719 </variablelist>
4720
4721                 In addition to the above, any run-time parameter that can be
4722                 set at backend start time might be listed.  Such settings
4723                 will be applied during backend start (after parsing the
4724                 command-line options if any).  The values will act as
4725                 session defaults.
4726 </para>
4727 </listitem>
4728 </varlistentry>
4729 <varlistentry>
4730 <term>
4731         String
4732 </term>
4733 <listitem>
4734 <para>
4735                 The parameter value.
4736 </para>
4737 </listitem>
4738 </varlistentry>
4739 </variablelist>
4740
4741 </para>
4742 </listitem>
4743 </varlistentry>
4744
4745
4746 <varlistentry>
4747 <term>
4748 Sync (F)
4749 </term>
4750 <listitem>
4751 <para>
4752
4753 <variablelist>
4754 <varlistentry>
4755 <term>
4756         Byte1('S')
4757 </term>
4758 <listitem>
4759 <para>
4760                 Identifies the message as a Sync command.
4761 </para>
4762 </listitem>
4763 </varlistentry>
4764 <varlistentry>
4765 <term>
4766         Int32(4)
4767 </term>
4768 <listitem>
4769 <para>
4770                 Length of message contents in bytes, including self.
4771 </para>
4772 </listitem>
4773 </varlistentry>
4774 </variablelist>
4775
4776 </para>
4777 </listitem>
4778 </varlistentry>
4779
4780
4781 <varlistentry>
4782 <term>
4783 Terminate (F)
4784 </term>
4785 <listitem>
4786 <para>
4787
4788 <variablelist>
4789 <varlistentry>
4790 <term>
4791         Byte1('X')
4792 </term>
4793 <listitem>
4794 <para>
4795                 Identifies the message as a termination.
4796 </para>
4797 </listitem>
4798 </varlistentry>
4799 <varlistentry>
4800 <term>
4801         Int32(4)
4802 </term>
4803 <listitem>
4804 <para>
4805                 Length of message contents in bytes, including self.
4806 </para>
4807 </listitem>
4808 </varlistentry>
4809 </variablelist>
4810
4811 </para>
4812 </listitem>
4813 </varlistentry>
4814
4815
4816 </variablelist>
4817
4818 </sect1>
4819
4820
4821 <sect1 id="protocol-error-fields">
4822 <title>Error and Notice Message Fields</title>
4823
4824 <para>
4825 This section describes the fields that can appear in ErrorResponse and
4826 NoticeResponse messages.  Each field type has a single-byte identification
4827 token.  Note that any given field type should appear at most once per
4828 message.
4829 </para>
4830
4831 <variablelist>
4832
4833 <varlistentry>
4834 <term>
4835 <literal>S</>
4836 </term>
4837 <listitem>
4838 <para>
4839         Severity: the field contents are
4840         <literal>ERROR</>, <literal>FATAL</>, or
4841         <literal>PANIC</> (in an error message), or
4842         <literal>WARNING</>, <literal>NOTICE</>, <literal>DEBUG</>,
4843         <literal>INFO</>, or <literal>LOG</> (in a notice message),
4844         or a localized translation of one of these.  Always present.
4845 </para>
4846 </listitem>
4847 </varlistentry>
4848
4849 <varlistentry>
4850 <term>
4851 <literal>C</>
4852 </term>
4853 <listitem>
4854 <para>
4855         Code: the SQLSTATE code for the error (see <xref
4856         linkend="errcodes-appendix">).  Not localizable.  Always present.
4857 </para>
4858 </listitem>
4859 </varlistentry>
4860
4861 <varlistentry>
4862 <term>
4863 <literal>M</>
4864 </term>
4865 <listitem>
4866 <para>
4867         Message: the primary human-readable error message.
4868         This should be accurate but terse (typically one line).
4869         Always present.
4870 </para>
4871 </listitem>
4872 </varlistentry>
4873
4874 <varlistentry>
4875 <term>
4876 <literal>D</>
4877 </term>
4878 <listitem>
4879 <para>
4880         Detail: an optional secondary error message carrying more
4881         detail about the problem.  Might run to multiple lines.
4882 </para>
4883 </listitem>
4884 </varlistentry>
4885
4886 <varlistentry>
4887 <term>
4888 <literal>H</>
4889 </term>
4890 <listitem>
4891 <para>
4892         Hint: an optional suggestion what to do about the problem.
4893         This is intended to differ from Detail in that it offers advice
4894         (potentially inappropriate) rather than hard facts.
4895         Might run to multiple lines.
4896 </para>
4897 </listitem>
4898 </varlistentry>
4899
4900 <varlistentry>
4901 <term>
4902 <literal>P</>
4903 </term>
4904 <listitem>
4905 <para>
4906         Position: the field value is a decimal ASCII integer, indicating
4907         an error cursor position as an index into the original query string.
4908         The first character has index 1, and positions are measured in
4909         characters not bytes.
4910 </para>
4911 </listitem>
4912 </varlistentry>
4913
4914 <varlistentry>
4915 <term>
4916 <literal>p</>
4917 </term>
4918 <listitem>
4919 <para>
4920         Internal position: this is defined the same as the <literal>P</>
4921         field, but it is used when the cursor position refers to an internally
4922         generated command rather than the one submitted by the client.
4923         The <literal>q</> field will always appear when this field appears.
4924 </para>
4925 </listitem>
4926 </varlistentry>
4927
4928 <varlistentry>
4929 <term>
4930 <literal>q</>
4931 </term>
4932 <listitem>
4933 <para>
4934         Internal query: the text of a failed internally-generated command.
4935         This could be, for example, a SQL query issued by a PL/pgSQL function.
4936 </para>
4937 </listitem>
4938 </varlistentry>
4939
4940 <varlistentry>
4941 <term>
4942 <literal>W</>
4943 </term>
4944 <listitem>
4945 <para>
4946         Where: an indication of the context in which the error occurred.
4947         Presently this includes a call stack traceback of active
4948         procedural language functions and internally-generated queries.
4949         The trace is one entry per line, most recent first.
4950 </para>
4951 </listitem>
4952 </varlistentry>
4953
4954 <varlistentry>
4955 <term>
4956 <literal>s</>
4957 </term>
4958 <listitem>
4959 <para>
4960         Schema name: if the error was associated with a specific database
4961         object, the name of the schema containing that object, if any.
4962 </para>
4963 </listitem>
4964 </varlistentry>
4965
4966 <varlistentry>
4967 <term>
4968 <literal>t</>
4969 </term>
4970 <listitem>
4971 <para>
4972         Table name: if the error was associated with a specific table, the
4973         name of the table.  (Refer to the schema name field for the name of
4974         the table's schema.)
4975 </para>
4976 </listitem>
4977 </varlistentry>
4978
4979 <varlistentry>
4980 <term>
4981 <literal>c</>
4982 </term>
4983 <listitem>
4984 <para>
4985         Column name: if the error was associated with a specific table column,
4986         the name of the column.  (Refer to the schema and table name fields to
4987         identify the table.)
4988 </para>
4989 </listitem>
4990 </varlistentry>
4991
4992 <varlistentry>
4993 <term>
4994 <literal>d</>
4995 </term>
4996 <listitem>
4997 <para>
4998         Data type name: if the error was associated with a specific data type,
4999         the name of the data type.  (Refer to the schema name field for the
5000         name of the data type's schema.)
5001 </para>
5002 </listitem>
5003 </varlistentry>
5004
5005 <varlistentry>
5006 <term>
5007 <literal>n</>
5008 </term>
5009 <listitem>
5010 <para>
5011         Constraint name: if the error was associated with a specific
5012         constraint, the name of the constraint.  Refer to fields listed above
5013         for the associated table or domain.  (For this purpose, indexes are
5014         treated as constraints, even if they weren't created with constraint
5015         syntax.)
5016 </para>
5017 </listitem>
5018 </varlistentry>
5019
5020 <varlistentry>
5021 <term>
5022 <literal>F</>
5023 </term>
5024 <listitem>
5025 <para>
5026         File: the file name of the source-code location where the error
5027         was reported.
5028 </para>
5029 </listitem>
5030 </varlistentry>
5031
5032 <varlistentry>
5033 <term>
5034 <literal>L</>
5035 </term>
5036 <listitem>
5037 <para>
5038         Line: the line number of the source-code location where the error
5039         was reported.
5040 </para>
5041 </listitem>
5042 </varlistentry>
5043
5044 <varlistentry>
5045 <term>
5046 <literal>R</>
5047 </term>
5048 <listitem>
5049 <para>
5050         Routine: the name of the source-code routine reporting the error.
5051 </para>
5052 </listitem>
5053 </varlistentry>
5054
5055 </variablelist>
5056
5057 <note>
5058  <para>
5059   The fields for schema name, table name, column name, data type name, and
5060   constraint name are supplied only for a limited number of error types;
5061   see <xref linkend="errcodes-appendix">.  Frontends should not assume that
5062   the presence of any of these fields guarantees the presence of another
5063   field.  Core error sources observe the interrelationships noted above, but
5064   user-defined functions may use these fields in other ways.  In the same
5065   vein, clients should not assume that these fields denote contemporary
5066   objects in the current database.
5067  </para>
5068 </note>
5069
5070 <para>
5071 The client is responsible for formatting displayed information to meet its
5072 needs; in particular it should break long lines as needed.  Newline characters
5073 appearing in the error message fields should be treated as paragraph breaks,
5074 not line breaks.
5075 </para>
5076
5077 </sect1>
5078
5079 <sect1 id="protocol-changes">
5080 <title>Summary of Changes since Protocol 2.0</title>
5081
5082 <para>
5083 This section provides a quick checklist of changes, for the benefit of
5084 developers trying to update existing client libraries to protocol 3.0.
5085 </para>
5086
5087 <para>
5088 The initial startup packet uses a flexible list-of-strings format
5089 instead of a fixed format.  Notice that session default values for run-time
5090 parameters can now be specified directly in the startup packet.  (Actually,
5091 you could do that before using the <literal>options</> field, but given the
5092 limited width of <literal>options</> and the lack of any way to quote
5093 whitespace in the values, it wasn't a very safe technique.)
5094 </para>
5095
5096 <para>
5097 All messages now have a length count immediately following the message type
5098 byte (except for startup packets, which have no type byte).  Also note that
5099 PasswordMessage now has a type byte.
5100 </para>
5101
5102 <para>
5103 ErrorResponse and NoticeResponse ('<literal>E</>' and '<literal>N</>')
5104 messages now contain multiple fields, from which the client code can
5105 assemble an error message of the desired level of verbosity.  Note that
5106 individual fields will typically not end with a newline, whereas the single
5107 string sent in the older protocol always did.
5108 </para>
5109
5110 <para>
5111 The ReadyForQuery ('<literal>Z</>') message includes a transaction status
5112 indicator.
5113 </para>
5114
5115 <para>
5116 The distinction between BinaryRow and DataRow message types is gone; the
5117 single DataRow message type serves for returning data in all formats.
5118 Note that the layout of DataRow has changed to make it easier to parse.
5119 Also, the representation of binary values has changed: it is no longer
5120 directly tied to the server's internal representation.
5121 </para>
5122
5123 <para>
5124 There is a new <quote>extended query</> sub-protocol, which adds the frontend
5125 message types Parse, Bind, Execute, Describe, Close, Flush, and Sync, and the
5126 backend message types ParseComplete, BindComplete, PortalSuspended,
5127 ParameterDescription, NoData, and CloseComplete.  Existing clients do not
5128 have to concern themselves with this sub-protocol, but making use of it
5129 might allow improvements in performance or functionality.
5130 </para>
5131
5132 <para>
5133 <command>COPY</command> data is now encapsulated into CopyData and CopyDone messages.  There
5134 is a well-defined way to recover from errors during <command>COPY</command>.  The special
5135 <quote><literal>\.</></quote> last line is not needed anymore, and is not sent
5136 during <command>COPY OUT</command>.
5137 (It is still recognized as a terminator during <command>COPY IN</command>, but its use is
5138 deprecated and will eventually be removed.)  Binary <command>COPY</command> is supported.
5139 The CopyInResponse and CopyOutResponse messages include fields indicating
5140 the number of columns and the format of each column.
5141 </para>
5142
5143 <para>
5144 The layout of FunctionCall and FunctionCallResponse messages has changed.
5145 FunctionCall can now support passing NULL arguments to functions.  It also
5146 can handle passing parameters and retrieving results in either text or
5147 binary format.  There is no longer any reason to consider FunctionCall a
5148 potential security hole, since it does not offer direct access to internal
5149 server data representations.
5150 </para>
5151
5152 <para>
5153 The backend sends ParameterStatus ('<literal>S</>') messages during connection
5154 startup for all parameters it considers interesting to the client library.
5155 Subsequently, a ParameterStatus message is sent whenever the active value
5156 changes for any of these parameters.
5157 </para>
5158
5159 <para>
5160 The RowDescription ('<literal>T</>') message carries new table OID and column
5161 number fields for each column of the described row.  It also shows the format
5162 code for each column.
5163 </para>
5164
5165 <para>
5166 The CursorResponse ('<literal>P</>') message is no longer generated by
5167 the backend.
5168 </para>
5169
5170 <para>
5171 The NotificationResponse ('<literal>A</>') message has an additional string
5172 field, which can carry a <quote>payload</> string passed
5173 from the <command>NOTIFY</command> event sender.
5174 </para>
5175
5176 <para>
5177 The EmptyQueryResponse ('<literal>I</>') message used to include an empty
5178 string parameter; this has been removed.
5179 </para>
5180
5181 </sect1>
5182
5183 </chapter>