Skip to content

Commit df93844

Browse files
committed
Improve connection denied error message during recovery.
Previously when an archive recovery or a standby was starting and reached the consistent recovery state but hot_standby was configured to off, the error message when a client connectted was "the database system is starting up", which was needless confusing and not really all that accurate either. This commit improves the connection denied error message during recovery, as follows, so that the users immediately know that their servers are configured to deny those connections. - If hot_standby is disabled, the error message "the database system is not accepting connections" and the detail message "Hot standby mode is disabled." are output when clients connect while an archive recovery or a standby is running. - If hot_standby is enabled, the error message "the database system is not yet accepting connections" and the detail message "Consistent recovery state has not been yet reached." are output when clients connect until the consistent recovery state is reached and postmaster starts accepting read only connections. This commit doesn't change the connection denied error message of "the database system is starting up" during normal server startup and crash recovery. Because it's still suitable for those situations. Author: James Coleman Reviewed-by: Alvaro Herrera, Andres Freund, David Zhang, Tom Lane, Fujii Masao Discussion: https://postgr.es/m/CAAaqYe8h5ES_B=F_zDT+Nj9XU7YEwNhKhHA2RE4CFhAQ93hfig@mail.gmail.com
1 parent b34ca59 commit df93844

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,18 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
22942294
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
22952295
errmsg("the database system is starting up")));
22962296
break;
2297+
case CAC_NOTCONSISTENT:
2298+
if (EnableHotStandby)
2299+
ereport(FATAL,
2300+
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
2301+
errmsg("the database system is not yet accepting connections"),
2302+
errdetail("Consistent recovery state has not been yet reached.")));
2303+
else
2304+
ereport(FATAL,
2305+
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
2306+
errmsg("the database system is not accepting connections"),
2307+
errdetail("Hot standby mode is disabled.")));
2308+
break;
22972309
case CAC_SHUTDOWN:
22982310
ereport(FATAL,
22992311
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
@@ -2435,10 +2447,11 @@ canAcceptConnections(int backend_type)
24352447
{
24362448
if (Shutdown > NoShutdown)
24372449
return CAC_SHUTDOWN; /* shutdown is pending */
2438-
else if (!FatalError &&
2439-
(pmState == PM_STARTUP ||
2440-
pmState == PM_RECOVERY))
2450+
else if (!FatalError && pmState == PM_STARTUP)
24412451
return CAC_STARTUP; /* normal startup */
2452+
else if (!FatalError && pmState == PM_RECOVERY)
2453+
return CAC_NOTCONSISTENT; /* not yet at consistent recovery
2454+
* state */
24422455
else
24432456
return CAC_RECOVERY; /* else must be crash recovery */
24442457
}

src/include/libpq/libpq-be.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ typedef struct
7070

7171
typedef enum CAC_state
7272
{
73-
CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY,
73+
CAC_OK,
74+
CAC_STARTUP,
75+
CAC_SHUTDOWN,
76+
CAC_RECOVERY,
77+
CAC_NOTCONSISTENT,
78+
CAC_TOOMANY,
7479
CAC_SUPERUSER
7580
} CAC_state;
7681

0 commit comments

Comments
 (0)