Hi Shihao, I tested v2 on master (cassert build) by restarting a crashed primary as a standby of its promoted standby, counting the DEBUG2 "updated min recovery point" messages per process after "entering archive recovery", and scanning the page LSNs on disk after an immediate stop.
Without the fix, the checkpointer never advances minRecoveryPoint after the switch, whether the restartpoints during crash recovery were skipped or real. With v2 the checkpointer kept advancing minRecoveryPoint after the switch with 9 updates during the restartpoints in that run, and 13 in a second run (2 during its one real restartpoint, 11 from the forced update on skipped restartpoints), against 0 on master in both runs. The scan of pages on disk was clean. The bgwriter has the same problem with a tiny shared_buffers and no restartpoints, master's bgwriter made 0 updates after the switch, v2's made 25. v2 fixes it too, but the commit message and the test only mention the checkpointer, so it might be worth saying the fix covers any process other than the startup process. Regarding Fujii's ordering question, the new 016 test failed 5/5 with the server change reverted and passed 3/3 with it, so in practice it catches the bug, even if the ordering isn't guaranteed. The full recovery and pg_rewind suites pass. Starting the crashed primary with recovery.signal behaves the same with and without the patch. The bug goes back to 7ff23c6d277, so it needs back-patching to 15. v2 applies cleanly to REL_19_STABLE; 15–18 only need XLogRecPtrIsValid() changed to !XLogRecPtrIsInvalid(). Overall v2 looks good to me. Regards, Surya Poondla
