I know the difference between background writer
, checkpointer
, walwriter
, and parallel_worker
:
But I am confused with client backend
. I use opensnoop
and trace
to find that client backend
usually writes (pwrite(2)
) something to both data-file and wal-file.
PID COMM FD ERR PATH
18365 (client backend) postgres 51 0 base/16384/16403
18365 (client backend) postgres 52 0 pg_wal/0000000100000001000000E1
Question
- What is
client backend
responsible for? - At most one
client backend
per connection?
CodePudding user response:
The client backend is the server process that communicates with the client and performs SQL statements on the client's behalf. There is one client backend process for each database session.
However, the client backend process normally should not have to write to the WAL file or the data file: the backend process writes to WAL buffers (a shared memory segment), and the "WAL writer" process is responsible for writing that information to disk. Similarly, the backend normally only writes table data only to chared buffers (the cache), and the "checkpointer" and "background writer" process do most of the actual writing to disk. The design idea here is that the client backend should not be bothered with these potentially slow tasks, but be free to process SQL statements as quickly as possible.
If the WAL writer or the background writer are not fast enough to cope with the workload, it can happen that the backend process has to do some of the writing. This should not happen regularly, but only during spikes in data modification activity. Often, that is an indication that you can improve the performance of your SQL statements if you increase the size of WAL buffers and shared buffers.