@@ -2281,49 +2281,6 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
22812281 */
22822282 MemoryContextSwitchTo (oldcontext );
22832283
2284- /*
2285- * If we're going to reject the connection due to database state, say so
2286- * now instead of wasting cycles on an authentication exchange. (This also
2287- * allows a pg_ping utility to be written.)
2288- */
2289- switch (port -> canAcceptConnections )
2290- {
2291- case CAC_STARTUP :
2292- ereport (FATAL ,
2293- (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
2294- errmsg ("the database system is starting up" )));
2295- break ;
2296- case CAC_NOTCONSISTENT :
2297- if (EnableHotStandby )
2298- ereport (FATAL ,
2299- (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
2300- errmsg ("the database system is not yet accepting connections" ),
2301- errdetail ("Consistent recovery state has not been yet reached." )));
2302- else
2303- ereport (FATAL ,
2304- (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
2305- errmsg ("the database system is not accepting connections" ),
2306- errdetail ("Hot standby mode is disabled." )));
2307- break ;
2308- case CAC_SHUTDOWN :
2309- ereport (FATAL ,
2310- (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
2311- errmsg ("the database system is shutting down" )));
2312- break ;
2313- case CAC_RECOVERY :
2314- ereport (FATAL ,
2315- (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
2316- errmsg ("the database system is in recovery mode" )));
2317- break ;
2318- case CAC_TOOMANY :
2319- ereport (FATAL ,
2320- (errcode (ERRCODE_TOO_MANY_CONNECTIONS ),
2321- errmsg ("sorry, too many clients already" )));
2322- break ;
2323- case CAC_OK :
2324- break ;
2325- }
2326-
23272284 return STATUS_OK ;
23282285}
23292286
@@ -4360,6 +4317,49 @@ BackendInitialize(Port *port)
43604317 */
43614318 status = ProcessStartupPacket (port , false, false);
43624319
4320+ /*
4321+ * If we're going to reject the connection due to database state, say so
4322+ * now instead of wasting cycles on an authentication exchange. (This also
4323+ * allows a pg_ping utility to be written.)
4324+ */
4325+ switch (port -> canAcceptConnections )
4326+ {
4327+ case CAC_STARTUP :
4328+ ereport (FATAL ,
4329+ (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
4330+ errmsg ("the database system is starting up" )));
4331+ break ;
4332+ case CAC_NOTCONSISTENT :
4333+ if (EnableHotStandby )
4334+ ereport (FATAL ,
4335+ (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
4336+ errmsg ("the database system is not yet accepting connections" ),
4337+ errdetail ("Consistent recovery state has not been yet reached." )));
4338+ else
4339+ ereport (FATAL ,
4340+ (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
4341+ errmsg ("the database system is not accepting connections" ),
4342+ errdetail ("Hot standby mode is disabled." )));
4343+ break ;
4344+ case CAC_SHUTDOWN :
4345+ ereport (FATAL ,
4346+ (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
4347+ errmsg ("the database system is shutting down" )));
4348+ break ;
4349+ case CAC_RECOVERY :
4350+ ereport (FATAL ,
4351+ (errcode (ERRCODE_CANNOT_CONNECT_NOW ),
4352+ errmsg ("the database system is in recovery mode" )));
4353+ break ;
4354+ case CAC_TOOMANY :
4355+ ereport (FATAL ,
4356+ (errcode (ERRCODE_TOO_MANY_CONNECTIONS ),
4357+ errmsg ("sorry, too many clients already" )));
4358+ break ;
4359+ case CAC_OK :
4360+ break ;
4361+ }
4362+
43634363 /*
43644364 * Disable the timeout, and prevent SIGTERM again.
43654365 */
0 commit comments