Hi hackers, A standby can continue to promote after pg_promote() or pg_ctl stops waiting. An HA controller can still see read-only queries succeed and pg_is_in_recovery() return true after startup has removed standby.signal. If it takes those observations as proof the standby will stay read-only, it can make another server writable while this one finishes promotion.
The first patch clarifies the timeout and restart behavior. The second adds recovery_end_state and new_timeline to pg_stat_recovery. It publishes the timeline switch immediately before removing the recovery signal files so that observers can treat the switch as potentially effective as soon as restart behavior can change. The third patch logs the duration of slow steps such as writing the timeline history, running recovery_end_command, and updating logical decoding status. The step duration is available on completion. A wait event can show where startup is blocked in the meantime. Separate local testing with injection points on PostgreSQL 20devel reproduced both the SQL and pg_ctl wait timeouts. An immediate restart before the switch resumed as a standby. An immediate restart at promotion-after-wal-segment-cleanup brought up a writable primary on timeline 2, although the last SQL probe before the stop still reported recovery and read-only transactions. The assertion-enabled Meson build passed the setup, core regression, and recovery suites on arm64 macOS. The new TAP tests also passed in a build with injection points disabled, with the injected assertions skipped. Both HTML and man-page documentation built successfully. The catalog change in the second patch needs a catversion bump at commit time. Two related discussions are the original pg_stat_recovery proposal and the report of promotion waiting for ProcSignalBarrier [1, 2]. Discussion of whether startup should be able to withdraw a pending promotion belongs in a separate RFC. [1] https://www.postgresql.org/message-id/cabptf7w%2bnody-%2bp9y4pnk37-qwulpfureonhuehrx%2bvx9kq%[email protected] [2] https://www.postgresql.org/message-id/cahgqgwhjwasrh%[email protected] I would welcome feedback on the state names and when the view reports the timeline switch. Would new_tli be a better fit alongside the existing last_replayed_tli and replay_end_tli columns? This series is based on master at 9b5d4e3331753b3399e84965093109cac8f364bf and is intended for the next CommitFest. Thanks, Goutham Reddy Aenugu
v1-0003-Log-the-duration-of-slow-end-of-recovery-steps.patch
Description: Binary data
v1-0002-Expose-end-of-recovery-progress-in-pg_stat_recove.patch
Description: Binary data
v1-0001-Clarify-what-a-standby-promotion-timeout-means.patch
Description: Binary data
