PostgreSQL 9.4.26 Documentation | |||
---|---|---|---|
Prev | Up | Chapter 49. Frontend/Backend Protocol | Next |
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 cannot be interpretable on their own.)
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that the authentication was successful.
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that Kerberos V5 authentication is required.
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that a clear-text password is required.
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that an MD5-encrypted password is required.
The salt to use when encrypting the password.
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that an SCM credentials message is required.
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that GSSAPI authentication is required.
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that SSPI authentication is required.
Identifies the message as an authentication request.
Length of message contents in bytes, including self.
Specifies that this message contains GSSAPI or SSPI data.
GSSAPI or SSPI authentication data.
Identifies the message as cancellation key data. The frontend must save these values if it wishes to be able to issue CancelRequest messages later.
Length of message contents in bytes, including self.
The process ID of this backend.
The secret key of this backend.
Identifies the message as a Bind command.
Length of message contents in bytes, including self.
The name of the destination portal (an empty string selects the unnamed portal).
The name of the source prepared statement (an empty string selects the unnamed prepared statement).
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 parameter format codes. Each must presently be zero (text) or one (binary).
The number of parameter values that follow (possibly zero). This must match the number of parameters needed by the query.
Next, the following pair of fields appear for each parameter:
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.
The value of the parameter, in the format indicated by the associated format code. n is the above length.
After the last parameter, the following fields appear:
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 result-column format codes. Each must presently be zero (text) or one (binary).
Identifies the message as a Bind-complete indicator.
Length of message contents in bytes, including self.
Length of message contents in bytes, including self.
The cancel request code. The value is chosen to contain 1234 in the most significant 16 bits, and 5678 in the least significant 16 bits. (To avoid confusion, this code must not be the same as any protocol version number.)
The process ID of the target backend.
The secret key for the target backend.
Identifies the message as a Close command.
Length of message contents in bytes, including self.
'S' to close a prepared statement; or 'P' to close a portal.
The name of the prepared statement or portal to close (an empty string selects the unnamed prepared statement or portal).
Identifies the message as a Close-complete indicator.
Length of message contents in bytes, including self.
Identifies the message as a command-completed response.
Length of message contents in bytes, including self.
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.
For a DELETE command, the tag is 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.
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 MOVE rows where rows is the number of rows the cursor's position has been changed by.
For a FETCH command, the tag is 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.)
Identifies the message as COPY data.
Length of message contents in bytes, including self.
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 might divide the data stream arbitrarily.
Identifies the message as a COPY-complete indicator.
Length of message contents in bytes, including self.
Identifies the message as a COPY-failure indicator.
Length of message contents in bytes, including self.
An error message to report as the cause of failure.
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).
Length of message contents in bytes, including self.
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 COPY for more information.
The number of columns in the data to be copied (denoted N below).
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.
Identifies the message as a Start Copy Out response. This message will be followed by copy-out data.
Length of message contents in bytes, including self.
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 COPY for more information.
The number of columns in the data to be copied (denoted N below).
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.
Identifies the message as a Start Copy Both response. This message is used only for Streaming Replication.
Length of message contents in bytes, including self.
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 COPY for more information.
The number of columns in the data to be copied (denoted N below).
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.
Identifies the message as a data row.
Length of message contents in bytes, including self.
The number of column values that follow (possibly zero).
Next, the following pair of fields appear for each column:
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.
The value of the column, in the format indicated by the associated format code. n is the above length.
Identifies the message as a Describe command.
Length of message contents in bytes, including self.
'S' to describe a prepared statement; or 'P' to describe a portal.
The name of the prepared statement or portal to describe (an empty string selects the unnamed prepared statement or portal).
Identifies the message as a response to an empty query string. (This substitutes for CommandComplete.)
Length of message contents in bytes, including self.
Identifies the message as an error.
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 can appear in any order. For each field there is the following:
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 Section 49.6. Since more field types might be added in future, frontends should silently ignore fields of unrecognized type.
The field value.
Identifies the message as an Execute command.
Length of message contents in bytes, including self.
The name of the portal to execute (an empty string selects the unnamed portal).
Maximum number of rows to return, if portal contains a query that returns rows (ignored otherwise). Zero denotes "no limit".
Identifies the message as a Flush command.
Length of message contents in bytes, including self.
Identifies the message as a function call.
Length of message contents in bytes, including self.
Specifies the object ID of the function to call.
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 argument format codes. Each must presently be zero (text) or one (binary).
Specifies the number of arguments being supplied to the function.
Next, the following pair of fields appear for each argument:
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.
The value of the argument, in the format indicated by the associated format code. n is the above length.
After the last argument, the following field appears:
The format code for the function result. Must presently be zero (text) or one (binary).
Identifies the message as a function call result.
Length of message contents in bytes, including self.
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.
The value of the function result, in the format indicated by the associated format code. n is the above length.
Identifies the message as a protocol version negotiation message.
Length of message contents in bytes, including self.
Newest minor protocol version supported by the server for the major protocol version requested by the client.
Number of protocol options not recognized by the server.
Then, for protocol option not recognized by the server, there is the following:
The option name.
Identifies the message as a no-data indicator.
Length of message contents in bytes, including self.
Identifies the message as a notice.
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 can appear in any order. For each field there is the following:
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 Section 49.6. Since more field types might be added in future, frontends should silently ignore fields of unrecognized type.
The field value.
Identifies the message as a notification response.
Length of message contents in bytes, including self.
The process ID of the notifying backend process.
The name of the channel that the notify has been raised on.
The "payload" string passed from the notifying process.
Identifies the message as a parameter description.
Length of message contents in bytes, including self.
The number of parameters used by the statement (can be zero).
Then, for each parameter, there is the following:
Specifies the object ID of the parameter data type.
Identifies the message as a run-time parameter status report.
Length of message contents in bytes, including self.
The name of the run-time parameter being reported.
The current value of the parameter.
Identifies the message as a Parse command.
Length of message contents in bytes, including self.
The name of the destination prepared statement (an empty string selects the unnamed prepared statement).
The query string to be parsed.
The number of parameter data types specified (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:
Specifies the object ID of the parameter data type. Placing a zero here is equivalent to leaving the type unspecified.
Identifies the message as a Parse-complete indicator.
Length of message contents in bytes, including self.
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).
Length of message contents in bytes, including self.
The password (encrypted, if requested).
Identifies the message as a portal-suspended indicator. Note this only appears if an Execute message's row-count limit was reached.
Length of message contents in bytes, including self.
Identifies the message as a simple query.
Length of message contents in bytes, including self.
The query string itself.
Identifies the message type. ReadyForQuery is sent whenever the backend is ready for a new query cycle.
Length of message contents in bytes, including self.
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).
Identifies the message as a row description.
Length of message contents in bytes, including self.
Specifies the number of fields in a row (can be zero).
Then, for each field, there is the following:
The field name.
If the field can be identified as a column of a specific table, the object ID of the table; otherwise zero.
If the field can be identified as a column of a specific table, the attribute number of the column; otherwise zero.
The object ID of the field's data type.
The data type size (see pg_type.typlen). Note that negative values denote variable-width types.
The type modifier (see pg_attribute.atttypmod). The meaning of the modifier is type-specific.
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.
Length of message contents in bytes, including self.
The SSL request code. The value is chosen to contain 1234 in the most significant 16 bits, and 5679 in the least significant 16 bits. (To avoid confusion, this code must not be the same as any protocol version number.)
Length of message contents in bytes, including self.
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 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:
The parameter name. Currently recognized names are:
The database user name to connect as. Required; there is no default.
The database to connect to. Defaults to the user name.
Command-line arguments for the backend. (This is deprecated in favor of setting individual run-time parameters.)
In addition to the above, other parameters may be listed. Parameter names beginning with _pq_. are reserved for use as protocol extensions, while others are treated as run-time parameters to be set at backend start time. Such settings will be applied during backend start (after parsing the command-line arguments if any) and will act as session defaults.
The parameter value.
Identifies the message as a Sync command.
Length of message contents in bytes, including self.
Identifies the message as a termination.
Length of message contents in bytes, including self.