I'm a bit confused with checkpoint_segments definition in PostgreSQL documentation. What happens when checkpoint_segments reached?
- The dirty pages in shared_buffers written to WAL. Then what is the
usage of background writer? - WAL is merged to actual data files.
Best Answer
Combing through the docs, I see the following (accidental incorrect details will hopefully (or surely) be pointed out by others):
BW does its work according to its config parameters. It writes at most
bgwriter_lru_maxpages
dirty shared buffers, then has abgwriter_delay
millisecond rest. Now, when it comes tocheckpoint_segments
log segments (orcheckpoint_timeout
seconds, if it comes first), it flushes all (remaining) dirty segments to data files. Now the database data has a consistent state on disk, with a corresponding entry in the log as well. It is a good starting point for a subsequent REDO if necessary.And who does make the checkpoints?
As for your 2nd point, WAL is WAL (stored in log segment files) and data files are data files. The two will be consistent with each other but not merged.