diff options
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/init/globals.c | 1 | ||||
-rw-r--r-- | src/backend/utils/init/miscinit.c | 6 | ||||
-rw-r--r-- | src/backend/utils/init/postinit.c | 13 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 15 |
4 files changed, 27 insertions, 8 deletions
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index 4b66bd3e358..8dd2b4b1234 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -87,6 +87,7 @@ pid_t PostmasterPid = 0; bool IsPostmasterEnvironment = false; bool IsUnderPostmaster = false; bool IsBinaryUpgrade = false; +bool IsBackgroundWorker = false; bool ExitOnAnyError = false; diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 5288aa77ee1..c518c2133cd 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -498,10 +498,10 @@ void InitializeSessionUserIdStandalone(void) { /* - * This function should only be called in single-user mode and in - * autovacuum workers. + * This function should only be called in single-user mode, in + * autovacuum workers, and in background workers. */ - AssertState(!IsUnderPostmaster || IsAutoVacuumWorkerProcess()); + AssertState(!IsUnderPostmaster || IsAutoVacuumWorkerProcess() || IsBackgroundWorker); /* call only once */ AssertState(!OidIsValid(AuthenticatedUserId)); diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 2eb456df45e..b87ec6c4822 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -627,6 +627,19 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, errhint("You should immediately run CREATE USER \"%s\" SUPERUSER;.", username))); } + else if (IsBackgroundWorker) + { + if (username == NULL) + { + InitializeSessionUserIdStandalone(); + am_superuser = true; + } + else + { + InitializeSessionUserId(username); + am_superuser = superuser(); + } + } else { /* normal multiuser case */ diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 81cf136937c..2cf34cea5a4 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -52,6 +52,7 @@ #include "parser/scansup.h" #include "pgstat.h" #include "postmaster/autovacuum.h" +#include "postmaster/bgworker.h" #include "postmaster/bgwriter.h" #include "postmaster/postmaster.h" #include "postmaster/syslogger.h" @@ -108,7 +109,8 @@ * removed, we still could not exceed INT_MAX/4 because some places compute * 4*MaxBackends without any overflow check. This is rechecked in * check_maxconnections, since MaxBackends is computed as MaxConnections - * plus autovacuum_max_workers plus one (for the autovacuum launcher). + * plus the number of bgworkers plus autovacuum_max_workers plus one (for the + * autovacuum launcher). */ #define MAX_BACKENDS 0x7fffff @@ -8628,7 +8630,8 @@ show_tcp_keepalives_count(void) static bool check_maxconnections(int *newval, void **extra, GucSource source) { - if (*newval + autovacuum_max_workers + 1 > MAX_BACKENDS) + if (*newval + GetNumShmemAttachedBgworkers() + autovacuum_max_workers + 1 > + MAX_BACKENDS) return false; return true; } @@ -8636,13 +8639,15 @@ check_maxconnections(int *newval, void **extra, GucSource source) static void assign_maxconnections(int newval, void *extra) { - MaxBackends = newval + autovacuum_max_workers + 1; + MaxBackends = newval + autovacuum_max_workers + 1 + + GetNumShmemAttachedBgworkers(); } static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source) { - if (MaxConnections + *newval + 1 > MAX_BACKENDS) + if (MaxConnections + *newval + 1 + GetNumShmemAttachedBgworkers() > + MAX_BACKENDS) return false; return true; } @@ -8650,7 +8655,7 @@ check_autovacuum_max_workers(int *newval, void **extra, GucSource source) static void assign_autovacuum_max_workers(int newval, void *extra) { - MaxBackends = MaxConnections + newval + 1; + MaxBackends = MaxConnections + newval + 1 + GetNumShmemAttachedBgworkers(); } static bool |