What does a checkpoint do, and how do you choose how often to take one?
Sketch your own answer first, then compare it with the one below.
A strong answer
A checkpoint writes the dirty pages in memory to the data file and records a point in the log. Recovery then only needs to replay the log from that point, and older log can be recycled.
Checkpoint rarely and you write fewer pages, because a hot page that changed a hundred times is written once. The cost is a long replay after a crash and a large log. Checkpoint often and recovery is quick, but you write pages more often and may produce bursts of I/O that hurt query latency.
A good answer mentions spreading the writes out over the interval so they do not arrive in a spike, and sizing the interval from the recovery time the service can tolerate.
Sources
- PostgreSQL Global Development Group (2024). Write-Ahead Logging (WAL).
- C. Mohan, Don Haderle, Bruce Lindsay, Hamid Pirahesh, Peter Schwarz (1992). ARIES: A Transaction Recovery Method Supporting Fine-Granularity Locking and Partial Rollbacks Using Write-Ahead Logging.