バージョンごとのドキュメント一覧

52.2. 接続の確立 #

<title>How Connections Are Established</title>

<productname>PostgreSQL</productname> implements a <quote>process per user</quote> client/server model. In this model, every <glossterm linkend="glossary-client">client process</glossterm> connects to exactly one <glossterm linkend="glossary-backend">backend process</glossterm>. As we do not know ahead of time how many connections will be made, we have to use a <quote>supervisor process</quote> that spawns a new backend process every time a connection is requested. This supervisor process is called <glossterm linkend="glossary-postmaster">postmaster</glossterm> and listens at a specified TCP/IP port for incoming connections. Whenever it detects a request for a connection, it spawns a new backend process. Those backend processes communicate with each other and with other processes of the <glossterm linkend="glossary-instance">instance</glossterm> using <firstterm>semaphores</firstterm> and <glossterm linkend="glossary-shared-memory">shared memory</glossterm> to ensure data integrity throughout concurrent data access. PostgreSQL1プロセスに1ユーザのクライアント/サーバモデルを実装しています。 このモデルでは、各クライアントプロセスは厳密に1つのバックエンドプロセスに接続します。 いくつの接続が行われるか事前にわからないので、接続要求の度に新しいバックエンドプロセスを作るスーパーバイザプロセスを使わなければなりません。 このスーパーバイザプロセスはpostmasterと呼ばれ、指定されたTCP/IPポートで入ってくる接続要求を監視します。 接続要求を検出すると、新しいバックエンドプロセスを生み出します。 このバックエンドプロセスはセマフォ共有メモリを活用してお互いに連絡を取り合い、instanceの他のプロセスと通信し、同時にデータにアクセスしても整合性が保たれるようにします。

The client process can be any program that understands the <productname>PostgreSQL</productname> protocol described in <xref linkend="protocol"/>. Many clients are based on the C-language library <application>libpq</application>, but several independent implementations of the protocol exist, such as the Java <application>JDBC</application> driver. クライアントプロセスは第55章に記載されたPostgreSQLプロトコルを理解できるどんなプログラムでも構いません。 多くのクライアントはlibpq C言語ライブラリに基づいていますが、Java JDBCドライバのようにいくつかの独立したプロトコル実装も存在します。

Once a connection is established, the client process can send a query to the backend process it's connected to. The query is transmitted using plain text, i.e., there is no parsing done in the client. The backend process parses the query, creates an <firstterm>execution plan</firstterm>, executes the plan, and returns the retrieved rows to the client by transmitting them over the established connection. いったん接続が確立されると、クライアントプロセスは接続されたバックエンドプロセスに問い合わせを送ることができます。 問い合わせは平文で送信されます。 つまり、クライアントでは構文解析を行いません。 バックエンドプロセスは問い合わせの構文解析を行い、実行計画を作り、そして計画を実行し、抽出した行を確立された接続を通じてクライアントに返します。