From 40c70656b47de156e06f1072739006f2320f1fa1 Mon Sep 17 00:00:00 2001 From: Nitin Jadhav Date: Sun, 18 Oct 2026 07:06:43 +0000 Subject: [PATCH] Fix recovery connection detail in EXEC_BACKEND builds When a connection is rejected after recovery has reached consistency but before a hot standby snapshot is ready, backend startup uses reachedConsistency to choose the error detail. Forked backends inherit this value from the postmaster, but EXEC_BACKEND processes do not. Consequently, they incorrectly report that consistent recovery state has not been reached. Restore CAC_NOTCONSISTENT and have the postmaster distinguish it from CAC_NOTHOTSTANDBY before launching the backend. This allows the backend to select the appropriate error detail directly from CAC_state, without relying on inherited process-local state. --- src/backend/postmaster/postmaster.c | 6 +++++- src/backend/tcop/backend_startup.c | 17 +++++++++-------- src/include/tcop/backend_startup.h | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index f53aa9c404d..3b9a9e46f77 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1851,7 +1851,11 @@ canAcceptConnections(BackendType backend_type) else if (!FatalError && pmState == PM_STARTUP) return CAC_STARTUP; /* normal startup */ else if (!FatalError && pmState == PM_RECOVERY) - return CAC_NOTHOTSTANDBY; /* not yet ready for hot standby */ + { + if (EnableHotStandby && reachedConsistency) + return CAC_NOTHOTSTANDBY; + return CAC_NOTCONSISTENT; + } else return CAC_RECOVERY; /* else must be crash recovery */ } diff --git a/src/backend/tcop/backend_startup.c b/src/backend/tcop/backend_startup.c index 912ad7dc957..323855b8792 100644 --- a/src/backend/tcop/backend_startup.c +++ b/src/backend/tcop/backend_startup.c @@ -308,25 +308,26 @@ BackendInitialize(ClientSocket *client_sock, CAC_state cac) (errcode(ERRCODE_CANNOT_CONNECT_NOW), errmsg("the database system is starting up"))); break; - case CAC_NOTHOTSTANDBY: + case CAC_NOTCONSISTENT: if (!EnableHotStandby) ereport(FATAL, (errcode(ERRCODE_CANNOT_CONNECT_NOW), errmsg("the database system is not accepting connections"), errdetail("Hot standby mode is disabled."))); - else if (reachedConsistency) - ereport(FATAL, - (errcode(ERRCODE_CANNOT_CONNECT_NOW), - errmsg("the database system is not yet accepting connections"), - errdetail("Recovery snapshot is not yet ready for hot standby."), - errhint("To enable hot standby, close write transactions with more than %d subtransactions on the primary server.", - PGPROC_MAX_CACHED_SUBXIDS))); else ereport(FATAL, (errcode(ERRCODE_CANNOT_CONNECT_NOW), errmsg("the database system is not yet accepting connections"), errdetail("Consistent recovery state has not been yet reached."))); break; + case CAC_NOTHOTSTANDBY: + ereport(FATAL, + (errcode(ERRCODE_CANNOT_CONNECT_NOW), + errmsg("the database system is not yet accepting connections"), + errdetail("Recovery snapshot is not yet ready for hot standby."), + errhint("To enable hot standby, close write transactions with more than %d subtransactions on the primary server.", + PGPROC_MAX_CACHED_SUBXIDS))); + break; case CAC_SHUTDOWN: ereport(FATAL, (errcode(ERRCODE_CANNOT_CONNECT_NOW), diff --git a/src/include/tcop/backend_startup.h b/src/include/tcop/backend_startup.h index d486f926319..ebf083dedfd 100644 --- a/src/include/tcop/backend_startup.h +++ b/src/include/tcop/backend_startup.h @@ -36,6 +36,7 @@ typedef enum CAC_state CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, + CAC_NOTCONSISTENT, CAC_NOTHOTSTANDBY, CAC_TOOMANY, } CAC_state; -- 2.43.0