diff options
| author | Robert Haas <rhaas@postgresql.org> | 2023-01-20 15:36:36 -0500 |
|---|---|---|
| committer | Robert Haas <rhaas@postgresql.org> | 2023-01-20 15:39:13 -0500 |
| commit | 6e2775e4d4e47775f0d933e4a93c148024a3bc63 (patch) | |
| tree | 41a9343dad0b900d899ebd04e9d22afd7976768f /src/backend/storage/lmgr/proc.c | |
| parent | fe00fec1f5d78a5cfe46ac72dc284ed4cc477be1 (diff) | |
| download | postgresql-6e2775e4d4e47775f0d933e4a93c148024a3bc63.tar.gz | |
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
Diffstat (limited to 'src/backend/storage/lmgr/proc.c')
| -rw-r--r-- | src/backend/storage/lmgr/proc.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index f8ac4edd6f..22b4278610 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -645,27 +645,33 @@ GetStartupBufferPinWaitBufId(void) } /* - * Check whether there are at least N free PGPROC objects. + * Check whether there are at least N free PGPROC objects. If false is + * returned, *nfree will be set to the number of free PGPROC objects. + * Otherwise, *nfree will be set to n. * * Note: this is designed on the assumption that N will generally be small. */ bool -HaveNFreeProcs(int n) +HaveNFreeProcs(int n, int *nfree) { dlist_iter iter; + Assert(n > 0); + Assert(nfree); + SpinLockAcquire(ProcStructLock); + *nfree = 0; dlist_foreach(iter, &ProcGlobal->freeProcs) { - n--; - if (n == 0) + (*nfree)++; + if (*nfree == n) break; } SpinLockRelease(ProcStructLock); - return (n <= 0); + return (*nfree == n); } /* |
