Hi, While i working on this reported bug [0], i observed this; currently, if you restore a backup where no WAL follows the shutdown checkpoint, PerformWalRecovery() realizes there is nothing to replay and takes the "redo is not required" path. Because this path bypasses the main WAL replay loop, neither recoveryStopsBefore() nor recoveryStopsAfter() gets called, then if the user requested an 'immediate' recovery target, the server exits with: FATAL: recovery ended before configured recovery target was reached.
This happens even though the cluster is already in a consistent state, it means the 'immediate' target was already reached before replay even started. The attached patch updates the "redo is not required" path to recognize that the server is already consistent and recovery can stop if the target is immediate. To implement this cleanly, I could not just skip the error, as the server must still do the recovery_target_action. To avoid duplicating that logic, I moved the target action handling code out of the main loop and into a new helper function called PerformRecoveryTargetAction(), this also adds a TAP test; thoughts? [0] - https://www.postgresql.org/message-id/flat/19897-60cf65e39604f958%40postgresql.org -- Thanks :) Srinath Reddy Sadipiralla EDB: https://www.enterprisedb.com/
V1-0001-Treat-an-immediate-recovery-target-as-reached-whe.patch
Description: Binary data
