3
Client and Server
connection authentication
generating queries executing queries
managing transactions supporting transactions
protocol
PostgreSQL
Python client
psycopg2
Java client
JDBC
SQL client
libpq
A client application, such as psql or any other application written in any
programming language, connects to the server and communicates with it
somehow. To understand each other, both the client and the server must
use the same interfacing protocol. The client usually uses a driver that
implements the protocol and provides a set of features to be used in the
application. The driver can use the standard libpq library or provide a
custom implementation of the protocol.
The programming language of the application is not that important—different
syntactic structures implement the same features defined by the protocol. In
our examples, we are going to use the SQL language and the psql client. It’s
clear that no one writes the frontend in SQL, but it is convenient for training
purposes. We expect that it will not be hard for you to compare SQL
commands with the capabilities of your favorite language.
Speaking very roughly, the protocol enables the client to connect to one of
the databases of a database cluster. At this point, the server performs
authentication: it decides whether to allow this connection, for example, by
asking for password.
Then the client sends SQL queries to the server, and the server executes
these queries and returns the results. Having a powerful and user-friendly
query language is one of distinctive features of relational database systems.
Another one is ensuring data consistency.