2 51.2. How Connections Are Established #
4 PostgreSQL implements a “process per user” client/server model. In this
5 model, every client process connects to exactly one backend process. As
6 we do not know ahead of time how many connections will be made, we have
7 to use a “supervisor process” that spawns a new backend process every
8 time a connection is requested. This supervisor process is called
9 postmaster and listens at a specified TCP/IP port for incoming
10 connections. Whenever it detects a request for a connection, it spawns
11 a new backend process. Those backend processes communicate with each
12 other and with other processes of the instance using semaphores and
13 shared memory to ensure data integrity throughout concurrent data
16 The client process can be any program that understands the PostgreSQL
17 protocol described in Chapter 54. Many clients are based on the
18 C-language library libpq, but several independent implementations of
19 the protocol exist, such as the Java JDBC driver.
21 Once a connection is established, the client process can send a query
22 to the backend process it's connected to. The query is transmitted
23 using plain text, i.e., there is no parsing done in the client. The
24 backend process parses the query, creates an execution plan, executes
25 the plan, and returns the retrieved rows to the client by transmitting
26 them over the established connection.