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 1tVDJ6-006Sk3-EV for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 17:23:56 +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 1tVDJ5-005xF9-Jw for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 17:23:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVDJ5-005xF0-99 for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2025 17:23:54 +0000 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tVDJ1-000NXh-34 for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2025 17:23:54 +0000 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-e53aa843a24so22494276.0 for ; Tue, 07 Jan 2025 09:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736270631; x=1736875431; darn=lists.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=eolZ9gwa0usL0rp0tPEUdyglUu9sMgdnQ2j99KeiV3c=; b=YVPSser5qqwNCke1Q6ngz18/sRR5wIuynQUA2dP8JwDthBSsmMK2NYdtjddkiAz3ni KTaL7t1n+iNAQuEqbTf4ViK1JSBDSLCsxG853/CG6xWoPC9Hgqu7RtkW2mC4dApAJq6v NndibK8JuzfxYxaRncCcqOdjYefbO0NU3XDg29yWJUgeZFtKkOOWbBPk9Vp0TORD9r3w GdiU01rOZvK8NRuE1y/lR7tm7jLeZQbQ1b/dXPn9b3XYB5pBps/vKjSJ2KlB61yZjODE fRX7aFGja1LkYyAaorSBSQBAPKYBdP6PJBU+iTR6+Ot1BboSdOVvWzVUmXcHZfnfpvzh H6+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736270631; x=1736875431; 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=eolZ9gwa0usL0rp0tPEUdyglUu9sMgdnQ2j99KeiV3c=; b=tZtGMVn9eUYeVArFSl5n8TEoqdW2VcVMNzkwKTFNS6bXUybQn6DaWp+cvshn/e0xkJ EEiP7xMrXdD2gtKnQ8L8aTWE0n0wLNFHHL56IsC48Ov3AUiazLzcpncDooCx2eFzv0CQ RmE9zXugfqoQquQyBwFPMR+odfZiKdfZe0khZZ43vp1x3S/gl+d3r/bQFr+Eoym+NqWi nCMe88ISMCAb0W17L8EftYCPcrUNhgG2m13OkFFZa3PKkYBcVcx0PyJWKO3lu2Hd+pP6 18ef1ibp5NXnwf5az81VbPSfVUeuqnA4DPWDuoX6Eomp86dhWX9kUrm4HDopaFJZDWHN fvnA== X-Forwarded-Encrypted: i=1; AJvYcCXurf7Q7vJ58rRIM7G8n1Am1oT2lj6nNPmOb12bSwexrwRFYFf1dtt2bz68VT0r9bTMgcOpnCmSobJHjW16@lists.postgresql.org X-Gm-Message-State: AOJu0Yw/Z0InF19kowVU211XOhk9dlmZccGtJPL1X+ILXz8RJ/gCIDQv eaU+cEa6xVQ+zGf+UnoJH02auTg5eZFpwCSrS0lLtFfOZJjOVdsv X-Gm-Gg: ASbGncuvy1gwbp4XmD+bWXT+kcKffDDl2nGE+eNaqs2FaAYe/yMD+ZBxhmgwI+0/UI9 yzMa8BQw4ZLz1XXc6TgxExeHERs54RKuBHmCsCpBDL3YofxRt3eluYIJT90Fs4WpbLtiXV7XkMA AfhnA59+DbzRcMx4ZGMackqfzzpLbSW8C4xW2fxsVuFSl13Cdw4hxImoeQ6BxvCFxtmWx6LwN6/ deqrtc0XzQmG5/yn1MKua1SuDNyPMvQW3eL0Xa6YvdPadGvVXEW6WozcL6U7On4EX1kIv9aW5yw JNOaldxcwbD9+h+JXJ0Tr8kmn7tzUV7EKwrSme+zDZO8Dck= X-Google-Smtp-Source: AGHT+IFfNccQ3GCKSWyRcAEJAXBTQMUm4YSGn14MKeX/nyYeF+J/D7HruCCSLw1ISZwfz5eMVNha4g== X-Received: by 2002:a05:6902:12c2:b0:e39:8992:57c8 with SMTP id 3f1490d57ef6-e54d2278d99mr2933326276.18.1736270630888; Tue, 07 Jan 2025 09:23:50 -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-e537cf46c9fsm9483485276.40.2025.01.07.09.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 09:23:50 -0800 (PST) Date: Tue, 7 Jan 2025 11:23:47 -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> <1359669.1736206603@sss.pgh.pa.us> <1386858.1736220547@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="fBsFehpR9B6WlT8V" Content-Disposition: inline In-Reply-To: <1386858.1736220547@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --fBsFehpR9B6WlT8V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jan 06, 2025 at 10:29:07PM -0500, Tom Lane wrote: > +1 for simplicity ... but on reflection, what do you think about > using max_connections / 6? That would keep autovacuum_worker_slots > at 100 / 6 = 16 for the vast majority of systems. For the worst case > *BSD machines, we'd select 25 / 6 = 4 which results in consuming one > more semaphore than where we were yesterday. I'm willing to accept > that outcome though, since we still have 3 or so to spare. WFM. I'm kicking myself for not having thought of that... > Other than the specific magic number, your patch LGTM. Here's a new version of the patch with some small cosmetic changes (including more commentary about the formula) and the constant changed to 6. I'll go commit this shortly. -- nathan --fBsFehpR9B6WlT8V Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-Lower-default-value-of-autovacuum_worker_slots-in.patch" From d8b9fe6d3c166c14d9a8d17f43418be33c4e0784 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 7 Jan 2025 11:15:22 -0600 Subject: [PATCH v3 1/1] Lower default value of autovacuum_worker_slots in initdb as needed. TODO Reported-by: Tom Lane Suggested-by: Andres Freund Reviewed-by: Tom Lane Discussion: https://postgr.es/m/1346002.1736198977%40sss.pgh.pa.us --- doc/src/sgml/config.sgml | 5 +++-- src/bin/initdb/initdb.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 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..f2b9d50e9b3 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -196,6 +196,7 @@ static char *pgdata_native; /* defaults */ static int n_connections = 10; +static int n_av_slots = 16; static int n_buffers = 50; 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_av_slots, + int test_buffs); static void setup_config(void); static void bootstrap_template1(void); static void setup_auth(FILE *cmdfd); @@ -1118,6 +1120,18 @@ test_config_settings(void) */ #define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10) + /* + * This macro defines the default value of autovacuum_worker_slots we want + * for a given max_connections value. Note that it has been carefully + * crafted to provide specific values for the associated values in + * trial_conns. We want it to return autovacuum_worker_slot's initial + * default value (16) for the maximum value in trial_conns (100), and we + * want it to return close to the minimum value we'd consider (3, which is + * the default of autovacuum_max_workers) for the minimum value in + * trial_conns (25). + */ +#define AV_SLOTS_FOR_CONNS(nconns) ((nconns) / 6) + static const int trial_conns[] = { 100, 50, 40, 30, 25 }; @@ -1145,7 +1159,8 @@ test_config_settings(void) /* * Probe for max_connections before shared_buffers, since it is subject to - * more constraints than shared_buffers. + * more constraints than shared_buffers. We also choose the default + * autovacuum_worker_slots here. */ printf(_("selecting default \"max_connections\" ... ")); fflush(stdout); @@ -1153,9 +1168,10 @@ test_config_settings(void) for (i = 0; i < connslen; i++) { test_conns = trial_conns[i]; + n_av_slots = AV_SLOTS_FOR_CONNS(test_conns); test_buffs = MIN_BUFS_FOR_CONNS(test_conns); - if (test_specific_config_settings(test_conns, test_buffs)) + if (test_specific_config_settings(test_conns, n_av_slots, test_buffs)) { ok_buffers = test_buffs; break; @@ -1167,6 +1183,13 @@ test_config_settings(void) printf("%d\n", n_connections); + /* + * We chose the default for autovacuum_worker_slots during the + * max_connections tests above, but we print a progress message anyway. + */ + printf(_("selecting default \"autovacuum_worker_slots\" ... %d\n"), + n_av_slots); + printf(_("selecting default \"shared_buffers\" ... ")); fflush(stdout); @@ -1180,7 +1203,7 @@ test_config_settings(void) break; } - if (test_specific_config_settings(n_connections, test_buffs)) + if (test_specific_config_settings(n_connections, n_av_slots, test_buffs)) break; } n_buffers = test_buffs; @@ -1200,7 +1223,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_av_slots, int test_buffs) { PQExpBufferData cmd; _stringlist *gnames, @@ -1213,10 +1236,11 @@ test_specific_config_settings(int test_conns, int test_buffs) printfPQExpBuffer(&cmd, "\"%s\" --check %s %s " "-c max_connections=%d " + "-c autovacuum_worker_slots=%d " "-c shared_buffers=%d " "-c dynamic_shared_memory_type=%s", backend_exec, boot_options, extra_options, - test_conns, test_buffs, + test_conns, test_av_slots, test_buffs, dynamic_shared_memory_type); /* Add any user-given setting overrides */ @@ -1280,6 +1304,10 @@ setup_config(void) conflines = replace_guc_value(conflines, "max_connections", repltok, false); + snprintf(repltok, sizeof(repltok), "%d", n_av_slots); + conflines = replace_guc_value(conflines, "autovacuum_worker_slots", + repltok, false); + if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0) snprintf(repltok, sizeof(repltok), "%dMB", (n_buffers * (BLCKSZ / 1024)) / 1024); -- 2.39.5 (Apple Git-154) --fBsFehpR9B6WlT8V--