Chapter 25. フロントエンド/バックエンド プロトコル

Table of Contents
概要
プロトコル
メッセージのデータ型
メッセージ形式

Note: Written by Phil Thompson.

Phil Thompson によって作成されました。 Updates for protocol 2.0 by Tom Lane. Tom Lane によりプロトコルバージョン 2.0 用にアップデートされました。

Postgres uses a message-based protocol for communication between frontends and backends. The protocol is implemented over TCP/IP and also on Unix sockets. Postgres v6.3 introduced version numbers into the protocol. This was done in such a way as to still allow connections from earlier versions of frontends, but this document does not cover the protocol used by those earlier versions.

Postgres はフロントエンドとバックエンドの通信に メッセージベースのプロトコルを使用します。このプロトコルは TCP/IP および Unix ソケットを介して実装されます。Postgres v6.3 はこのプロトコルに対しバージョン番号を導入しました。これは旧バージョンのフロントエンド に対しても接続を可能にするためですが、このドキュメントでは以前のバージョンで使用された プロトコルについては解説しません。

This document describes version 2.0 of the protocol, implemented in Postgres v6.4 and later.

このドキュメントは Postgres v6.4 およびそれ以降に実装された プロトコル 2.0 バージョンについて記載します。

Higher level features built on this protocol (for example, how libpq passes certain environment variables after the connection is established) are covered elsewhere.

本プロトコル上に構築されたより高度の機能(たとえば、接続開始後どのように libpq がある特定の環境変数を手渡すか)についても記載します。

概要

The three major components are the frontend (running on the client) and the postmaster and backend (running on the server). The postmaster and backend have different roles but may be implemented by the same executable.

主だった3つのコンポーネントとして、フロントエンド(クライアント側で動くもの)、 postmaster およびバックエンド(サーバ上で動くもの)があります。 postmaster と バックエンドは異なった役割を持っていますが、同一のバイナリで実装されています。

A frontend sends a startup packet to the postmaster. This includes the names of the user and the database the user wants to connect to. The postmaster then uses this, and the information in the pg_hba.conf(5) file to determine what further authentication information it requires the frontend to send (if any) and responds to the frontend accordingly.

フロントエンドは開始パケットを postmaster に送ります。開始パケットにはユーザの 名前とユーザが接続しようとしているデータベースの名称が含まれています。 postmaster はこのパケットの情報と pg_hba.conf(5) ファイルの内容から、ここでフロントエンドが 更に加えて送さなければならない認証のための情報(もし有れば)を決定してフロントエン ドに要求します。

The frontend then sends any required authentication information. Once the postmaster validates this it responds to the frontend that it is authenticated and hands over the connection to a backend. The backend then sends a message indicating successful startup (normal case) or failure (for example, an invalid database name).

フロントエンドはそこで要求された認証情報を送り返します。 postmaster が承認した 場合 postmaster は認証完了のサインをフロントエンドに返し、接続をバックエンドに 引き渡します。そこでバックエンドは(通常の場合)起動成功あるいは失敗(例えば無効な データベース名)のメッセージを返します。

Subsequent communications are query and result packets exchanged between the frontend and the backend. The postmaster takes no further part in ordinary query/result communication. (However, the postmaster is involved when the frontend wishes to cancel a query currently being executed by its backend. Further details about that appear below.)

次に引き続く通信はフロントエンドとバックエンド間で交換される問い合わせとその 結果のパケットです。postmaster は通常の問い合わせと回答の通信には関与しません。 (但し、現在バックエンドで処理中の問い合わせをフロントエンドが取消けそうとす るとき postmaster は関与します。詳細に付いては下記にあります。)

When the frontend wishes to disconnect it sends an appropriate packet and closes the connection without waiting for a response for the backend.

フロントエンドが接続を解除するとき、特定のパケットを送出しバックエンドの応答 を待つこと無く接続を解除します。

Packets are sent as a data stream. The first byte determines what should be expected in the rest of the packet. The exception is packets sent from a frontend to the postmaster, which comprise a packet length then the packet itself. The difference is historical.

パケットは一連のデータの流れとして送出されます。第一番目のバイトは、それ以降 パケットが何を要求しているかを規定します。例外はフロントエンドから postmaster に送られるパケットで、パケット長と、パケットのデータそのものから成ります。 この違いは歴史的な事情によるものです。