From 5c4506dcfe9bb9511006b044513fa3f1c7f5a912 Mon Sep 17 00:00:00 2001 From: Nitin Jadhav Date: Mon, 12 Oct 2026 06:26:49 +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 because the value is not explicitly transferred. Consequently, they incorrectly report that consistent recovery state has not been reached. Pass the consistency state through BackendStartupData and use the captured value when choosing the connection error detail. --- src/backend/postmaster/postmaster.c | 3 ++- src/backend/tcop/backend_startup.c | 10 ++++++---- src/include/tcop/backend_startup.h | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index f53aa9c404d..6603e1539eb 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -3640,8 +3640,9 @@ BackendStartup(ClientSocket *client_sock) } } - /* Pass down canAcceptConnections state */ + /* Pass down the state used to handle connection acceptance. */ startup_data.canAcceptConnections = cac; + startup_data.reachedConsistency = reachedConsistency; bn->rw = NULL; /* Hasn't asked to be notified about any bgworkers yet */ diff --git a/src/backend/tcop/backend_startup.c b/src/backend/tcop/backend_startup.c index 912ad7dc957..1e003380a2e 100644 --- a/src/backend/tcop/backend_startup.c +++ b/src/backend/tcop/backend_startup.c @@ -18,7 +18,6 @@ #include #include "access/xlog.h" -#include "access/xlogrecovery.h" #include "common/ip.h" #include "common/string.h" #include "libpq/libpq.h" @@ -57,7 +56,8 @@ char *log_connections_string = NULL; */ ConnectionTiming conn_timing = {.ready_for_use = TIMESTAMP_MINUS_INFINITY}; -static void BackendInitialize(ClientSocket *client_sock, CAC_state cac); +static void BackendInitialize(ClientSocket *client_sock, CAC_state cac, + bool reachedConsistency); static int ProcessSSLStartup(Port *port); static int ProcessStartupPacket(Port *port); static void ProcessCancelRequestPacket(Port *port, void *pkt, int pktlen); @@ -107,7 +107,8 @@ BackendMain(const void *startup_data, size_t startup_data_len) #endif /* Perform additional initialization and collect startup packet */ - BackendInitialize(MyClientSocket, bsdata->canAcceptConnections); + BackendInitialize(MyClientSocket, bsdata->canAcceptConnections, + bsdata->reachedConsistency); /* * Create a per-backend PGPROC struct in shared memory. We must do this @@ -138,7 +139,8 @@ BackendMain(const void *startup_data, size_t startup_data_len) * but have not yet set up most of our local pointers to shmem structures. */ static void -BackendInitialize(ClientSocket *client_sock, CAC_state cac) +BackendInitialize(ClientSocket *client_sock, CAC_state cac, + bool reachedConsistency) { int status; int ret; diff --git a/src/include/tcop/backend_startup.h b/src/include/tcop/backend_startup.h index d486f926319..1b9acf59a6f 100644 --- a/src/include/tcop/backend_startup.h +++ b/src/include/tcop/backend_startup.h @@ -44,6 +44,7 @@ typedef enum CAC_state typedef struct BackendStartupData { CAC_state canAcceptConnections; + bool reachedConsistency; /* * Time at which the connection client socket is created. Only used for -- 2.43.0