mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Move canAcceptConnections check from ProcessStartupPacket to caller.
The check is not about processing the startup packet, so the calling function seems like a more natural place. I'm also working on a patch that moves 'canAcceptConnections' out of the Port struct, and this makes that refactoring more convenient. Reviewed-by: Tristan Partin Discussion: https://www.postgresql.org/message-id/7a59b073-5b5b-151e-7ed3-8b01ff7ce9ef@iki.fi
This commit is contained in:
parent
c7c801ef3b
commit
16671ba6e7
@ -2281,49 +2281,6 @@ retry1:
|
|||||||
*/
|
*/
|
||||||
MemoryContextSwitchTo(oldcontext);
|
MemoryContextSwitchTo(oldcontext);
|
||||||
|
|
||||||
/*
|
|
||||||
* If we're going to reject the connection due to database state, say so
|
|
||||||
* now instead of wasting cycles on an authentication exchange. (This also
|
|
||||||
* allows a pg_ping utility to be written.)
|
|
||||||
*/
|
|
||||||
switch (port->canAcceptConnections)
|
|
||||||
{
|
|
||||||
case CAC_STARTUP:
|
|
||||||
ereport(FATAL,
|
|
||||||
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
|
||||||
errmsg("the database system is starting up")));
|
|
||||||
break;
|
|
||||||
case CAC_NOTCONSISTENT:
|
|
||||||
if (EnableHotStandby)
|
|
||||||
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.")));
|
|
||||||
else
|
|
||||||
ereport(FATAL,
|
|
||||||
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
|
||||||
errmsg("the database system is not accepting connections"),
|
|
||||||
errdetail("Hot standby mode is disabled.")));
|
|
||||||
break;
|
|
||||||
case CAC_SHUTDOWN:
|
|
||||||
ereport(FATAL,
|
|
||||||
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
|
||||||
errmsg("the database system is shutting down")));
|
|
||||||
break;
|
|
||||||
case CAC_RECOVERY:
|
|
||||||
ereport(FATAL,
|
|
||||||
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
|
||||||
errmsg("the database system is in recovery mode")));
|
|
||||||
break;
|
|
||||||
case CAC_TOOMANY:
|
|
||||||
ereport(FATAL,
|
|
||||||
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
|
|
||||||
errmsg("sorry, too many clients already")));
|
|
||||||
break;
|
|
||||||
case CAC_OK:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4360,6 +4317,49 @@ BackendInitialize(Port *port)
|
|||||||
*/
|
*/
|
||||||
status = ProcessStartupPacket(port, false, false);
|
status = ProcessStartupPacket(port, false, false);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we're going to reject the connection due to database state, say so
|
||||||
|
* now instead of wasting cycles on an authentication exchange. (This also
|
||||||
|
* allows a pg_ping utility to be written.)
|
||||||
|
*/
|
||||||
|
switch (port->canAcceptConnections)
|
||||||
|
{
|
||||||
|
case CAC_STARTUP:
|
||||||
|
ereport(FATAL,
|
||||||
|
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
||||||
|
errmsg("the database system is starting up")));
|
||||||
|
break;
|
||||||
|
case CAC_NOTCONSISTENT:
|
||||||
|
if (EnableHotStandby)
|
||||||
|
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.")));
|
||||||
|
else
|
||||||
|
ereport(FATAL,
|
||||||
|
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
||||||
|
errmsg("the database system is not accepting connections"),
|
||||||
|
errdetail("Hot standby mode is disabled.")));
|
||||||
|
break;
|
||||||
|
case CAC_SHUTDOWN:
|
||||||
|
ereport(FATAL,
|
||||||
|
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
||||||
|
errmsg("the database system is shutting down")));
|
||||||
|
break;
|
||||||
|
case CAC_RECOVERY:
|
||||||
|
ereport(FATAL,
|
||||||
|
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
||||||
|
errmsg("the database system is in recovery mode")));
|
||||||
|
break;
|
||||||
|
case CAC_TOOMANY:
|
||||||
|
ereport(FATAL,
|
||||||
|
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
|
||||||
|
errmsg("sorry, too many clients already")));
|
||||||
|
break;
|
||||||
|
case CAC_OK:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disable the timeout, and prevent SIGTERM again.
|
* Disable the timeout, and prevent SIGTERM again.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user