Message Formats

PostgreSQL 7.2 Documentation
Prev | Chapter 4. Frontend/Backend Protocol | Next

# 4.4. Message Formats

This section describes the detailed format of each message. Each can be sent by either a frontend (F), a backend (B), or both (F & B).

AsciiRow (B)

  Byte1('D')

    Identifies the message as an ASCII data row. (A prior RowDescription message defines the number of fields in the row and their data types.)

  Byte`n`

    A bit map with one bit for each field in the row. The 1st field corresponds to bit 7 (MSB) of the 1st byte, the 2nd field corresponds to bit 6 of the 1st byte, the 8th field corresponds to bit 0 (LSB) of the 1st byte, the 9th field corresponds to bit 7 of the 2nd byte, and so on. Each bit is set if the value of the corresponding field is not NULL. If the number of fields is not a multiple of 8, the remainder of the last byte in the bit map is wasted.

    Then, for each field with a non-NULL value, there is the following:

    Int32

      Specifies the size of the value of the field, including this size.

    Byte`n`

      Specifies the value of the field itself in ASCII characters. `n` is the above size minus 4. There is no trailing zero-byte in the field data; the front end must add one if it wants one.

AuthenticationOk (B)

  Byte1('R')

    Identifies the message as an authentication request.

  Int32(0)

    Specifies that the authentication was successful.

AuthenticationKerberosV4 (B)

  Byte1('R')

    Identifies the message as an authentication request.

  Int32(1)

    Specifies that Kerberos V4 authentication is required.

AuthenticationKerberosV5 (B)

  Byte1('R')

    Identifies the message as an authentication request.

  Int32(2)

    Specifies that Kerberos V5 authentication is required.

AuthenticationCleartextPassword (B)

  Byte1('R')

    Identifies the message as an authentication request.

  Int32(3)

    Specifies that a cleartext password is required.

AuthenticationCryptPassword (B)

  Byte1('R')

    Identifies the message as an authentication request.

  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(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(6)

    Specifies that an SCM credentials message is required.

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

    The process ID of this backend.

  Int32

    The secret key of this backend.

BinaryRow (B)

  Byte1('B')

    Identifies the message as a binary data row. (A prior RowDescription message defines the number of fields in the row and their data types.)

  Byte`n`

    A bit map with one bit for each field in the row. The 1st field corresponds to bit 7 (MSB) of the 1st byte, the 2nd field corresponds to bit 6 of the 1st byte, the 8th field corresponds to bit 0 (LSB) of the 1st byte, the 9th field corresponds to bit 7 of the 2nd byte, and so on. Each bit is set if the value of the corresponding field is not NULL. If the number of fields is not a multiple of 8, the remainder of the last byte in the bit map is wasted.

    Then, for each field with a non-NULL value, there is the following:

    Int32

      Specifies the size of the value of the field, excluding this size.

    Byte`n`

      Specifies the value of the field itself in binary format. `n` is the above size.

CancelRequest (F)

  Int32(16)

    The size of the packet in bytes.

  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.

CompletedResponse (B)

  Byte1('C')

    Identifies the message as a completed response.

  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, and `oid` is the object ID of the inserted row if `rows` is 1, 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.

CopyDataRows (B & F)

  This is a stream of rows where each row is terminated by a Byte1('\n'). This is then followed by the sequence Byte1('\\'), Byte1('.'), Byte1('\n').

CopyInResponse (B)

  Byte1('G')

    Identifies the message as a Start Copy In response. The frontend must now send a CopyDataRows message.

CopyOutResponse (B)

  Byte1('H')

    Identifies the message as a Start Copy Out response. This message will be followed by a CopyDataRows message.

CursorResponse (B)

  Byte1('P')

    Identifies the message as a cursor response.

  String

    The name of the cursor. This will be "blank" if the cursor is implicit.

EmptyQueryResponse (B)

  Byte1('I')

    Identifies the message as a response to an empty query string.

  String("")

    Unused.

ErrorResponse (B)

  Byte1('E')

    Identifies the message as an error.

  String

    The error message itself.

FunctionCall (F)

  Byte1('F')

    Identifies the message as a function call.

  String("")

    Unused.

  Int32

    Specifies the object ID of the function to call.

  Int32

    Specifies the number of arguments being supplied to the function.

    Then, for each argument, there is the following:

    Int32

      Specifies the size of the value of the argument, excluding this size.

    Byte`n`

      Specifies the value of the field itself in binary format. `n` is the above size.

FunctionResultResponse (B)

  Byte1('V')

    Identifies the message as a function call result.

  Byte1('G')

    Specifies that a nonempty result was returned.

  Int32

    Specifies the size of the value of the result, excluding this size.

  Byte`n`

    Specifies the value of the result itself in binary format. `n` is the above size.

  Byte1('0')

    Unused. (Strictly speaking, FunctionResultResponse and FunctionVoidResponse are the same thing but with some optional parts to the message.)

FunctionVoidResponse (B)

  Byte1('V')

    Identifies the message as a function call result.

  Byte1('0')

    Specifies that an empty result was returned.

NoticeResponse (B)

  Byte1('N')

    Identifies the message as a notice.

  String

    The notice message itself.

NotificationResponse (B)

  Byte1('A')

    Identifies the message as a notification response.

  Int32

    The process ID of the notifying backend process.

  String

    The name of the condition that the notify has been raised on.

PasswordPacket (F)

  Int32

    The size of the packet in bytes.

  String

    The password (encrypted, if requested).

Query (F)

  Byte1('Q')

    Identifies the message as a query.

  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.

RowDescription (B)

  Byte1('T')

    Identifies the message as a row description.

  Int16

    Specifies the number of fields in a row (may be zero).

    Then, for each field, there is the following:

    String

      Specifies the field name.

    Int32

      Specifies the object ID of the field type.

    Int16

      Specifies the type size.

    Int32

      Specifies the type modifier.

SSLRequest (F)

  Int32(8)

    The size of the packet in bytes.

  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.)

StartupPacket (F)

  Int32(296)

    The size of the packet in bytes.

  Int32

    The protocol version number. The most significant 16 bits are the major version number. The least 16 significant bits are the minor version number.

  LimString64

    The database name, defaults to the user name if empty.

  LimString32

    The user name.

  LimString64

    Any additional command line arguments to be passed to the backend child process by the server.

  LimString64

    Unused.

  LimString64

    The optional tty the backend should use for debugging messages. (Currently, this field is unsupported and ignored.)

Terminate (F)

  Byte1('X')

    Identifies the message as a termination.

Prev | Home | Next
Message Data Types | Up | gcc Default Optimizations