3
Client and server
connection authentication
query generation query execution
transaction management transactionality control
protocol
PostgreSQL
Python client
psycopg2
Java client
JDBC
SQL client
libpq
A client application, such as psql or any other program written in any
programming language, connects to the server and "communicates" with it
in one way or another. In order for the client and the server to understand
each other, they must use the same communication protocol. Usually, the
client uses a driver that implements the protocol and provides a set of
functions to use in the program. Internally, the driver can use the standard
protocol implementation (the libpq library), or can implement the protocol
itself.
The language the client is written in is unimportant, as the functionality
behind the syntax is defined by the protocol. As an example, we will use the
SQL language and the psql client. Of course, no one really would program a
client in SQL, but we will use it here purely for educational purposes. It
should not be that difficult to substitute any of the SQL commands provided
below with corresponding statements in your programming language of
choice.
Generally speaking, a connection protocol allows the client to connect to a
database in a cluster. The server performs authentication: decides if the
client should be allowed to connect, i.e. by demanding a password.
Then, the client sends the server queries in the SQL language, the server
executes the queries and sends back the results. A powerful and convenient
query language is one of the fundamentals of relational databases.
Another one is the ability to maintain consistency between transactions.