mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Add new GUC reserved_connections.
This provides a way to reserve connection slots for non-superusers. The slots reserved via the new GUC are available only to users who have the new predefined role pg_use_reserved_connections. superuser_reserved_connections remains as a final reserve in case reserved_connections has been exhausted. Patch by Nathan Bossart. Reviewed by Tushar Ahuja and by me. Discussion: http://postgr.es/m/20230119194601.GA4105788@nathanxps13
This commit is contained in:
@@ -205,14 +205,24 @@ char *ListenAddresses;
|
||||
|
||||
/*
|
||||
* SuperuserReservedConnections is the number of backends reserved for
|
||||
* superuser use. This number is taken out of the pool size given by
|
||||
* MaxConnections so number of backend slots available to non-superusers is
|
||||
* (MaxConnections - SuperuserReservedConnections). Note what this really
|
||||
* means is "if there are <= SuperuserReservedConnections connections
|
||||
* available, only superusers can make new connections" --- pre-existing
|
||||
* superuser connections don't count against the limit.
|
||||
* superuser use, and ReservedConnections is the number of backends reserved
|
||||
* for use by roles with privileges of the pg_use_reserved_connections
|
||||
* predefined role. These are taken out of the pool of MaxConnections backend
|
||||
* slots, so the number of backend slots available for roles that are neither
|
||||
* superuser nor have privileges of pg_use_reserved_connections is
|
||||
* (MaxConnections - SuperuserReservedConnections - ReservedConnections).
|
||||
*
|
||||
* If the number of remaining slots is less than or equal to
|
||||
* SuperuserReservedConnections, only superusers can make new connections. If
|
||||
* the number of remaining slots is greater than SuperuserReservedConnections
|
||||
* but less than or equal to
|
||||
* (SuperuserReservedConnections + ReservedConnections), only superusers and
|
||||
* roles with privileges of pg_use_reserved_connections can make new
|
||||
* connections. Note that pre-existing superuser and
|
||||
* pg_use_reserved_connections connections don't count against the limits.
|
||||
*/
|
||||
int SuperuserReservedConnections;
|
||||
int ReservedConnections;
|
||||
|
||||
/* The socket(s) we're listening to. */
|
||||
#define MAXLISTEN 64
|
||||
@@ -908,11 +918,12 @@ PostmasterMain(int argc, char *argv[])
|
||||
/*
|
||||
* Check for invalid combinations of GUC settings.
|
||||
*/
|
||||
if (SuperuserReservedConnections >= MaxConnections)
|
||||
if (SuperuserReservedConnections + ReservedConnections >= MaxConnections)
|
||||
{
|
||||
write_stderr("%s: superuser_reserved_connections (%d) must be less than max_connections (%d)\n",
|
||||
write_stderr("%s: superuser_reserved_connections (%d) plus reserved_connections (%d) must be less than max_connections (%d)\n",
|
||||
progname,
|
||||
SuperuserReservedConnections, MaxConnections);
|
||||
SuperuserReservedConnections, ReservedConnections,
|
||||
MaxConnections);
|
||||
ExitPostmaster(1);
|
||||
}
|
||||
if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
|
||||
|
||||
Reference in New Issue
Block a user