11
backend
Processes and Memory
client
application
PostgreSQL
postmaster
backend
background processes
shared memory
local
memory
parsed queries,
cursor states,
system catalog cache,
space for sorting,
joining etc.
Between processing queries from clients, the server must store technical
information, such as parsed queries and their plans and the status of open
cursors (portals). Where is it stored and how?
Under the hood, a PostgreSQL server consists of several interacting
processes. First of all, when the server starts, a process traditionally called
postmaster is started. It starts all other processes (using the fork system call
in Unix). It also “babysits” them: if any of the processes crashes, postmaster
will restart it (or restart the entire server if it considers that the failed process
could have damaged any of the shared data).
Operations of the server are maintained by a number of background
processes. The main ones will be discussed in the following lessons.
In order for the processes to exchange information between them,
postmaster allocates shared memory that all the processes can access. In
addition to shared memory, each process has its own local memory,
accessible only to itself.
Postmaster also listens for incoming connections. For each connecting
client, postmaster generates a designated backend process for the client to
communicate with on the server side, and each client gets its own process.
The backend process performs authentication, among other things.
The space required to execute a client’s query (parsed queries and their
plans, cursor states, system catalog cache, a place to sort data, etc.) is
allocated in the local memory of the backend process of this client.