接続の確立

Postgres is implemented using a simple "process per-user" client/server model. In this model there is one client process connected to exactly one server process. As we don't know per se how many connections will be made, we have to use a master process that spawns a new server process every time a connection is requested. This master process is called postmaster and listens at a specified TCP/IP port for incoming connections. Whenever a request for a connection is detected the postmaster process spawns a new server process called postgres. The server tasks (postgres processes) communicate with each other using semaphores and shared memory to ensure data integrity throughout concurrent data access. Figure \ref{connection} illustrates the interaction of the master process postmaster the server process postgres and a client application.

Postgres は単純な「ユーザ毎のプロセス」での クライアント・サーバモデルを導入しています。 このモデルでは、正確に 一つのサーバプロセスに接続する一つの クライアントプロセスが存在します。 それ自体がいくつの接続を張るのか解らないため、接続が要求される 毎にサーバプロセスを幾つも生成する 主プロセスを使う必要が あります。 このマスタプロセスは postmaster と 呼ばれ、接続要求の入ってくる特定の TCP/IP ポートを監視(リッスン)します。 接続要求が検出されると直ちに postmaster プロセス は postgres と呼ばれる新規サーバプロセスを 生成します。 サーバタスク(postgres プロセス)は、同時に並行して 実行されているデータアクセス全般にわたって、データの保全を確保するた め セマフォおよび 共有メモリ 方式でお互いに通信します。 図 \ref{connection} は postmaster 主プロセスと postgres サーバプロセス、およびクライアント アプリケーションの相互作用を示したものです。

The client process can either be the psql frontend (for interactive SQL queries) or any user application implemented using the libpg library. Note that applications implemented using ecpg (the Postgres embedded SQL preprocessor for C) also use this library.

クライアントプロセスは(インタラクティブな SQL による問合せによる) psql フロントエンドまたは、 libpg ライブラリを実装したしたユーザアプリケーション のいずれでもかまいません。 ecpg (C 用 の SQL プリプロセッサが実装された Postgres) を実装したアプリケーションは 同様に、このライブラリを使用することを覚えておいて下さい。

Once a connection is established the client process can send a query to the backend (server). The query is transmitted using plain text, i.e. there is no parsing done in the frontend (client). The server parses the query, creates an execution plan, executes the plan and returns the retrieved tuples to the client by transmitting them over the established connection.

接続が完了した時点で、クライアントプロセスは バックエンド(サーバ)に対して問合せを送る 事が出来ます。問合せは平文で送られますの。ということは フロントエンド(クライアント)側では問合せの 解析をしません。サーバは問合せを解析し、 実行プラン を作成し、そのプラン を実行して抽出されたタプルを、確立された接続を通じてクライアントに 返します。