Postgresql 中文操作指南

Chapter 55. Frontend/Backend Protocol

Table of Contents

PostgreSQL 使用基于消息的协议在前端和后端(客户端和服务器)之间进行通信。此协议在 TCP/IP 和 Unix 域套接字上受到支持。端口号 5432 已在 IANA 注册为支持此协议的服务器的惯用 TCP 端口号,但实际上可以用任何非特权端口号。

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.

本文档描述了在 PostgreSQL 7.4 及更高版本中实现的版本 3.0 协议。有关早期协议版本的说明,请参阅 PostgreSQL 文档的早期版本。单个服务器可以支持多个协议版本。初始启动请求消息告诉服务器客户端尝试使用的协议版本。如果服务器不支持客户端请求的主要版本,则连接将被拒绝(例如,如果客户端请求不存在的协议版本 4.0,则会出现这种情况)。如果客户端请求的次要版本不受服务器支持(例如,客户端请求版本 3.1,但服务器只支持 3.0),则服务器可能会拒绝连接,也可能会使用 NegotiateProtocolVersion 消息响应,其中包含它支持的最高次要协议版本。然后,客户端可以选择继续使用指定的协议版本进行连接或中止连接。

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. If the major version requested by the client is not supported by the server, the connection will be rejected (for example, this would occur if the client requested protocol version 4.0, which does not exist as of this writing). If the minor version requested by the client is not supported by the server (e.g., the client requests version 3.1, but the server supports only 3.0), the server may either reject the connection or may respond with a NegotiateProtocolVersion message containing the highest minor protocol version which it supports. The client may then choose either to continue with the connection using the specified protocol version or to abort the connection.

为了有效地服务多个客户端,服务器为每个客户端启动新的“后端”进程。在当前的实现中,在检测到传入连接后,将立即创建一个新子进程。但这是对于该协议来说是透明的。对于该协议的目的,“后端”和“服务器”是同义的;同样,“前端”和“客户端”也是同义的。

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.