Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tUpPU-0035L7-Cm for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2025 15:52:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tUpPT-009ozq-JT for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2025 15:52:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tUpPT-009ozh-1u for pgsql-hackers@lists.postgresql.org; Mon, 06 Jan 2025 15:52:54 +0000 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tUpPP-000AtZ-2r for pgsql-hackers@postgresql.org; Mon, 06 Jan 2025 15:52:53 +0000 Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-e4419a47887so18109577276.0 for ; Mon, 06 Jan 2025 07:52:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736178771; x=1736783571; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=9IyhJNEJiBQ2bXYTGATZzlmI6eCaBTmWmOQqd+wK1zI=; b=TnaJ7fQyICuYj4o7x1TegABOsUEVxzv4pV2nhoI9H5jljvtDR0nRvNpn8X6pet2h4k oc4AH9N4r1r2T8SliTRSrZU6hSwAlFfurgnZNddHFeuAoxDs67WhCZRfMkNBVIAs3ONB y/j492KwU9o/AZp6VxtKQ/nqaHAbjI+LwG/YdHBHoAEHkyQWr0ZH4X8rrLGBxYYBwRcz ZYfzkPZxDOlfY6yS0c0rWhdcvpVy7wzNZ6mG46injtG4lUfAghzLs0Rvp2mEnJuq0tKK MaPEd1MG6SpIzZNLpwoCcRJ3B5946ES6O/+HVkh8bEBifnmC2XU9eilaNOKPAxPsVcjf xIgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178771; x=1736783571; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9IyhJNEJiBQ2bXYTGATZzlmI6eCaBTmWmOQqd+wK1zI=; b=Wl7tHuR0LtUZmVAWFTHiw2nXxPIULpIF1FYXcFeziiGpocw29GvqiTRoXqVblyiTuK on2adHOn/Vee3cHS1mdJa7o6AB0uucLHa0KVJUYM4wxKp3GKHpEp0IGzmDZhtN7jAXWs uN5w0BgBFdBgnw/ldghf3UiPXLdGaAl5cBoN64RaRYyBCp2T8VVTCS+r2ClLwN/0i9Ue wbhObnSpSKU5/a021EDhbqQTpM/nBz1SNOfeZcJIPmwHhCLFNQrX1/UdYjiTFBvVmpKR s4Ao+yFhc9vJ+G5cgrx27sgksFn0bONgCG4evBKxLewQIv1JzZUKY4Z/Zl66D2sNyTdD xE8w== X-Forwarded-Encrypted: i=1; AJvYcCV09517Fca+MM1uFCjj6fjxqEKGCczZnYYX/MuKyujvMtnWHSMJreo/zQQg5NGFvO6iKnw+06x2ObmUOZLw@postgresql.org X-Gm-Message-State: AOJu0YwsSZ+QUAlSJ8FCyh6U12xdBZMcbrU82CMI13laBQnD93QQiK9g wBZ63arXZQOzKUYRnEf2zbqIKfu+zSjmPkc4RT5ERqJOeUYQryp6 X-Gm-Gg: ASbGncs0s8nipXpheCD8eXuskNv18zOyCgSvBp6TZYBXxrGHd9NgJTs9jA1Lqkx4hP3 mVnTMzno9RKJ/yun14EZt1KUppcBH3xQSNVOLvTO6rCPUdUG4ghH4J1bFqUcIPQKukYt9wl+xxc AppdmuvLVu3Fd8Gg7g9CNVlUjLsYkH3uAyufUhH1oh7tTadVIki3qat6BlxJoi6zdU7ALazjFFC B/Eem+vPxFll/AacgaD719Uxpge2NwUz9+xa9h4q7KWL5nyeur2oTqWloCScB2YrBdBrf7pJMRU SSl20OP4fTZgtm85plmqpZQwaDuPgMq7ZpXA5C2rflZtFwo= X-Google-Smtp-Source: AGHT+IErDC0paO3cUCA1uS2xHCEmTkIYNXrPHByCdbcOjIWhGcjLz1xYZSWXr5lrv1dtVNI1zY+9qQ== X-Received: by 2002:a05:690c:f0f:b0:6ef:6107:69c9 with SMTP id 00721157ae682-6f3f80cdf67mr329781177b3.4.1736178771388; Mon, 06 Jan 2025 07:52:51 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6f3e7444b73sm84335527b3.42.2025.01.06.07.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:52:50 -0800 (PST) Date: Mon, 6 Jan 2025 09:52:48 -0600 From: Nathan Bossart To: Andres Freund Cc: "Imseih (AWS), Sami" , Justin Pryzby , "pgsql-hackers@postgresql.org" Subject: Re: allow changing autovacuum_max_workers without restarting Message-ID: References: <20240618213331.ef2spg3nasksisbi@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="zXvfk38q/oLA3gt5" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --zXvfk38q/oLA3gt5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Dec 20, 2024 at 01:46:20PM -0600, Nathan Bossart wrote: > I think I've been saying I would commit this since August, but now I am > planning to do so first thing in the new year. In v11 of the patch, I > moved the initial startup WARNING to autovac_init() to avoid repeatedly > logging when the launcher restarts (e.g., for emergency vacuums when the > autovacuum parameter is disabled). Otherwise, I just made a couple of > cosmetic alterations and added a commit message. This one needed a rebase after commit 2bdf1b2. -- nathan --zXvfk38q/oLA3gt5 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v12-0001-Allow-changing-autovacuum_max_workers-without-re.patch" From 46ea1dbcbb3f344c656db7fead89e3e9753dfadc Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 20 Dec 2024 13:33:26 -0600 Subject: [PATCH v12 1/1] Allow changing autovacuum_max_workers without restarting. This commit introduces a new parameter named autovacuum_worker_slots that controls how many autovacuum worker slots to reserve during server startup. Modifying this new parameter's value does require a server restart, but it should typically be set to the upper bound of what you might realistically need to set autovacuum_max_workers. With that new parameter in place, autovacuum_max_workers can now be changed with a SIGHUP (e.g., pg_ctl reload). If autovacuum_max_workers is set higher than autovacuum_worker_slots, a WARNING is emitted, and the server will only start up to autovacuum_worker_slots workers at a given time. If autovacuum_max_workers is set to a value less than the number of currently-running autovacuum workers, the existing workers will continue running, but no new workers will be started until the number of running autovacuum workers drops below autovacuum_max_workers. Reviewed-by: Sami Imseih, Justin Pryzby, Robert Haas, Andres Freund, Yogesh Sharma Discussion: https://postgr.es/m/20240410212344.GA1824549%40nathanxps13 --- doc/src/sgml/config.sgml | 28 ++++++- doc/src/sgml/runtime.sgml | 4 +- src/backend/access/transam/xlog.c | 2 +- src/backend/postmaster/autovacuum.c | 82 +++++++++++++++---- src/backend/postmaster/pmchild.c | 4 +- src/backend/storage/lmgr/proc.c | 6 +- src/backend/utils/init/postinit.c | 6 +- src/backend/utils/misc/guc_tables.c | 11 ++- src/backend/utils/misc/postgresql.conf.sample | 3 +- src/include/postmaster/autovacuum.h | 1 + src/test/perl/PostgreSQL/Test/Cluster.pm | 1 + 11 files changed, 117 insertions(+), 31 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index fbdd6ce5740..740ff5d5044 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -8630,6 +8630,25 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; + + autovacuum_worker_slots (integer) + + autovacuum_worker_slots configuration parameter + + + + + Specifies the number of backend slots to reserve for autovacuum worker + processes. The default is 16. This parameter can only be set at server + start. + + + When changing this value, consider also adjusting + . + + + + autovacuum_max_workers (integer) @@ -8640,7 +8659,14 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; Specifies the maximum number of autovacuum processes (other than the autovacuum launcher) that may be running at any one time. The default - is three. This parameter can only be set at server start. + is three. This parameter can only be set in the + postgresql.conf file or on the server command line. + + + Note that a setting for this value which is higher than + will have no effect, + since autovacuum workers are taken from the pool of slots established + by that setting. diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index 8750044852d..59f39e89924 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -839,7 +839,7 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such When using System V semaphores, PostgreSQL uses one semaphore per allowed connection (), allowed autovacuum worker process - (), allowed WAL sender process + (), allowed WAL sender process (), allowed background process (), etc., in sets of 19. The runtime-computed parameter @@ -892,7 +892,7 @@ $ postgres -D $PGDATA -C num_os_semaphores When using POSIX semaphores, the number of semaphores needed is the same as for System V, that is one semaphore per allowed connection (), allowed autovacuum worker process - (), allowed WAL sender process + (), allowed WAL sender process (), allowed background process (), etc. On the platforms where this option is preferred, there is no specific diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b9ea92a5427..bf3dbda901d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5403,7 +5403,7 @@ CheckRequiredParameterValues(void) */ if (ArchiveRecoveryRequested && EnableHotStandby) { - /* We ignore autovacuum_max_workers when we make this test. */ + /* We ignore autovacuum_worker_slots when we make this test. */ RecoveryRequiresIntParameter("max_connections", MaxConnections, ControlFile->MaxConnections); diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 3f826532b88..0ab921a169b 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -115,6 +115,7 @@ * GUC parameters */ bool autovacuum_start_daemon = false; +int autovacuum_worker_slots; int autovacuum_max_workers; int autovacuum_work_mem = -1; int autovacuum_naptime; @@ -210,7 +211,7 @@ typedef struct autovac_table /*------------- * This struct holds information about a single worker's whereabouts. We keep * an array of these in shared memory, sized according to - * autovacuum_max_workers. + * autovacuum_worker_slots. * * wi_links entry into free list or running list * wi_dboid OID of the database this worker is supposed to work on @@ -291,7 +292,7 @@ typedef struct { sig_atomic_t av_signal[AutoVacNumSignals]; pid_t av_launcherpid; - dlist_head av_freeWorkers; + dclist_head av_freeWorkers; dlist_head av_runningWorkers; WorkerInfo av_startingWorker; AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]; @@ -349,6 +350,8 @@ static void autovac_report_activity(autovac_table *tab); static void autovac_report_workitem(AutoVacuumWorkItem *workitem, const char *nspname, const char *relname); static void avl_sigusr2_handler(SIGNAL_ARGS); +static bool av_worker_available(void); +static void check_av_worker_gucs(void); @@ -577,8 +580,7 @@ AutoVacLauncherMain(char *startup_data, size_t startup_data_len) * wakening conditions. */ - launcher_determine_sleep(!dlist_is_empty(&AutoVacuumShmem->av_freeWorkers), - false, &nap); + launcher_determine_sleep(av_worker_available(), false, &nap); /* * Wait until naptime expires or we get some type of signal (all the @@ -638,7 +640,7 @@ AutoVacLauncherMain(char *startup_data, size_t startup_data_len) current_time = GetCurrentTimestamp(); LWLockAcquire(AutovacuumLock, LW_SHARED); - can_launch = !dlist_is_empty(&AutoVacuumShmem->av_freeWorkers); + can_launch = av_worker_available(); if (AutoVacuumShmem->av_startingWorker != NULL) { @@ -681,8 +683,8 @@ AutoVacLauncherMain(char *startup_data, size_t startup_data_len) worker->wi_sharedrel = false; worker->wi_proc = NULL; worker->wi_launchtime = 0; - dlist_push_head(&AutoVacuumShmem->av_freeWorkers, - &worker->wi_links); + dclist_push_head(&AutoVacuumShmem->av_freeWorkers, + &worker->wi_links); AutoVacuumShmem->av_startingWorker = NULL; ereport(WARNING, errmsg("autovacuum worker took too long to start; canceled")); @@ -747,6 +749,8 @@ HandleAutoVacLauncherInterrupts(void) if (ConfigReloadPending) { + int autovacuum_max_workers_prev = autovacuum_max_workers; + ConfigReloadPending = false; ProcessConfigFile(PGC_SIGHUP); @@ -754,6 +758,14 @@ HandleAutoVacLauncherInterrupts(void) if (!AutoVacuumingActive()) AutoVacLauncherShutdown(); + /* + * If autovacuum_max_workers changed, emit a WARNING if + * autovacuum_worker_slots < autovacuum_max_workers. If it didn't + * change, skip this to avoid too many repeated log messages. + */ + if (autovacuum_max_workers_prev != autovacuum_max_workers) + check_av_worker_gucs(); + /* rebuild the list in case the naptime changed */ rebuild_database_list(InvalidOid); } @@ -1089,7 +1101,7 @@ do_start_worker(void) /* return quickly when there are no free workers */ LWLockAcquire(AutovacuumLock, LW_SHARED); - if (dlist_is_empty(&AutoVacuumShmem->av_freeWorkers)) + if (!av_worker_available()) { LWLockRelease(AutovacuumLock); return InvalidOid; @@ -1242,7 +1254,7 @@ do_start_worker(void) * Get a worker entry from the freelist. We checked above, so there * really should be a free slot. */ - wptr = dlist_pop_head_node(&AutoVacuumShmem->av_freeWorkers); + wptr = dclist_pop_head_node(&AutoVacuumShmem->av_freeWorkers); worker = dlist_container(WorkerInfoData, wi_links, wptr); worker->wi_dboid = avdb->adw_datid; @@ -1615,8 +1627,8 @@ FreeWorkerInfo(int code, Datum arg) MyWorkerInfo->wi_proc = NULL; MyWorkerInfo->wi_launchtime = 0; pg_atomic_clear_flag(&MyWorkerInfo->wi_dobalance); - dlist_push_head(&AutoVacuumShmem->av_freeWorkers, - &MyWorkerInfo->wi_links); + dclist_push_head(&AutoVacuumShmem->av_freeWorkers, + &MyWorkerInfo->wi_links); /* not mine anymore */ MyWorkerInfo = NULL; @@ -3248,10 +3260,14 @@ AutoVacuumRequestWork(AutoVacuumWorkItemType type, Oid relationId, void autovac_init(void) { - if (autovacuum_start_daemon && !pgstat_track_counts) + if (!autovacuum_start_daemon) + return; + else if (!pgstat_track_counts) ereport(WARNING, (errmsg("autovacuum not started because of misconfiguration"), errhint("Enable the \"track_counts\" option."))); + else + check_av_worker_gucs(); } /* @@ -3268,7 +3284,7 @@ AutoVacuumShmemSize(void) */ size = sizeof(AutoVacuumShmemStruct); size = MAXALIGN(size); - size = add_size(size, mul_size(autovacuum_max_workers, + size = add_size(size, mul_size(autovacuum_worker_slots, sizeof(WorkerInfoData))); return size; } @@ -3295,7 +3311,7 @@ AutoVacuumShmemInit(void) Assert(!found); AutoVacuumShmem->av_launcherpid = 0; - dlist_init(&AutoVacuumShmem->av_freeWorkers); + dclist_init(&AutoVacuumShmem->av_freeWorkers); dlist_init(&AutoVacuumShmem->av_runningWorkers); AutoVacuumShmem->av_startingWorker = NULL; memset(AutoVacuumShmem->av_workItems, 0, @@ -3305,10 +3321,10 @@ AutoVacuumShmemInit(void) MAXALIGN(sizeof(AutoVacuumShmemStruct))); /* initialize the WorkerInfo free list */ - for (i = 0; i < autovacuum_max_workers; i++) + for (i = 0; i < autovacuum_worker_slots; i++) { - dlist_push_head(&AutoVacuumShmem->av_freeWorkers, - &worker[i].wi_links); + dclist_push_head(&AutoVacuumShmem->av_freeWorkers, + &worker[i].wi_links); pg_atomic_init_flag(&worker[i].wi_dobalance); } @@ -3344,3 +3360,35 @@ check_autovacuum_work_mem(int *newval, void **extra, GucSource source) return true; } + +/* + * Returns whether there is a free autovacuum worker slot available. + */ +static bool +av_worker_available(void) +{ + int free_slots; + int reserved_slots; + + free_slots = dclist_count(&AutoVacuumShmem->av_freeWorkers); + + reserved_slots = autovacuum_worker_slots - autovacuum_max_workers; + reserved_slots = Max(0, reserved_slots); + + return free_slots > reserved_slots; +} + +/* + * Emits a WARNING if autovacuum_worker_slots < autovacuum_max_workers. + */ +static void +check_av_worker_gucs(void) +{ + if (autovacuum_worker_slots < autovacuum_max_workers) + ereport(WARNING, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("\"autovacuum_max_workers\" (%d) should be less than or equal to \"autovacuum_worker_slots\" (%d)", + autovacuum_max_workers, autovacuum_worker_slots), + errdetail("The server will only start up to \"autovacuum_worker_slots\" (%d) autovacuum workers at a given time.", + autovacuum_worker_slots))); +} diff --git a/src/backend/postmaster/pmchild.c b/src/backend/postmaster/pmchild.c index 0d53812406c..0d473226c3a 100644 --- a/src/backend/postmaster/pmchild.c +++ b/src/backend/postmaster/pmchild.c @@ -8,7 +8,7 @@ * child process is allocated a PMChild struct from a fixed pool of structs. * The size of the pool is determined by various settings that configure how * many worker processes and backend connections are allowed, i.e. - * autovacuum_max_workers, max_worker_processes, max_wal_senders, and + * autovacuum_worker_slots, max_worker_processes, max_wal_senders, and * max_connections. * * Dead-end backends are handled slightly differently. There is no limit @@ -99,7 +99,7 @@ InitPostmasterChildSlots(void) */ pmchild_pools[B_BACKEND].size = 2 * (MaxConnections + max_wal_senders); - pmchild_pools[B_AUTOVAC_WORKER].size = autovacuum_max_workers; + pmchild_pools[B_AUTOVAC_WORKER].size = autovacuum_worker_slots; pmchild_pools[B_BG_WORKER].size = max_worker_processes; /* diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index c7a972df7dd..49204f91a20 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -150,7 +150,7 @@ ProcGlobalSemas(void) * So, now we grab enough semaphores to support the desired max number * of backends immediately at initialization --- if the sysadmin has set * MaxConnections, max_worker_processes, max_wal_senders, or - * autovacuum_max_workers higher than his kernel will support, he'll + * autovacuum_worker_slots higher than his kernel will support, he'll * find out sooner rather than later. * * Another reason for creating semaphores here is that the semaphore @@ -284,13 +284,13 @@ InitProcGlobal(void) dlist_push_tail(&ProcGlobal->freeProcs, &proc->links); proc->procgloballist = &ProcGlobal->freeProcs; } - else if (i < MaxConnections + autovacuum_max_workers + NUM_SPECIAL_WORKER_PROCS) + else if (i < MaxConnections + autovacuum_worker_slots + NUM_SPECIAL_WORKER_PROCS) { /* PGPROC for AV or special worker, add to autovacFreeProcs list */ dlist_push_tail(&ProcGlobal->autovacFreeProcs, &proc->links); proc->procgloballist = &ProcGlobal->autovacFreeProcs; } - else if (i < MaxConnections + autovacuum_max_workers + NUM_SPECIAL_WORKER_PROCS + max_worker_processes) + else if (i < MaxConnections + autovacuum_worker_slots + NUM_SPECIAL_WORKER_PROCS + max_worker_processes) { /* PGPROC for bgworker, add to bgworkerFreeProcs list */ dlist_push_tail(&ProcGlobal->bgworkerFreeProcs, &proc->links); diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 46dbc46a97e..01bb6a410cb 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -547,15 +547,15 @@ InitializeMaxBackends(void) Assert(MaxBackends == 0); /* Note that this does not include "auxiliary" processes */ - MaxBackends = MaxConnections + autovacuum_max_workers + + MaxBackends = MaxConnections + autovacuum_worker_slots + max_worker_processes + max_wal_senders + NUM_SPECIAL_WORKER_PROCS; if (MaxBackends > MAX_BACKENDS) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("too many server processes configured"), - errdetail("\"max_connections\" (%d) plus \"autovacuum_max_workers\" (%d) plus \"max_worker_processes\" (%d) plus \"max_wal_senders\" (%d) must be less than %d.", - MaxConnections, autovacuum_max_workers, + errdetail("\"max_connections\" (%d) plus \"autovacuum_worker_slots\" (%d) plus \"max_worker_processes\" (%d) plus \"max_wal_senders\" (%d) must be less than %d.", + MaxConnections, autovacuum_worker_slots, max_worker_processes, max_wal_senders, MAX_BACKENDS - (NUM_SPECIAL_WORKER_PROCS - 1)))); } diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index 22f16a3b462..c9d8cd796a8 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -3467,7 +3467,16 @@ struct config_int ConfigureNamesInt[] = }, { /* see max_connections */ - {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM, + {"autovacuum_worker_slots", PGC_POSTMASTER, AUTOVACUUM, + gettext_noop("Sets the number of backend slots to allocate for autovacuum workers."), + NULL + }, + &autovacuum_worker_slots, + 16, 1, MAX_BACKENDS, + NULL, NULL, NULL + }, + { + {"autovacuum_max_workers", PGC_SIGHUP, AUTOVACUUM, gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."), NULL }, diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index a2ac7575ca7..b2bc43383db 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -661,8 +661,9 @@ #autovacuum = on # Enable autovacuum subprocess? 'on' # requires track_counts to also be on. -#autovacuum_max_workers = 3 # max number of autovacuum subprocesses +autovacuum_worker_slots = 16 # autovacuum worker slots to allocate # (change requires restart) +#autovacuum_max_workers = 3 # max number of autovacuum subprocesses #autovacuum_naptime = 1min # time between autovacuum runs #autovacuum_vacuum_threshold = 50 # min number of row updates before # vacuum diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h index edac746f3cf..54e01c81d68 100644 --- a/src/include/postmaster/autovacuum.h +++ b/src/include/postmaster/autovacuum.h @@ -28,6 +28,7 @@ typedef enum /* GUC variables */ extern PGDLLIMPORT bool autovacuum_start_daemon; +extern PGDLLIMPORT int autovacuum_worker_slots; extern PGDLLIMPORT int autovacuum_max_workers; extern PGDLLIMPORT int autovacuum_work_mem; extern PGDLLIMPORT int autovacuum_naptime; diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index 74bf3408682..08b89a4cdff 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -707,6 +707,7 @@ sub init } print $conf "max_wal_senders = 10\n"; print $conf "max_replication_slots = 10\n"; + print $conf "autovacuum_worker_slots = 3\n"; print $conf "wal_log_hints = on\n"; print $conf "hot_standby = on\n"; # conservative settings to ensure we can run multiple postmasters: -- 2.39.5 (Apple Git-154) --zXvfk38q/oLA3gt5--