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 1tUwOd-0040o8-13 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2025 23:20:31 +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 1tUwOc-00EZDZ-FI for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2025 23:20:30 +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 1tUwOc-00EZDF-23 for pgsql-hackers@lists.postgresql.org; Mon, 06 Jan 2025 23:20:29 +0000 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tUwOY-000EQm-2V for pgsql-hackers@postgresql.org; Mon, 06 Jan 2025 23:20:28 +0000 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-e3983426f80so20745535276.1 for ; Mon, 06 Jan 2025 15:20:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736205626; x=1736810426; 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=AV8ZVQVY+TaxR8fL/Sv+ZfHL96ZwJxajlFQfXyu6PTo=; b=dnqMdEI4CxGmRjtcusYAIja87icZp4w2zflWy5OWBA/UalAwr3arEzfLLpu/JCXXOG 1Iy0lkBHO332mLcBV7WaDLND+Kd2jHCZONtNfsfb9z3B49QrIPXTIcSNboabvc7JHJOE /8fo397lKp9jwMjOOOkKEbinwZJHp5dyRFRypM5KMmHf2hMv/avDzXD61cjyYTW9jRzi rvywdsPGxsfK6gbZUJb6wIUTxylYJIKlO+Gn6qRhI1xrM2893r2JOLWsV1Qtanb7LIgo tEN/GxkesL7bfE32VFlbSeF1WsvYQR7fNXX9vIUcAKB5B5df5AxZEjdCDxYRV9bfCR4s 18Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736205626; x=1736810426; 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=AV8ZVQVY+TaxR8fL/Sv+ZfHL96ZwJxajlFQfXyu6PTo=; b=k8hTxDpQ1b72XR9+xQ0b/gO6bHU7NvpO0wR3KM2oy3EGVXqnMgJXCj1dHQHdFfbKez l7Q3h7KCbqOCrTAzRlS10lxFFlbQyTdWUIZxh3RooVNufI8ylBT4C0qwDZPiAf7HBZkG nAU3ayDuzA5ZYi8PcNQ0j8O4BPPkTiMp3/z2/36JPO2sE+0vOMlhlVPJBJ/hQx7KCqoD 001oA59KI0gLwVxUlPW2qTDH4/4XbemaD458jVbCX77oz2+3qtHawwtixDnH/Jskjn7K mXWc1VPfFEBTXzlw/Zu/t6CIagNc8HuS0unDWbQnhd8txiSs5zgArWpNnGHRSeGWZQn5 YmLw== X-Forwarded-Encrypted: i=1; AJvYcCW6u7uZj13LS3ewmJ/FY77caXQKPvIaW8h8iLb5RppSIDmY8ZcO6TDUoDy9xw/kHp3yMlappyIMTTp3xtmX@postgresql.org X-Gm-Message-State: AOJu0YxrSDaOTfu/Bj4E5/lafXMMiUHMAUZc6LySqnuC32/HqGzN/P6z LgC2E+S/MZcjr6DXUUMmyqRSja4vD5NwYshoLiI1bUyDuRWuu9dF X-Gm-Gg: ASbGncv9ieT7m8o4ZQ+iXqOy4r2yu0D1852XyC43VSNrfNYEXcnwU7sE7s4cRaLnMMH 7aeRWgAgHMM4jKweMku+hCvsEGI8hSIvGgBu9bywcaGuhG/q+NGQ8XJzN2gxr1YbyGtZsZPv3DE uOrst/MwGN0gD1zhgnk0bmQ8xaIZqQZaoEBIp9wwKtX19J5SgqlZeoa2Ts60lBqZtTvCP+xq3HP n+CA4fgnDEzIWoIDp5v/sXJh/j0+cTClgYVh16YMw6+mjUOmtcR95z1fEu66rZenuNpjao4u3Gg w86Qmnju7g6nMfyhatnc40MjIP+ymwuwIF+cytiN/I2iXpY= X-Google-Smtp-Source: AGHT+IHS6YqBDmbSNMWX8OzAZiLpBU9DPQvYtv/c86pQYHemcbn4fm8/CMZylcpF5dWe2UaP5nbB0g== X-Received: by 2002:a05:6902:18ce:b0:e44:82ef:395b with SMTP id 3f1490d57ef6-e53965500bfmr41943195276.32.1736205626337; Mon, 06 Jan 2025 15:20:26 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e537cf738b2sm9381728276.50.2025.01.06.15.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 15:20:25 -0800 (PST) Date: Mon, 6 Jan 2025 17:20:22 -0600 From: Nathan Bossart To: Tom Lane Cc: Andres Freund , pgsql-hackers@lists.postgresql.org, "Imseih (AWS), Sami" , Justin Pryzby , "pgsql-hackers@postgresql.org" Subject: Re: allow changing autovacuum_max_workers without restarting Message-ID: References: <1346002.1736198977@sss.pgh.pa.us> <7B8590B5-3A23-4CF6-B21D-4AA8C0177C2C@anarazel.de> <1353350.1736202977@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="M2fDjIoTK0cGSyOs" Content-Disposition: inline In-Reply-To: <1353350.1736202977@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --M2fDjIoTK0cGSyOs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jan 06, 2025 at 05:36:17PM -0500, Tom Lane wrote: > Andres Freund writes: >> How about trying the higher setting first in initdb? On any sane system >> that won't cost anything because it'll succeed with the higher value. > > That might be a good compromise. +1, I like the idea. > You'd have to think about how > it should interact with initdb's probes for workable values of > max_connections. My first thought about that is to have initdb > set autovacuum_worker_slots to max_connections / 8 or thereabouts > as it works down the list of max_connections values to try. Or > you could do something more complicated, but I don't see a reason > to make it too complex. My first instinct was just to set it to the lowest default we'd consider during the max_connections tests (which I'm assuming is 3 due to the current default for autovacuum_max_workers). That way, the max_connections default won't change from version to version on affected systems, but you might get some extra autovacuum slots. -- nathan --M2fDjIoTK0cGSyOs Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Lower-default-value-of-autovacuum_worker_slots-in.patch" From e35b4c5425cbe1120d3c38619be4f1523ae1f2c9 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 6 Jan 2025 17:14:54 -0600 Subject: [PATCH v1 1/1] Lower default value of autovacuum_worker_slots in initdb as needed. --- doc/src/sgml/config.sgml | 5 +++-- src/bin/initdb/initdb.c | 41 +++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 740ff5d5044..8683f0bdf53 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -8639,8 +8639,9 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; 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. + processes. The default is typically 16 slots, but might be less if + your kernel settings will not support it (as determined during initdb). + This parameter can only be set at server start. When changing this value, consider also adjusting diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 4e4b7ede190..1214f1b492a 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -197,6 +197,7 @@ static char *pgdata_native; /* defaults */ static int n_connections = 10; static int n_buffers = 50; +static int n_av_slots = 16; static const char *dynamic_shared_memory_type = NULL; static const char *default_timezone = NULL; @@ -273,7 +274,8 @@ static void check_input(char *path); static void write_version_file(const char *extrapath); static void set_null_conf(void); static void test_config_settings(void); -static bool test_specific_config_settings(int test_conns, int test_buffs); +static bool test_specific_config_settings(int test_conns, int test_buffs, + int test_av_slots); static void setup_config(void); static void bootstrap_template1(void); static void setup_auth(FILE *cmdfd); @@ -1118,6 +1120,13 @@ test_config_settings(void) */ #define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10) + /* + * This macro defines the minimum default autovacuum_worker_slots we are + * willing to consider. It should be kept >= the default for + * autovacuum_max_workers. + */ +#define MIN_AV_WORKER_SLOTS (3) + static const int trial_conns[] = { 100, 50, 40, 30, 25 }; @@ -1155,7 +1164,9 @@ test_config_settings(void) test_conns = trial_conns[i]; test_buffs = MIN_BUFS_FOR_CONNS(test_conns); - if (test_specific_config_settings(test_conns, test_buffs)) + if (test_specific_config_settings(test_conns, + test_buffs, + MIN_AV_WORKER_SLOTS)) { ok_buffers = test_buffs; break; @@ -1180,7 +1191,9 @@ test_config_settings(void) break; } - if (test_specific_config_settings(n_connections, test_buffs)) + if (test_specific_config_settings(n_connections, + test_buffs, + MIN_AV_WORKER_SLOTS)) break; } n_buffers = test_buffs; @@ -1190,6 +1203,19 @@ test_config_settings(void) else printf("%dkB\n", n_buffers * (BLCKSZ / 1024)); + printf(_("selecting default \"autovacuum_worker_slots\" ... ")); + fflush(stdout); + + for (; n_av_slots > MIN_AV_WORKER_SLOTS; n_av_slots--) + { + if (test_specific_config_settings(n_connections, + n_buffers, + n_av_slots)) + break; + } + + printf("%d\n", n_av_slots); + printf(_("selecting default time zone ... ")); fflush(stdout); default_timezone = select_default_timezone(share_path); @@ -1200,7 +1226,7 @@ test_config_settings(void) * Test a specific combination of configuration settings. */ static bool -test_specific_config_settings(int test_conns, int test_buffs) +test_specific_config_settings(int test_conns, int test_buffs, int test_av_slots) { PQExpBufferData cmd; _stringlist *gnames, @@ -1214,9 +1240,10 @@ test_specific_config_settings(int test_conns, int test_buffs) "\"%s\" --check %s %s " "-c max_connections=%d " "-c shared_buffers=%d " + "-c autovacuum_worker_slots=%d " "-c dynamic_shared_memory_type=%s", backend_exec, boot_options, extra_options, - test_conns, test_buffs, + test_conns, test_buffs, test_av_slots, dynamic_shared_memory_type); /* Add any user-given setting overrides */ @@ -1289,6 +1316,10 @@ setup_config(void) conflines = replace_guc_value(conflines, "shared_buffers", repltok, false); + snprintf(repltok, sizeof(repltok), "%d", n_av_slots); + conflines = replace_guc_value(conflines, "autovacuum_worker_slots", + repltok, false); + conflines = replace_guc_value(conflines, "lc_messages", lc_messages, false); -- 2.39.5 (Apple Git-154) --M2fDjIoTK0cGSyOs--