X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=doc%2Fsrc%2Fsgml%2Fprotocol.sgml;h=73f26b432da0943ecbc9477fce139f9f832acca3;hb=048d148fe63102fafb2336ab5439c950dea7f692;hp=e93d5e4aa2c7b2b7dadbd866efe9a2706ae42466;hpb=b5ae0d69da8f83e400921fcdd171e5bdadb45db3;p=postgresql diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml index e93d5e4aa2..73f26b432d 100644 --- a/doc/src/sgml/protocol.sgml +++ b/doc/src/sgml/protocol.sgml @@ -1,15 +1,20 @@ - + Frontend/Backend Protocol + + protocol + frontend-backend + + PostgreSQL uses a message-based protocol for communication between frontends and backends (clients and servers). The protocol is supported over TCP/IP and also over Unix-domain sockets. Port number 5432 has been registered with IANA as the customary TCP port number for servers supporting this protocol, but - in practice any non-privileged port number may be used. + in practice any non-privileged port number can be used. @@ -23,12 +28,6 @@ if it is able. - - Higher level features built on this protocol (for example, how - libpq passes certain environment - variables when the connection is established) are covered elsewhere. - - In order to serve multiple clients efficiently, the server launches a new backend process for each client. @@ -104,7 +103,7 @@ count) before attempting to process its contents. This allows easy recovery if an error is detected while processing the contents. In extreme situations (such as not having enough memory to buffer the - message), the receiver may use the byte count to determine how much + message), the receiver can use the byte count to determine how much input to skip before it resumes reading messages. @@ -126,8 +125,9 @@ into multiple steps. The state retained between steps is represented by two types of objects: prepared statements and portals. A prepared statement represents the result of - parsing, semantic analysis, and planning of a textual query string. A - prepared statement is not necessarily ready to execute, because it may + parsing, semantic analysis, and (optionally) planning of a textual query + string. + A prepared statement is not necessarily ready to execute, because it might lack specific values for parameters. A portal represents a ready-to-execute or already-partially-executed statement, with any missing parameter values filled in. (For SELECT statements, @@ -143,7 +143,7 @@ execute step that runs a portal's query. In the case of a query that returns rows (SELECT, SHOW, etc), the execute step can be told to fetch only - a limited number of rows, so that multiple execute steps may be needed + a limited number of rows, so that multiple execute steps might be needed to complete the operation. @@ -169,7 +169,7 @@ the only supported formats are text and binary, but the protocol makes provision for future extensions. The desired format for any value is specified by a format code. - Clients may specify a format code for each transmitted parameter value + Clients can specify a format code for each transmitted parameter value and for each column of a query result. Text has format code zero, binary has format code one, and all other format codes are reserved for future definition. @@ -188,7 +188,7 @@ Binary representations for integers use network byte order (most significant byte first). For other data types consult the documentation or source code to learn about the binary representation. Keep in mind - that binary representations for complex data types may change across + that binary representations for complex data types might change across server versions; the text format is usually the more portable choice. @@ -210,7 +210,7 @@ - Start-Up + Start-Up To begin a session, a frontend opens a connection to the server and sends @@ -229,11 +229,11 @@ The server then sends an appropriate authentication request message, to which the frontend must reply with an appropriate authentication response message (such as a password). - In principle the authentication request/response cycle could require - multiple iterations, but none of the present authentication methods - use more than one request and response. In some methods, no response + For all authentication methods except GSSAPI and SSPI, there is at most + one request and one response. In some methods, no response at all is needed from the frontend, and so no authentication request - occurs. + occurs. For GSSAPI and SSPI, multiple exchanges of packets may be needed + to complete the authentication. @@ -265,10 +265,10 @@ - AuthenticationKerberosV4 + AuthenticationKerberosV5 - The frontend must now take part in a Kerberos V4 + The frontend must now take part in a Kerberos V5 authentication dialog (not described here, part of the Kerberos specification) with the server. If this is successful, the server responds with an AuthenticationOk, @@ -278,74 +278,89 @@ - AuthenticationKerberosV5 - - - The frontend must now take part in a Kerberos V5 - authentication dialog (not described here, part of the - Kerberos specification) with the server. If this is - successful, the server responds with an AuthenticationOk, - otherwise it responds with an ErrorResponse. - - - - - - AuthenticationCleartextPassword - - - The frontend must now send a PasswordMessage containing the - password in clear-text form. If - this is the correct password, the server responds with an - AuthenticationOk, otherwise it responds with an ErrorResponse. - - - - - - AuthenticationCryptPassword - - + AuthenticationCleartextPassword + + The frontend must now send a PasswordMessage containing the - password encrypted via crypt(3), using the 2-character salt - specified in the AuthenticationCryptPassword message. If + password in clear-text form. If this is the correct password, the server responds with an AuthenticationOk, otherwise it responds with an ErrorResponse. - - - - - - AuthenticationMD5Password - - + + + + + + AuthenticationMD5Password + + The frontend must now send a PasswordMessage containing the - password encrypted via MD5, using the 4-character salt - specified in the AuthenticationMD5Password message. If + password encrypted via MD5, using the 4-character salt + specified in the AuthenticationMD5Password message. If this is the correct password, the server responds with an AuthenticationOk, otherwise it responds with an ErrorResponse. - - - - - - AuthenticationSCMCredential - - + + + + + + AuthenticationSCMCredential + + This response is only possible for local Unix-domain connections - on platforms that support SCM credential messages. The frontend - must issue an SCM credential message and then send a single data - byte. (The contents of the data byte are uninteresting; it's - only used to ensure that the server waits long enough to receive - the credential message.) If the credential is acceptable, - the server responds with an + on platforms that support SCM credential messages. The frontend + must issue an SCM credential message and then send a single data + byte. (The contents of the data byte are uninteresting; it's + only used to ensure that the server waits long enough to receive + the credential message.) If the credential is acceptable, + the server responds with an AuthenticationOk, otherwise it responds with an ErrorResponse. - - - + + + - - + + AuthenticationGSS + + + The frontend must now initiate a GSSAPI negotiation. The frontend + will send a PasswordMessage with the first part of the GSSAPI + data stream in response to this. If further messages are needed, + the server will respond with AuthenticationGSSContinue. + + + + + + AuthenticationSSPI + + + The frontend must now initiate a SSPI negotiation. The frontend + will send a PasswordMessage with the first part of the SSPI + data stream in response to this. If further messages are needed, + the server will respond with AuthenticationGSSContinue. + + + + + + AuthenticationGSSContinue + + + This message contains the response data from the previous step + of GSSAPI or SSPI negotiation (AuthenticationGSS, AuthenticationSSPI + or a previous AuthenticationGSSContinue). If the GSSAPI + or SSPI data in this message + indicates more data is needed to complete the authentication, + the frontend must send that data as another PasswordMessage. If + GSSAPI or SSPI authentication is completed by this message, the server + will next send AuthenticationOk to indicate successful authentication + or ErrorResponse to indicate failure. + + + + + + If the frontend does not support the authentication method @@ -372,66 +387,66 @@ The possible messages from the backend in this phase are: - - - BackendKeyData - - + + + BackendKeyData + + This message provides secret-key data that the frontend must save if it wants to be able to issue cancel requests later. The frontend should not respond to this message, but should continue listening for a ReadyForQuery message. - - - - - - ParameterStatus - - + + + + + + ParameterStatus + + This message informs the frontend about the current (initial) setting of backend parameters, such as or . - The frontend may ignore this message, or record the settings + linkend="guc-client-encoding"> or . + The frontend can ignore this message, or record the settings for its future use; see for more details. The frontend should not respond to this message, but should continue listening for a ReadyForQuery message. - - - - - - ReadyForQuery - - - Start-up is completed. The frontend may now issue commands. - - - - - - ErrorResponse - - + + + + + + ReadyForQuery + + + Start-up is completed. The frontend can now issue commands. + + + + + + ErrorResponse + + Start-up failed. The connection is closed after sending this message. - - - - - - NoticeResponse - - + + + + + + NoticeResponse + + A warning message has been issued. The frontend should display the message but continue listening for ReadyForQuery or ErrorResponse. - - - - - + + + + + The ReadyForQuery message is the same one that the backend will @@ -442,126 +457,126 @@ - - Simple Query + + Simple Query - + A simple query cycle is initiated by the frontend sending a Query message to the backend. The message includes an SQL command (or commands) expressed as a text string. The backend then sends one or more response messages depending on the contents of the query command string, and finally a ReadyForQuery response message. ReadyForQuery - informs the frontend that it may safely send a new command. + informs the frontend that it can safely send a new command. (It is not actually necessary for the frontend to wait for ReadyForQuery before issuing another command, but the frontend must then take responsibility for figuring out what happens if the earlier command fails and already-issued later commands succeed.) - + The possible response messages from the backend are: - - - CommandComplete - - + + + CommandComplete + + An SQL command completed normally. - - - - - - CopyInResponse - - + + + + + + CopyInResponse + + The backend is ready to copy data from the frontend to a table; see . - - - - - - CopyOutResponse - - + + + + + + CopyOutResponse + + The backend is ready to copy data from a table to the frontend; see . - - - - - - RowDescription - - + + + + + + RowDescription + + Indicates that rows are about to be returned in response to - a SELECT, FETCH, etc query. - The contents of this message describe the column layout of the rows. - This will be followed by a DataRow message for each row being returned + a SELECT, FETCH, etc query. + The contents of this message describe the column layout of the rows. + This will be followed by a DataRow message for each row being returned to the frontend. - - - - - - DataRow - - + + + + + + DataRow + + One of the set of rows returned by - a SELECT, FETCH, etc query. - - - - - - EmptyQueryResponse - - + a SELECT, FETCH, etc query. + + + + + + EmptyQueryResponse + + An empty query string was recognized. - - - - - - ErrorResponse - - + + + + + + ErrorResponse + + An error has occurred. - - - - - - ReadyForQuery - - + + + + + + ReadyForQuery + + Processing of the query string is complete. A separate - message is sent to indicate this because the query string may + message is sent to indicate this because the query string might contain multiple SQL commands. (CommandComplete marks the end of processing one SQL command, not the whole string.) ReadyForQuery will always be sent, whether processing terminates successfully or with an error. - - - - - - NoticeResponse - - + + + + + + NoticeResponse + + A warning message has been issued in relation to the query. Notices are in addition to other responses, i.e., the backend will continue processing the command. - - - + + + - - + + - + The response to a SELECT query (or other queries that return row sets, such as EXPLAIN or SHOW) normally consists of RowDescription, zero or more @@ -570,28 +585,28 @@ as described in . All other query types normally produce only a CommandComplete message. - + - + Since a query string could contain several queries (separated by semicolons), there might be several such response sequences before the backend finishes processing the query string. ReadyForQuery is issued when the entire string has been processed and the backend is ready to accept a new query string. - + - + If a completely empty (no contents other than whitespace) query string is received, the response is EmptyQueryResponse followed by ReadyForQuery. - + - + In the event of an error, ErrorResponse is issued followed by ReadyForQuery. All further processing of the query string is aborted by ErrorResponse (even if more queries remained in it). Note that this - may occur partway through the sequence of messages generated by an + might occur partway through the sequence of messages generated by an individual query. - + In simple Query mode, the format of retrieved values is always text, @@ -605,7 +620,7 @@ A frontend must be prepared to accept ErrorResponse and NoticeResponse messages whenever it is expecting any other type of message. See also concerning messages - that the backend may generate due to outside events. + that the backend might generate due to outside events. @@ -615,8 +630,8 @@ - - Extended Query + + Extended Query The extended query protocol breaks down the above-described simple @@ -633,12 +648,30 @@ about data types of parameter placeholders, and the name of a destination prepared-statement object (an empty string selects the unnamed prepared statement). The response is - either ParseComplete or ErrorResponse. Parameter data types may be + either ParseComplete or ErrorResponse. Parameter data types can be specified by OID; if not given, the parser attempts to infer the data types in the same way as it would do for untyped literal string constants. + + + A parameter data type can be left unspecified by setting it to zero, + or by making the array of parameter type OIDs shorter than the + number of parameter symbols ($n) + used in the query string. Another special case is that a parameter's + type can be specified as void (that is, the OID of the + void pseudotype). This is meant to allow parameter symbols + to be used for function parameters that are actually OUT parameters. + Ordinarily there is no context in which a void parameter + could be used, but if such a parameter symbol appears in a function's + parameter list, it is effectively ignored. For example, a function + call such as foo($1,$2,$3,$4) could match a function with + two IN and two OUT arguments, if $3 and $4 + are specified as having type void. + + + The query string contained in a Parse message cannot include more @@ -670,6 +703,8 @@ the values to use for any parameter placeholders present in the prepared statement. The supplied parameter set must match those needed by the prepared statement. + (If you declared any void parameters in the Parse message, + pass NULL values for them in the Bind message.) Bind also specifies the format to use for any data returned by the query; the format can be specified overall, or per-column. The response is either BindComplete or ErrorResponse. @@ -686,8 +721,8 @@ Query planning for named prepared-statement objects occurs when the Parse - message is received. If a query will be repeatedly executed with - different parameters, it may be beneficial to send a single Parse message + message is processed. If a query will be repeatedly executed with + different parameters, it might be beneficial to send a single Parse message containing a parameterized query, followed by multiple Bind and Execute messages. This will avoid replanning the query on each execution. @@ -696,31 +731,22 @@ The unnamed prepared statement is likewise planned during Parse processing if the Parse message defines no parameters. But if there are parameters, - query planning is delayed until the first Bind message for the statement - is received. The planner will consider the actual values of the parameters - provided in the Bind message when planning the query. + query planning occurs every time Bind parameters are supplied. This allows the + planner to make use of the actual values of the parameters provided by + each Bind message, rather than use generic estimates. - Query plans generated from a parameterized query may be less + Query plans generated from a parameterized query might be less efficient than query plans generated from an equivalent query with actual parameter values substituted. The query planner cannot make decisions based on actual parameter values (for example, index selectivity) when planning a parameterized query assigned to a named prepared-statement object. This possible penalty is avoided when using the unnamed statement, since it is not planned until actual parameter values are - available. - - - - If a second or subsequent Bind referencing the unnamed prepared-statement - object is received without an intervening Parse, the query is - not replanned. The parameter values used in the first Bind message may - produce a query plan that is only efficient for a subset of possible - parameter values. To force replanning of the query for a fresh set of - parameters, send another Parse message to replace the unnamed - prepared-statement object. + available. The cost is that planning must occur afresh for each Bind, + even if the query stays the same. @@ -854,8 +880,8 @@ - - Function Call + + Function Call The Function Call sub-protocol allows the client to request a direct @@ -878,58 +904,58 @@ FunctionCall message to the backend. The backend then sends one or more response messages depending on the results of the function call, and finally a ReadyForQuery response message. ReadyForQuery - informs the frontend that it may safely send a new query or + informs the frontend that it can safely send a new query or function call. The possible response messages from the backend are: - - - ErrorResponse - - + + + ErrorResponse + + An error has occurred. - - - - - - FunctionCallResponse - - + + + + + + FunctionCallResponse + + The function call was completed and returned the result given - in the message. - (Note that the Function Call protocol can only handle a single - scalar result, not a row type or set of results.) - - - - - - ReadyForQuery - - + in the message. + (Note that the Function Call protocol can only handle a single + scalar result, not a row type or set of results.) + + + + + + ReadyForQuery + + Processing of the function call is complete. ReadyForQuery will always be sent, whether processing terminates successfully or with an error. - - - - - - NoticeResponse - - + + + + + + NoticeResponse + + A warning message has been issued in relation to the function call. Notices are in addition to other responses, i.e., the backend will continue processing the command. - - - - - + + + + + @@ -960,7 +986,7 @@ In the event of a backend-detected error during copy-in mode (including - receipt of a CopyFail message), the backend will issue an ErrorResponse + receipt of a CopyFail message), the backend will issue an ErrorResponse message. If the COPY command was issued via an extended-query message, the backend will now discard frontend messages until a Sync message is received, then it will issue ReadyForQuery and return to normal @@ -994,18 +1020,38 @@ In the event of a backend-detected error during copy-out mode, the backend will issue an ErrorResponse message and revert to normal - processing. The frontend should treat receipt of ErrorResponse (or - indeed any message type other than CopyData or CopyDone) as terminating - the copy-out mode. + processing. The frontend should treat receipt of ErrorResponse as + terminating the copy-out mode. + + + + It is possible for NoticeResponse and ParameterStatus messages to be + interspersed between CopyData messages; frontends must handle these cases, + and should be prepared for other asynchronous message types as well (see + ). Otherwise, any message type other than + CopyData or CopyDone may be treated as terminating copy-out mode. + + + + There is another Copy-related mode called Copy-both, which allows + high-speed bulk data transfer to and from the server. + Copy-both mode is initiated when a backend in walsender mode + executes a START_REPLICATION statement. The + backend sends a CopyBothResponse message to the frontend. Both + the backend and the frontend may then send CopyData messages + until the connection is terminated. See . - The CopyInResponse and CopyOutResponse messages include fields that - inform the frontend of the number of columns per row and the format - codes being used for each column. (As of the present implementation, - all columns in a given COPY operation will use the same - format, but the message design does not assume this.) + The CopyInResponse, CopyOutResponse and CopyBothResponse messages + include fields that inform the frontend of the number of columns + per row and the format codes being used for each column. (As of + the present implementation, all columns in a given COPY + operation will use the same format, but the message design does not + assume this.) + @@ -1037,7 +1083,7 @@ this case is effectively synchronous — but it is also possible for parameter status changes to occur because the administrator changed a configuration file and then sent the - SIGHUP signal to the postmaster. Also, + SIGHUP signal to the server. Also, if a SET command is rolled back, an appropriate ParameterStatus message will be generated to report the current effective value. @@ -1049,13 +1095,20 @@ server_version, server_encoding, client_encoding, + application_name, is_superuser, session_authorization, DateStyle, - TimeZone, and - integer_datetimes. + IntervalStyle, + TimeZone, + integer_datetimes, and + standard_conforming_strings. (server_encoding, TimeZone, and - integer_datetimes were not reported by releases before 8.0.) + integer_datetimes were not reported by releases before 8.0; + standard_conforming_strings was not reported by releases + before 8.1; + IntervalStyle was not reported by releases before 8.4; + application_name was not reported by releases before 9.0.) Note that server_version, server_encoding and @@ -1071,14 +1124,14 @@ backend will send a NotificationResponse message (not to be confused with NoticeResponse!) whenever a NOTIFY command is executed for the same - notification name. + channel name. At present, NotificationResponse can only be sent outside a transaction, and thus it will not occur in the middle of a - command-response series, though it may occur just before ReadyForQuery. + command-response series, though it might occur just before ReadyForQuery. It is unwise to design frontend logic that assumes that, however. Good practice is to be able to accept NotificationResponse at any point in the protocol. @@ -1086,11 +1139,11 @@ - - Cancelling Requests in Progress + + Cancelling Requests in Progress - - During the processing of a query, the frontend may request + + During the processing of a query, the frontend might request cancellation of the query. The cancel request is not sent directly on the open connection to the backend for reasons of implementation efficiency: we don't want to have the backend @@ -1100,7 +1153,7 @@ the normal case. - + To issue a cancel request, the frontend opens a new connection to the server and sends a CancelRequest message, rather than the StartupMessage message that would ordinarily be sent across a new @@ -1109,7 +1162,7 @@ the cancel request message. - + A CancelRequest message will be ignored unless it contains the same key data (PID and secret key) passed to the frontend during connection start-up. If the request matches the PID and secret @@ -1119,15 +1172,15 @@ processing the query.) - - The cancellation signal may or may not have any effect — for + + The cancellation signal might or might not have any effect — for example, if it arrives after the backend has finished processing the query, then it will have no effect. If the cancellation is effective, it results in the current command being terminated early with an error message. - + The upshot of all this is that for reasons of both security and efficiency, the frontend has no direct way to tell whether a cancel request has succeeded. It must continue to wait for the @@ -1137,12 +1190,12 @@ succeeding. - + Since the cancel request is sent across a new connection to the server and not across the regular frontend/backend communication link, it is possible for the cancel request to be issued by any process, not just the frontend whose query is to be canceled. - This may have some benefits of flexibility in building + This might provide additional flexibility when building multiple-process applications. It also introduces a security risk, in that unauthorized persons might try to cancel queries. The security risk is addressed by requiring a dynamically @@ -1150,8 +1203,8 @@ - - Termination + + Termination The normal, graceful termination procedure is that the frontend @@ -1162,7 +1215,7 @@ In rare cases (such as an administrator-commanded database shutdown) - the backend may disconnect without any frontend request to do so. + the backend might disconnect without any frontend request to do so. In such cases the backend will attempt to send an error or notice message giving the reason for the disconnection before it closes the connection. @@ -1185,15 +1238,15 @@ is being processed, the backend will probably finish the query before noticing the disconnection. If the query is outside any transaction block (BEGIN ... COMMIT - sequence) then its results may be committed before the + sequence) then its results might be committed before the disconnection is recognized. - - <acronym>SSL</acronym> Session Encryption + + <acronym>SSL</acronym> Session Encryption - + If PostgreSQL was built with SSL support, frontend/backend communications can be encrypted using SSL. This provides @@ -1209,7 +1262,7 @@ StartupMessage. The server then responds with a single byte containing S or N, indicating that it is willing or unwilling to perform SSL, - respectively. The frontend may close the connection at this point + respectively. The frontend might close the connection at this point if it is dissatisfied with the response. To continue after S, perform an SSL startup handshake (not described here, part of the SSL @@ -1226,910 +1279,1239 @@ response to SSLRequest from the server. This would only occur if the server predates the addition of SSL support to PostgreSQL. In this case the connection must - be closed, but the frontend may choose to open a fresh connection + be closed, but the frontend might choose to open a fresh connection and proceed without requesting SSL. - An initial SSLRequest may also be used in a connection that is being + An initial SSLRequest can also be used in a connection that is being opened to send a CancelRequest message. While the protocol itself does not provide a way for the server to - force SSL encryption, the administrator may + force SSL encryption, the administrator can configure the server to reject unencrypted sessions as a byproduct of authentication checking. - -Message Data Types + +Streaming Replication Protocol - -This section describes the base data types used in messages. + +To initiate streaming replication, the frontend sends the +replication parameter in the startup message. This tells the +backend to go into walsender mode, wherein a small set of replication commands +can be issued instead of SQL statements. Only the simple query protocol can be +used in walsender mode. + +The commands accepted in walsender mode are: + + + + IDENTIFY_SYSTEM + + + Requests the server to identify itself. Server replies with a result + set of a single row, containing two fields: + + + + + + + systemid + + + + The unique system identifier identifying the cluster. This + can be used to check that the base backup used to initialize the + standby came from the same cluster. + + + - - - - - Intn(i) - - - - An n-bit integer in network byte - order (most significant byte first). - If i is specified it - is the exact value that will appear, otherwise the value - is variable. Eg. Int16, Int32(42). - - - - - - - Intn[k] - - - - An array of k - n-bit integers, each in network - byte order. The array length k - is always determined by an earlier field in the message. - Eg. Int16[M]. - - - - - - - String(s) - - - - A null-terminated string (C-style string). There is no - specific length limitation on strings. - If s is specified it is the exact - value that will appear, otherwise the value is variable. - Eg. String, String("user"). - - - - -There is no predefined limit on the length of a string -that can be returned by the backend. Good coding strategy for a frontend -is to use an expandable buffer so that anything that fits in memory can be -accepted. If that's not feasible, read the full string and discard trailing -characters that don't fit into your fixed-size buffer. - - - - - - - - Byten(c) - - - - Exactly n bytes. If the field - width n is not a constant, it is - always determinable from an earlier field in the message. - If c is specified it is the exact - value. Eg. Byte2, Byte1('\n'). - - - + + + timeline + + + + Current TimelineID. Also useful to check that the standby is + consistent with the master. + + + + + + + + + + START_REPLICATION XXX/XXX + + + Instructs server to start streaming WAL, starting at + WAL position XXX/XXX. + The server can reply with an error, e.g. if the requested section of WAL + has already been recycled. On success, server responds with a + CopyBothResponse message, and then starts to stream WAL to the frontend. + WAL will continue to be streamed until the connection is broken; + no further commands will be accepted. + + + + WAL data is sent as a series of CopyData messages. (This allows + other information to be intermixed; in particular the server can send + an ErrorResponse message if it encounters a failure after beginning + to stream.) The payload in each CopyData message follows this format: + + + + + + + XLogData (B) + + + + + + + Byte1('w') + + + + Identifies the message as WAL data. + + + + + + Byte8 + + + + The starting point of the WAL data in this message, given in + XLogRecPtr format. + + + + + + Byte8 + + + + The current end of WAL on the server, given in + XLogRecPtr format. + + + + + + Byte8 + + + + The server's system clock at the time of transmission, + given in TimestampTz format. + + + + + + Byten + + + + A section of the WAL data stream. + + + + + + + + + + + A single WAL record is never split across two CopyData messages. + When a WAL record crosses a WAL page boundary, and is therefore + already split using continuation records, it can be split at the page + boundary. In other words, the first main WAL record and its + continuation records can be sent in different CopyData messages. + + + Note that all fields within the WAL data and the above-described header + will be in the sending server's native format. Endianness, and the + format for the timestamp, are unpredictable unless the receiver has + verified that the sender's system identifier matches its own + pg_control contents. + + + If the WAL sender process is terminated normally (during postmaster + shutdown), it will send a CommandComplete message before exiting. + This might not happen during an abnormal shutdown, of course. + + + + + + BASE_BACKUP [LABEL 'label'] [PROGRESS] [FAST] + + + Instructs the server to start streaming a base backup. + The system will automatically be put in backup mode before the backup + is started, and taken out of it when the backup is complete. The + following options are accepted: + + + LABEL 'label' + + + Sets the label of the backup. If none is specified, a backup label + of base backup will be used. The quoting rules + for the label are the same as a standard SQL string with + turned on. + + + + + + PROGRESS + + + Request information required to generate a progress report. This will + send back an approximate size in the header of each tablespace, which + can be used to calculate how far along the stream is done. This is + calculated by enumerating all the file sizes once before the transfer + is even started, and may as such have a negative impact on the + performance - in particular it may take longer before the first data + is streamed. Since the database files can change during the backup, + the size is only approximate and may both grow and shrink between + the time of approximation and the sending of the actual files. + + + + + + FAST + + + Request a fast checkpoint. + + + + + + + When the backup is started, the server will first send a header in + ordinary result set format, followed by one or more CopyResponse + results, one for PGDATA and one for each additional tablespace other + than pg_default and pg_global. The data in + the CopyResponse results will be a tar format (using ustar00 + extensions) dump of the tablespace contents. + + + The header is an ordinary resultset with one row for each tablespace. + The fields in this row are: + + + spcoid + + + The oid of the tablespace, or NULL if it's the base + directory. + + + + + spclocation + + + The full path of the tablespace directory, or NULL + if it's the base directory. + + + + + size + + + The approximate size of the tablespace, if progress report has + been requested; otherwise it's NULL. + + + + + + + The tar archive for the data directory and each tablespace will contain + all files in the directories, regardless of whether they are + PostgreSQL files or other files added to the same + directory. The only excluded files are: + + + + postmaster.pid + + + + + pg_xlog (including subdirectories) + + + + Owner, group and file mode are set if the underlying filesystem on + the server supports it. + + + + + + - - - -Message Formats + +Message Data Types - -This section describes the detailed format of each message. Each is marked to -indicate that it may be sent by a frontend (F), a backend (B), or both -(F & B). -Notice that although each message includes a byte count at the beginning, -the message format is defined so that the message end can be found without -reference to the byte count. This aids validity checking. (The CopyData + +This section describes the base data types used in messages. + + + + + + Intn(i) + + + + An n-bit integer in network byte + order (most significant byte first). + If i is specified it + is the exact value that will appear, otherwise the value + is variable. Eg. Int16, Int32(42). + + + + + + + Intn[k] + + + + An array of k + n-bit integers, each in network + byte order. The array length k + is always determined by an earlier field in the message. + Eg. Int16[M]. + + + + + + + String(s) + + + + A null-terminated string (C-style string). There is no + specific length limitation on strings. + If s is specified it is the exact + value that will appear, otherwise the value is variable. + Eg. String, String("user"). + + + + +There is no predefined limit on the length of a string +that can be returned by the backend. Good coding strategy for a frontend +is to use an expandable buffer so that anything that fits in memory can be +accepted. If that's not feasible, read the full string and discard trailing +characters that don't fit into your fixed-size buffer. + + + + + + + + Byten(c) + + + + Exactly n bytes. If the field + width n is not a constant, it is + always determinable from an earlier field in the message. + If c is specified it is the exact + value. Eg. Byte2, Byte1('\n'). + + + + + + + + + +Message Formats + + +This section describes the detailed format of each message. Each is marked to +indicate that it can be sent by a frontend (F), a backend (B), or both +(F & B). +Notice that although each message includes a byte count at the beginning, +the message format is defined so that the message end can be found without +reference to the byte count. This aids validity checking. (The CopyData message is an exception, because it forms part of a data stream; the contents -of any individual CopyData message may not be interpretable on their own.) +of any individual CopyData message cannot be interpretable on their own.) - + - - + + AuthenticationOk (B) - - - + + + - - - + + + Byte1('R') - - - + + + Identifies the message as an authentication request. - - - - - + + + + + Int32(8) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(0) - - - + + + Specifies that the authentication was successful. - - - - - - - - - - - - -AuthenticationKerberosV4 (B) - - - - - - - - Byte1('R') - - - - Identifies the message as an authentication request. - - - - - - Int32(8) - - - - Length of message contents in bytes, including self. - - - - - - Int32(1) - - - - Specifies that Kerberos V4 authentication is required. - - - - - - - - - - - + + + + + + + + + + + + AuthenticationKerberosV5 (B) - - - + + + - - - + + + Byte1('R') - - - + + + Identifies the message as an authentication request. - - - - - + + + + + Int32(8) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(2) - - - + + + Specifies that Kerberos V5 authentication is required. - - - - - - - + + + + + + + - - + + AuthenticationCleartextPassword (B) - - - + + + - - - + + + Byte1('R') - - - + + + Identifies the message as an authentication request. - - - - - + + + + + Int32(8) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(3) - - - + + + Specifies that a clear-text password is required. - - - - - - - - - - - -AuthenticationCryptPassword (B) - - - - - - - - Byte1('R') - - - - Identifies the message as an authentication request. - - - - - - Int32(10) - - - - Length of message contents in bytes, including self. - - - - - - Int32(4) - - - - Specifies that a crypt()-encrypted password is required. - - - - - - Byte2 - - - - The salt to use when encrypting the password. - - - - - - - - + + + + + + + - - + + AuthenticationMD5Password (B) - - - + + + - - - + + + Byte1('R') - - - + + + Identifies the message as an authentication request. - - - - - + + + + + Int32(12) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(5) - - - + + + Specifies that an MD5-encrypted password is required. - - - - - + + + + + Byte4 - - - + + + The salt to use when encrypting the password. - - - - + + + + - - - + + + - - + + AuthenticationSCMCredential (B) - - - + + + - - - + + + Byte1('R') - - - + + + Identifies the message as an authentication request. - - - - - + + + + + Int32(8) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(6) - - - + + + Specifies that an SCM credentials message is required. - - - - + + + + + + + + + + + + +AuthenticationGSS (B) + + + + + + + + Byte1('R') + + + + Identifies the message as an authentication request. + + + + + + Int32(8) + + + + Length of message contents in bytes, including self. + + + + + + Int32(7) + + + + Specifies that GSSAPI authentication is required. + + + + + + + + + + + + +AuthenticationSSPI (B) + + + + + + + + Byte1('R') + + + + Identifies the message as an authentication request. + + + + + + Int32(8) + + + + Length of message contents in bytes, including self. + + + + + + Int32(9) + + + + Specifies that SSPI authentication is required. + + + + + + + + + + +AuthenticationGSSContinue (B) + + + - - - + + + + Byte1('R') + + + + Identifies the message as an authentication request. + + + + + + Int32 + + + + Length of message contents in bytes, including self. + + + + + + Int32(8) + + + + Specifies that this message contains GSSAPI or SSPI data. + + + + + + Byten + + + + GSSAPI or SSPI authentication data. + + + + + + + - - + + + BackendKeyData (B) - - - + + + - - - + + + Byte1('K') - - - + + + Identifies the message as cancellation key data. The frontend must save these values if it wishes to be able to issue CancelRequest messages later. - - - - - + + + + + Int32(12) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32 - - - + + + The process ID of this backend. - - - - - + + + + + Int32 - - - + + + The secret key of this backend. - - - - + + + + - - - + + + - - + + Bind (F) - - - + + + - - - + + + Byte1('B') - - - + + + Identifies the message as a Bind command. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + The name of the destination portal - (an empty string selects the unnamed portal). - - - - - + (an empty string selects the unnamed portal). + + + + + String - - - + + + The name of the source prepared statement - (an empty string selects the unnamed prepared statement). - - - - - + (an empty string selects the unnamed prepared statement). + + + + + Int16 - - - - The number of parameter format codes that follow - (denoted C below). - This can be zero to indicate that there are no parameters - or that the parameters all use the default format (text); - or one, in which case the specified format code is applied - to all parameters; or it can equal the actual number of - parameters. - - - - - + + + + The number of parameter format codes that follow + (denoted C below). + This can be zero to indicate that there are no parameters + or that the parameters all use the default format (text); + or one, in which case the specified format code is applied + to all parameters; or it can equal the actual number of + parameters. + + + + + Int16[C] - - - + + + The parameter format codes. Each must presently be - zero (text) or one (binary). - - - - - + zero (text) or one (binary). + + + + + Int16 - - - + + + The number of parameter values that follow (possibly zero). - This must match the number of parameters needed by the query. - - - - + This must match the number of parameters needed by the query. + + + + Next, the following pair of fields appear for each parameter: - - - + + + Int32 - - - + + + The length of the parameter value, in bytes (this count - does not include itself). Can be zero. - As a special case, -1 indicates a NULL parameter value. - No value bytes follow in the NULL case. - - - - - - Byten - - - + does not include itself). Can be zero. + As a special case, -1 indicates a NULL parameter value. + No value bytes follow in the NULL case. + + + + + + Byten + + + The value of the parameter, in the format indicated by the - associated format code. - n is the above length. - - - - + associated format code. + n is the above length. + + + + After the last parameter, the following fields appear: - - - + + + Int16 - - - - The number of result-column format codes that follow - (denoted R below). - This can be zero to indicate that there are no result columns - or that the result columns should all use the default format - (text); - or one, in which case the specified format code is applied - to all result columns (if any); or it can equal the actual - number of result columns of the query. - - - - - + + + + The number of result-column format codes that follow + (denoted R below). + This can be zero to indicate that there are no result columns + or that the result columns should all use the default format + (text); + or one, in which case the specified format code is applied + to all result columns (if any); or it can equal the actual + number of result columns of the query. + + + + + Int16[R] - - - + + + The result-column format codes. Each must presently be - zero (text) or one (binary). - - - - - - - - - - - + zero (text) or one (binary). + + + + + + + + + + + BindComplete (B) - - - + + + - - - + + + Byte1('2') - - - + + + Identifies the message as a Bind-complete indicator. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + CancelRequest (F) - - - + + + - - - + + + Int32(16) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(80877102) - - - + + + The cancel request code. The value is chosen to contain 1234 in the most significant 16 bits, and 5678 in the least 16 significant bits. (To avoid confusion, this code must not be the same as any protocol version number.) - - - - - + + + + + Int32 - - - + + + The process ID of the target backend. - - - - - + + + + + Int32 - - - + + + The secret key for the target backend. - - - - + + + + - - - + + + - - + + Close (F) - - - + + + - - - + + + Byte1('C') - - - + + + Identifies the message as a Close command. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Byte1 - - - + + + 'S' to close a prepared statement; or 'P' to close a portal. - - - - - + + + + + String - - - + + + The name of the prepared statement or portal to close - (an empty string selects the unnamed prepared statement - or portal). - - - - - - - - - - - + (an empty string selects the unnamed prepared statement + or portal). + + + + + + + + + + + CloseComplete (B) - - - + + + - - - + + + Byte1('3') - - - + + + Identifies the message as a Close-complete indicator. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + CommandComplete (B) - - - + + + - - - + + + Byte1('C') - - - + + + Identifies the message as a command-completed response. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + The command tag. This is usually a single word that identifies which SQL command was completed. - + - + For an INSERT command, the tag is INSERT oid rows, where rows is the number of rows inserted. oid is the object ID - of the inserted row if rows is 1 - and the target table has OIDs; - otherwise oid is 0. - + of the inserted row if rows is 1 + and the target table has OIDs; + otherwise oid is 0. + - + For a DELETE command, the tag is - DELETE rows where - rows is the number of rows deleted. - + DELETE rows where + rows is the number of rows deleted. + - + For an UPDATE command, the tag is - UPDATE rows where - rows is the number of rows updated. - + UPDATE rows where + rows is the number of rows updated. + + + + For a SELECT or CREATE TABLE AS + command, the tag is SELECT rows + where rows is the number of rows retrieved. + For a MOVE command, the tag is @@ -2143,1890 +2525,1973 @@ CommandComplete (B) FETCH rows where rows is the number of rows that have been retrieved from the cursor. - - - - + - - - + + For a COPY command, the tag is + COPY rows where + rows is the number of rows copied. + (Note: the row count appears only in + PostgreSQL 8.2 and later.) + + + + + + + + - - + + + CopyData (F & B) - - - - - - + + + + + + Byte1('d') - - - + + + Identifies the message as COPY data. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - - Byten - - - + + + + + + Byten + + + Data that forms part of a COPY data stream. Messages sent - from the backend will always correspond to single data rows, - but messages sent by frontends may divide the data stream - arbitrarily. - - - - - - - - - - - + from the backend will always correspond to single data rows, + but messages sent by frontends might divide the data stream + arbitrarily. + + + + + + + + + + + CopyDone (F & B) - - - + + + - - - + + + Byte1('c') - - - + + + Identifies the message as a COPY-complete indicator. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + CopyFail (F) - - - + + + - - - + + + Byte1('f') - - - + + + Identifies the message as a COPY-failure indicator. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + An error message to report as the cause of failure. - - - - + + + + - - - + + + - - + + CopyInResponse (B) - - - + + + - - - + + + Byte1('G') - - - + + + Identifies the message as a Start Copy In response. The frontend must now send copy-in data (if not - prepared to do so, send a CopyFail message). - - - - - + prepared to do so, send a CopyFail message). + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int8 - - - + + + 0 indicates the overall COPY format is textual (rows - separated by newlines, columns separated by separator - characters, etc). - 1 indicates the overall copy format is binary (similar - to DataRow format). - See - for more information. - - - - - + separated by newlines, columns separated by separator + characters, etc). + 1 indicates the overall copy format is binary (similar + to DataRow format). + See + for more information. + + + + + Int16 - - - - The number of columns in the data to be copied - (denoted N below). - - - - - + + + + The number of columns in the data to be copied + (denoted N below). + + + + + Int16[N] - - - + + + The format codes to be used for each column. - Each must presently be zero (text) or one (binary). - All must be zero if the overall copy format is textual. - - - - + Each must presently be zero (text) or one (binary). + All must be zero if the overall copy format is textual. + + + + - - - + + + - - + + CopyOutResponse (B) - - - + + + - - - + + + Byte1('H') - - - + + + Identifies the message as a Start Copy Out response. This message will be followed by copy-out data. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int8 - - - + + + 0 indicates the overall COPY format is textual (rows separated by newlines, columns separated by separator characters, etc). 1 indicates the overall copy format is binary (similar to DataRow - format). See for more information. - - - - - + format). See for more information. + + + + + Int16 - - - - The number of columns in the data to be copied - (denoted N below). - - - - - + + + + The number of columns in the data to be copied + (denoted N below). + + + + + Int16[N] - - - + + + The format codes to be used for each column. - Each must presently be zero (text) or one (binary). - All must be zero if the overall copy format is textual. - - - - + Each must presently be zero (text) or one (binary). + All must be zero if the overall copy format is textual. + + + + + + + + - - - + + +CopyBothResponse (B) + + + - - + + + + Byte1('W') + + + + Identifies the message as a Start Copy Both response. + This message is used only for Streaming Replication. + + + + + + Int32 + + + + Length of message contents in bytes, including self. + + + + + + Int8 + + + + 0 indicates the overall COPY format + is textual (rows separated by newlines, columns + separated by separator characters, etc). 1 indicates + the overall copy format is binary (similar to DataRow + format). See for more information. + + + + + + Int16 + + + + The number of columns in the data to be copied + (denoted N below). + + + + + + Int16[N] + + + + The format codes to be used for each column. + Each must presently be zero (text) or one (binary). + All must be zero if the overall copy format is textual. + + + + + + + + + + + + DataRow (B) - - - - - - + + + + + + Byte1('D') - - - + + + Identifies the message as a data row. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int16 - - - + + + The number of column values that follow (possibly zero). - - - - + + + + Next, the following pair of fields appear for each column: - - - + + + Int32 - - - + + + The length of the column value, in bytes (this count - does not include itself). Can be zero. - As a special case, -1 indicates a NULL column value. - No value bytes follow in the NULL case. - - - - - - Byten - - - + does not include itself). Can be zero. + As a special case, -1 indicates a NULL column value. + No value bytes follow in the NULL case. + + + + + + Byten + + + The value of the column, in the format indicated by the - associated format code. - n is the above length. - - - - + associated format code. + n is the above length. + + + + - - - + + + - - + + Describe (F) - - - + + + - - - + + + Byte1('D') - - - + + + Identifies the message as a Describe command. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Byte1 - - - + + + 'S' to describe a prepared statement; or 'P' to describe a portal. - - - - - + + + + + String - - - + + + The name of the prepared statement or portal to describe - (an empty string selects the unnamed prepared statement - or portal). - - - - - - - - - - - + (an empty string selects the unnamed prepared statement + or portal). + + + + + + + + + + + EmptyQueryResponse (B) - - - + + + - - - + + + Byte1('I') - - - + + + Identifies the message as a response to an empty query string. - (This substitutes for CommandComplete.) - - - - - + (This substitutes for CommandComplete.) + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + ErrorResponse (B) - - - + + + - - - + + + Byte1('E') - - - + + + Identifies the message as an error. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - + + + + The message body consists of one or more identified fields, - followed by a zero byte as a terminator. Fields may appear in - any order. For each field there is the following: - - - + followed by a zero byte as a terminator. Fields can appear in + any order. For each field there is the following: + + + Byte1 - - - + + + A code identifying the field type; if zero, this is - the message terminator and no string follows. - The presently defined field types are listed in - . - Since more field types may be added in future, - frontends should silently ignore fields of unrecognized - type. - - - - - + the message terminator and no string follows. + The presently defined field types are listed in + . + Since more field types might be added in future, + frontends should silently ignore fields of unrecognized + type. + + + + + String - - - + + + The field value. - - - - + + + + - - - + + + - - + + Execute (F) - - - + + + - - - + + + Byte1('E') - - - + + + Identifies the message as an Execute command. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + The name of the portal to execute - (an empty string selects the unnamed portal). - - - - - + (an empty string selects the unnamed portal). + + + + + Int32 - - - + + + Maximum number of rows to return, if portal contains - a query that returns rows (ignored otherwise). Zero - denotes no limit. - - - - - - - - - - - + a query that returns rows (ignored otherwise). Zero + denotes no limit. + + + + + + + + + + + Flush (F) - - - + + + - - - + + + Byte1('H') - - - + + + Identifies the message as a Flush command. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + FunctionCall (F) - - - + + + - - - + + + Byte1('F') - - - + + + Identifies the message as a function call. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32 - - - + + + Specifies the object ID of the function to call. - - - - - + + + + + Int16 - - - - The number of argument format codes that follow - (denoted C below). - This can be zero to indicate that there are no arguments - or that the arguments all use the default format (text); - or one, in which case the specified format code is applied - to all arguments; or it can equal the actual number of - arguments. - - - - - + + + + The number of argument format codes that follow + (denoted C below). + This can be zero to indicate that there are no arguments + or that the arguments all use the default format (text); + or one, in which case the specified format code is applied + to all arguments; or it can equal the actual number of + arguments. + + + + + Int16[C] - - - + + + The argument format codes. Each must presently be - zero (text) or one (binary). - - - - - + zero (text) or one (binary). + + + + + Int16 - - - + + + Specifies the number of arguments being supplied to the function. - - - - + + + + Next, the following pair of fields appear for each argument: - - - + + + Int32 - - - + + + The length of the argument value, in bytes (this count - does not include itself). Can be zero. - As a special case, -1 indicates a NULL argument value. - No value bytes follow in the NULL case. - - - - - - Byten - - - + does not include itself). Can be zero. + As a special case, -1 indicates a NULL argument value. + No value bytes follow in the NULL case. + + + + + + Byten + + + The value of the argument, in the format indicated by the - associated format code. - n is the above length. - - - - + associated format code. + n is the above length. + + + + After the last argument, the following field appears: - - - + + + Int16 - - - + + + The format code for the function result. Must presently be - zero (text) or one (binary). - - - - + zero (text) or one (binary). + + + + - - - + + + - - + + FunctionCallResponse (B) - - - + + + - - - + + + Byte1('V') - - - + + + Identifies the message as a function call result. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32 - - - + + + The length of the function result value, in bytes (this count - does not include itself). Can be zero. - As a special case, -1 indicates a NULL function result. - No value bytes follow in the NULL case. - - - - - - Byten - - - + does not include itself). Can be zero. + As a special case, -1 indicates a NULL function result. + No value bytes follow in the NULL case. + + + + + + Byten + + + The value of the function result, in the format indicated by - the associated format code. - n is the above length. - - - - + the associated format code. + n is the above length. + + + + - - - + + + - - + + NoData (B) - - - + + + - - - + + + Byte1('n') - - - + + + Identifies the message as a no-data indicator. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + NoticeResponse (B) - - - + + + - - - + + + Byte1('N') - - - + + + Identifies the message as a notice. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - + + + + The message body consists of one or more identified fields, - followed by a zero byte as a terminator. Fields may appear in - any order. For each field there is the following: - - - + followed by a zero byte as a terminator. Fields can appear in + any order. For each field there is the following: + + + Byte1 - - - + + + A code identifying the field type; if zero, this is - the message terminator and no string follows. - The presently defined field types are listed in - . - Since more field types may be added in future, - frontends should silently ignore fields of unrecognized - type. - - - - - + the message terminator and no string follows. + The presently defined field types are listed in + . + Since more field types might be added in future, + frontends should silently ignore fields of unrecognized + type. + + + + + String - - - + + + The field value. - - - - + + + + - - - + + + - - + + NotificationResponse (B) - - - + + + - - - + + + Byte1('A') - - - + + + Identifies the message as a notification response. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32 - - - + + + The process ID of the notifying backend process. - - - - - + + + + + String - - - - The name of the condition that the notify has been raised on. - - - - - + + + + The name of the channel that the notify has been raised on. + + + + + String - - - - Additional information passed from the notifying process. - (Currently, this feature is unimplemented so the field - is always an empty string.) - - - - - - - - - - - - + + + + The payload string passed from the notifying process. + + + + + + + + + + + + ParameterDescription (B) - - - + + + - - - + + + Byte1('t') - - - + + + Identifies the message as a parameter description. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int16 - - - + + + The number of parameters used by the statement - (may be zero). - - - - + (can be zero). + + + + Then, for each parameter, there is the following: - - - + + + Int32 - - - + + + Specifies the object ID of the parameter data type. - - - - - - - + + + + + + + - - + + ParameterStatus (B) - - - + + + - - - + + + Byte1('S') - - - + + + Identifies the message as a run-time parameter status report. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + The name of the run-time parameter being reported. - - - - - + + + + + String - - - + + + The current value of the parameter. - - - - - - - + + + + + + + - - + + Parse (F) - - - + + + - - - + + + Byte1('P') - - - + + + Identifies the message as a Parse command. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + The name of the destination prepared statement - (an empty string selects the unnamed prepared statement). - - - - - + (an empty string selects the unnamed prepared statement). + + + + + String - - - + + + The query string to be parsed. - - - - - + + + + + Int16 - - - + + + The number of parameter data types specified - (may be zero). Note that this is not an indication of - the number of parameters that might appear in the - query string, only the number that the frontend wants to - prespecify types for. - - - - + (can be zero). Note that this is not an indication of + the number of parameters that might appear in the + query string, only the number that the frontend wants to + prespecify types for. + + + + Then, for each parameter, there is the following: - - - + + + Int32 - - - + + + Specifies the object ID of the parameter data type. - Placing a zero here is equivalent to leaving the type - unspecified. - - - - - - - - - - - + Placing a zero here is equivalent to leaving the type + unspecified. + + + + + + + + + + + ParseComplete (B) - - - + + + - - - + + + Byte1('1') - - - + + + Identifies the message as a Parse-complete indicator. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + PasswordMessage (F) - - - + + + - - - + + + Byte1('p') - - - - Identifies the message as a password response. - - - - - + + + + Identifies the message as a password response. Note that + this is also used for GSSAPI and SSPI response messages + (which is really a design error, since the contained data + is not a null-terminated string in that case, but can be + arbitrary binary data). + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + The password (encrypted, if requested). - - - - - - - + + + + + + + - - + + PortalSuspended (B) - - - + + + - - - + + + Byte1('s') - - - + + + Identifies the message as a portal-suspended indicator. - Note this only appears if an Execute message's row-count limit - was reached. - - - - - + Note this only appears if an Execute message's row-count limit + was reached. + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + Query (F) - - - + + + - - - + + + Byte1('Q') - - - + + + Identifies the message as a simple query. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + String - - - + + + The query string itself. - - - - + + + + - - - + + + - - + + ReadyForQuery (B) - - - + + + - - - + + + Byte1('Z') - - - + + + Identifies the message type. ReadyForQuery is sent whenever the backend is ready for a new query cycle. - - - - - + + + + + Int32(5) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Byte1 - - - + + + Current backend transaction status indicator. - Possible values are 'I' if idle (not in - a transaction block); 'T' if in a transaction - block; or 'E' if in a failed transaction - block (queries will be rejected until block is ended). - - - - - - - - - - - - + Possible values are 'I' if idle (not in + a transaction block); 'T' if in a transaction + block; or 'E' if in a failed transaction + block (queries will be rejected until block is ended). + + + + + + + + + + + + RowDescription (B) - - - + + + - - - + + + Byte1('T') - - - + + + Identifies the message as a row description. - - - - - + + + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int16 - - - - Specifies the number of fields in a row (may be zero). - - - - + + + + Specifies the number of fields in a row (can be zero). + + + + Then, for each field, there is the following: - - - + + + String - - - + + + The field name. - - - - - + + + + + Int32 - - - + + + If the field can be identified as a column of a specific - table, the object ID of the table; otherwise zero. - - - - - + table, the object ID of the table; otherwise zero. + + + + + Int16 - - - + + + If the field can be identified as a column of a specific - table, the attribute number of the column; otherwise zero. - - - - - + table, the attribute number of the column; otherwise zero. + + + + + Int32 - - - + + + The object ID of the field's data type. - - - - - + + + + + Int16 - - - + + + The data type size (see pg_type.typlen). - Note that negative values denote variable-width types. - - - - - + Note that negative values denote variable-width types. + + + + + Int32 - - - + + + The type modifier (see pg_attribute.atttypmod). - The meaning of the modifier is type-specific. - - - - - + The meaning of the modifier is type-specific. + + + + + Int16 - - - + + + The format code being used for the field. Currently will - be zero (text) or one (binary). In a RowDescription - returned from the statement variant of Describe, the - format code is not yet known and will always be zero. - - - - + be zero (text) or one (binary). In a RowDescription + returned from the statement variant of Describe, the + format code is not yet known and will always be zero. + + + + - - - + + + - - + + SSLRequest (F) - - - + + + - - - + + + Int32(8) - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(80877103) - - - + + + The SSL request code. The value is chosen to contain 1234 in the most significant 16 bits, and 5679 in the least 16 significant bits. (To avoid confusion, this code must not be the same as any protocol version number.) - - - - + + + + - - - + + + - - + + StartupMessage (F) - - - + + + - - - + + + Int32 - - - + + + Length of message contents in bytes, including self. - - - - - + + + + + Int32(196608) - - - + + + The protocol version number. The most significant 16 bits are the major version number (3 for the protocol described here). - The least significant 16 bits are the minor version number - (0 for the protocol described here). - - - - + The least significant 16 bits are the minor version number + (0 for the protocol described here). + + + + The protocol version number is followed by one or more pairs of - parameter name and value strings. A zero byte is required as a - terminator after the last name/value pair. - Parameters can appear in any - order. user is required, others are optional. - Each parameter is specified as: - - - + parameter name and value strings. A zero byte is required as a + terminator after the last name/value pair. + Parameters can appear in any + order. user is required, others are optional. + Each parameter is specified as: + + + String - - - + + + The parameter name. Currently recognized names are: - - - + + + user - - - + + + The database user name to connect as. Required; - there is no default. - - - - - + there is no default. + + + + + database - - - + + + The database to connect to. Defaults to the user name. - - - - - + + + + + options - - - + + + Command-line arguments for the backend. (This is - deprecated in favor of setting individual run-time - parameters.) - - - - + deprecated in favor of setting individual run-time + parameters.) + + + + In addition to the above, any run-time parameter that can be - set at backend start time may be listed. Such settings - will be applied during backend start (after parsing the - command-line options if any). The values will act as - session defaults. - - - - - + set at backend start time might be listed. Such settings + will be applied during backend start (after parsing the + command-line options if any). The values will act as + session defaults. + + + + + String - - - + + + The parameter value. - - - - + + + + - - - + + + - - + + Sync (F) - - - + + + - - - + + + Byte1('S') - - - + + + Identifies the message as a Sync command. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - - + + Terminate (F) - - - + + + - - - + + + Byte1('X') - - - + + + Identifies the message as a termination. - - - - - + + + + + Int32(4) - - - + + + Length of message contents in bytes, including self. - - - - + + + + - - - + + + - + - -Error and Notice Message Fields + +Error and Notice Message Fields -This section describes the fields that may appear in ErrorResponse and +This section describes the fields that can appear in ErrorResponse and NoticeResponse messages. Each field type has a single-byte identification token. Note that any given field type should appear at most once per message. - + - - + + S - - - + + + Severity: the field contents are ERROR, FATAL, or PANIC (in an error message), or - WARNING, NOTICE, DEBUG, - INFO, or LOG (in a notice message), - or a localized translation of one of these. Always present. - - - - - - + WARNING, NOTICE, DEBUG, + INFO, or LOG (in a notice message), + or a localized translation of one of these. Always present. + + + + + + C - - - + + + Code: the SQLSTATE code for the error (see ). Not localizable. Always present. - - - + linkend="errcodes-appendix">). Not localizable. Always present. + + + - - + + M - - - + + + Message: the primary human-readable error message. This should be accurate but terse (typically one line). Always present. - - - + + + - - + + D - - - + + + Detail: an optional secondary error message carrying more - detail about the problem. May run to multiple lines. - - - + detail about the problem. Might run to multiple lines. + + + - - + + H - - - + + + Hint: an optional suggestion what to do about the problem. - This is intended to differ from Detail in that it offers advice - (potentially inappropriate) rather than hard facts. - May run to multiple lines. - - - - - - + This is intended to differ from Detail in that it offers advice + (potentially inappropriate) rather than hard facts. + Might run to multiple lines. + + + + + + P - - - + + + Position: the field value is a decimal ASCII integer, indicating - an error cursor position as an index into the original query string. - The first character has index 1, and positions are measured in - characters not bytes. - - - - - - + an error cursor position as an index into the original query string. + The first character has index 1, and positions are measured in + characters not bytes. + + + + + + p - - - + + + Internal position: this is defined the same as the P field, but it is used when the cursor position refers to an internally generated command rather than the one submitted by the client. The q field will always appear when this field appears. - - - + + + - - + + q - - - + + + Internal query: the text of a failed internally-generated command. This could be, for example, a SQL query issued by a PL/pgSQL function. - - - + + + - - + + W - - - + + + Where: an indication of the context in which the error occurred. Presently this includes a call stack traceback of active procedural language functions and internally-generated queries. The trace is one entry per line, most recent first. - - - + + + - - + + F - - - + + + File: the file name of the source-code location where the error - was reported. - - - + was reported. + + + - - + + L - - - + + + Line: the line number of the source-code location where the error - was reported. - - - + was reported. + + + - - + + R - - - + + + Routine: the name of the source-code routine reporting the error. - - - + + + - + The client is responsible for formatting displayed information to meet its @@ -4037,9 +4502,8 @@ not line breaks. - - -Summary of Changes since Protocol 2.0 + +Summary of Changes since Protocol 2.0 This section provides a quick checklist of changes, for the benefit of @@ -4063,7 +4527,7 @@ PasswordMessage now has a type byte. ErrorResponse and NoticeResponse ('E' and 'N') -messages now contain multiple fields, from which the client code may +messages now contain multiple fields, from which the client code can assemble an error message of the desired level of verbosity. Note that individual fields will typically not end with a newline, whereas the single string sent in the older protocol always did. @@ -4088,7 +4552,7 @@ message types Parse, Bind, Execute, Describe, Close, Flush, and Sync, and the backend message types ParseComplete, BindComplete, PortalSuspended, ParameterDescription, NoData, and CloseComplete. Existing clients do not have to concern themselves with this sub-protocol, but making use of it -may allow improvements in performance or functionality. +might allow improvements in performance or functionality. @@ -4131,7 +4595,7 @@ the backend. The NotificationResponse ('A') message has an additional string -field, which is presently empty but may someday carry additional data passed +field, which can carry a payload string passed from the NOTIFY event sender. @@ -4142,5 +4606,4 @@ string parameter; this has been removed. - - +