[PATCH] Fix recovery connection detail in EXEC_BACKEND builds
[PATCH] Fix recovery connection detail in EXEC_BACKEND builds
Hi, The recent discussion about reachedConsistency in [1] mentioned a separate EXEC_BACKEND issue. When a connection is rejected after recovery has reached consistency but before a hot standby snapshot is ready, backend startup uses reachedConsistency to select the error detail. On Unix systems using fork(), the backend inherits reachedConsistency from the postmaster. In EXEC_BACKEND builds, this process-local variable is not inherited by the backend. Consequently, it reports: DETAIL: Consistent recovery state has not been yet reached. instead of: DETAIL: Recovery snapshot is not yet ready for hot standby. It also omits the associated hint about transactions with more than 64 subtransactions. The attached patch passes reachedConsistency through BackendStartupData, alongside canAcceptConnections, and uses the captured value when choosing the connection error detail. This only changes the reported DETAIL and HINT; connection acceptance and recovery behavior are unaffected. I tested this on Linux with both normal and EXEC_BACKEND builds. The core regression tests passed under EXEC_BACKEND, and manual testing confirmed the expected DETAIL and HINT. I have not tested it on Windows. Please review and share your feedback. [1]: https://www.postgresql.org/message-id/flat/CA%2BUBoq2n2Zg9rKgMfUtUohzGssisF9cDeyjKqPrnRNFprEyX1Q%40mail.gmail.com Best Regards, Nitin Jadhav Microsoft
Re: [PATCH] Fix recovery connection detail in EXEC_BACKEND builds
От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
On 12/10/2026 10:14, Nitin Jadhav wrote: > The attached patch passes reachedConsistency through > BackendStartupData, alongside canAcceptConnections, and uses the > captured value when choosing the connection error detail. This only > changes the reported DETAIL and HINT; connection acceptance and > recovery behavior are unaffected. That works. But what do you think of adding a new CAC_* code instead? It feels a bit weird to me that we've multiplexed CAC_NOTHOTSTANDBY for many different "sub-reasons". - Heikki
Re: [PATCH] Fix recovery connection detail in EXEC_BACKEND builds
От:
Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Дата:
Hi Heikki, Thanks for reviewing the patch. I had considered adding a separate CAC_* code as well, but since the existing code had already combined these cases under CAC_NOTHOTSTANDBY, I initially chose the smaller change and preserved that structure. I agree that distinguishing the reasons in CAC_state is cleaner. I will restore CAC_NOTCONSISTENT and use CAC_NOTHOTSTANDBY specifically for the case where hot standby is enabled and consistency has been reached, but the recovery snapshot is not yet ready. This would also avoid passing reachedConsistency through BackendStartupData. I will revise the patch accordingly and send a v2 soon. Best Regards, Nitin Jadhav Microsoft
Re: [PATCH] Fix recovery connection detail in EXEC_BACKEND builds
Hi, Attached is v2 of the patch. As suggested by Heikki, this version distinguishes the recovery states using CAC_state instead of passing reachedConsistency separately through BackendStartupData. The patch restores CAC_NOTCONSISTENT and uses CAC_NOTHOTSTANDBY when hot standby is enabled and consistency has been reached, but the recovery snapshot is not yet ready. The backend can therefore select the appropriate DETAIL and HINT directly from CAC_state without relying on inherited process-local state. I tested this on Linux with both normal and EXEC_BACKEND builds, and the tests passed. I have not tested it on Windows. Please review and share your feedback. Best Regards, Nitin Jadhav Microsoft