Redrock Postgres Search Chinese
Version: 9.3 / 9.4 / 9.5 / 9.6 / 10 / 11 / 12 / 13 / 14 / 15 / 16

Chapter 51. Frontend/Backend Protocol

Table of Contents
51.1. Overview
51.1.1. Messaging Overview
51.1.2. Extended Query Overview
51.1.3. Formats and Format Codes
51.2. Message Flow
51.2.1. Start-up
51.2.2. Simple Query
51.2.3. Extended Query
51.2.4. Function Call
51.2.5. COPY Operations
51.2.6. Asynchronous Operations
51.2.7. Canceling Requests in Progress
51.2.8. Termination
51.2.9. SSL Session Encryption
51.3. Streaming Replication Protocol
51.4. Message Data Types
51.5. Message Formats
51.6. Error and Notice Message Fields
51.7. Summary of Changes since Protocol 2.0

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 can be used.

This document describes version 3.0 of the protocol, implemented in PostgreSQL 7.4 and later. For descriptions of the earlier protocol versions, see previous releases of the PostgreSQL documentation. A single server can support multiple protocol versions. The initial startup-request message tells the server which protocol version the client is attempting to use, and then the server follows that protocol if it is able.

In order to serve multiple clients efficiently, the server launches a new "backend" process for each client. In the current implementation, a new child process is created immediately after an incoming connection is detected. This is transparent to the protocol, however. For purposes of the protocol, the terms "backend" and "server" are interchangeable; likewise "frontend" and "client" are interchangeable.