I'm trying to better understand Checkpoint internals, specifically in PostgreSQL.
My current understanding is that Crash Recovery will always start from the latest REDO location that is marked when a Checkpoint starts. Data in all WAL records before the REDO location are guaranteed to be on disk (in data files), and those WAL records are no longer needed.
I'm having a hard time understanding the following:
1) How is the REDO location determined exactly. When a Checkpoint starts, does it literally say "REDO location is the current WAL record + 1"?
2) When we do determine the REDO location, how is it that we are guaranteed that all WAL records before this are no longer needed?
Specifically, how is the following scenario handled:
- Checkpoint 1 runs and writes out dirty page A to disk.
- Dirty page A then has new rows inserted
- Checkpoint 1 finishes
- Checkpoint 2 starts and determines REDO location.
How can Checkpoint 2 be sure that all previous data is written to disk if pages can be dirtied after Checkpoint 1 flushes them, is the gist of the question.