Chin
Chin

Reputation: 20665

Postgres terminology: client vs connection

In Postgres, is there a one-to-one relationship between a client and a connection? In other word, is a client always one connection and no client can open more than one connection?

For example, when Postgres says:

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already.

is that equivalent to "too many connections already"?

Also, as far as I understand, Postgres uses one process for each client. So does this mean that each process is used for one connection only?

Upvotes: 0

Views: 963

Answers (2)

Gurwinder Singh
Gurwinder Singh

Reputation: 39457

Refer - https://www.postgresql.org/docs/9.6/static/connect-estab.html

PostgreSQL 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 do not know ahead of time 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.

So yes, one server process serves one connection.

Upvotes: 1

Patrick
Patrick

Reputation: 32179

You can have as many connections from a single client (machine, application) as the server can manage. The server can support a given number of connections, whether or not these come from different clients (machine, application) is irrelevant to the server.

The connection is made to the postmaster process that is listening on the port that PG is configured to listen to (5432 by default). When a connection is established (after authentication), the server spawns a process which is used exclusively by a single client. That client can make multiple connections to the same server, for instance to connect to different databases, or the same database using different credentials, etc.

Upvotes: 0

Related Questions