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 1tVIWB-0076jv-PY for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 22:57:48 +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 1tVIWB-009SOU-9S for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 22:57:46 +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 1tVIWA-009SOM-S1 for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2025 22:57:46 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tVIW8-000PTL-0e for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2025 22:57:45 +0000 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-84cdacbc373so31839539f.1 for ; Tue, 07 Jan 2025 14:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736290663; x=1736895463; 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=OjJaIzmeGHNSNTVIvHIf5vfqOiRox6xtg7pxkAh8nJM=; b=c2Sew+pLjiOzwUQSDe4HOcpfrf8leNJz9AVhsGsT6scHBM6wy16igJ8fotG5ul6/kq Y6Y0MxtqhAUttqNjyFgxuMpCaadQ9/bzEB927UpcsIxZzBzYz+84lo+XvGjzjN+UJABN Bscas7xs2EU+mgffgJ9AIi/2lZ+pBJ4syBwZybEYz3PPRVkYsnE5BzFza0no4Ytaynj6 RCGQtNIvYWeheqPi3ogVPyo6KP5Z+4DUZfzdCF4Ge/5gQD3tKFDuprIeRVS4w0mQLD4z 9iJtejhLbYQFsQK+IyUtIGtAJLuDDyMfQedyLIiKLBOqr2TKAJEMeO0o/Rk1eeJi5dWi LGIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736290663; x=1736895463; 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=OjJaIzmeGHNSNTVIvHIf5vfqOiRox6xtg7pxkAh8nJM=; b=lCwVsO/ML4SkmDWMYSZ+wFZ4hvf1OSUVQBr1vIhrJ/Kk3DZ4nDtYTAvCP5yILqyTvG K+ioQ7dqd/PkFsylfiJzQzeJP2XKtMesLecMJIVW5+W2lmEeLqZx5jq4cxBg84Wiw7GN p9hMfRZzLW/fiv/Zkl4qkFmUiWbULMSdVdSpOZHx4xKtVmuWHjayh0IrGH+x0hCPWlnd i52gKzc5XA+/+7UzHAYmjPQ8PpNqrk0a96ujrSPZVVA5Tw2OZc2JG9c0e7+0iZWs6fKL SSrW5HtFyPFIxG3HCaAsi4+u9OdrcFTHATd67oVUlPpWM4yhLLGdaBU303Z6DtZrS5Ri A1Pw== X-Forwarded-Encrypted: i=1; AJvYcCVw/QjjCGIJVdaLOIMuSZC8rGqb1+xxyx+cj03YoiejVlZ7e1KjGMI7JL2kwp8Og/BVNXW6D2tw8v6xIpir@lists.postgresql.org X-Gm-Message-State: AOJu0YyMF9b6h2OkargObujHneC6g94CsFaSPzVt9y+j3JU4mgSs2SiY fGhdZecOliq3YQGzjLBzVtwRDbMniUAVAMqGA96zBFBy00Mi+fn4 X-Gm-Gg: ASbGnctVGtsVi7InhVLj9GX2MvhC4pFCFOO8uwJb47H0Qeb6duTOEZhvSRvKTuCf622 CK3sHI6NRSHinQ2Gjt3JjYBLe2Y/yTUTMygwumrdMQnmQHIcLQHGoIl9QnbD3tSROUhzybTkkot c44N3N9Vz2D20hpvUcpE6r+WKoJqNorFuYCVemahUcLrptHukHvioJ8c7Kobr0azjfCffjq4Ppn u9INDBSiKK5Eizr9u9DnXmaf9lEx9zy5n1+cojNUdrJXdl7d+gEj7aruBYnjOZQLCgAbaSwZxwv aQKq89AZNr7/PxRIlZXU5yNmGFOHzqQML084hT4K3buWUBs= X-Google-Smtp-Source: AGHT+IFnZsnIRKY1ra9X41pJyl/ZO3y45FbrEVFE9Au9eGYqr7NcD1UhHNd9feuQAUrHpXcaI4/9Pw== X-Received: by 2002:a05:6602:3605:b0:844:c750:3d9d with SMTP id ca18e2360f4ac-84ce0081cf9mr96198939f.4.1736290663563; Tue, 07 Jan 2025 14:57:43 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e81ebd3369sm2829893173.97.2025.01.07.14.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 14:57:42 -0800 (PST) Date: Tue, 7 Jan 2025 16:57:41 -0600 From: Nathan Bossart To: wenhui qiu Cc: =?iso-8859-1?Q?Fr=E9d=E9ric?= Yhuel , Robert Haas , "Imseih (AWS), Sami" , David Rowley , Joe Conway , Michael Banck , Laurenz Albe , Melanie Plageman , PostgreSQL Hackers Subject: Re: New GUC autovacuum_max_threshold ? Message-ID: References: <97f04e09-a08a-417c-b65d-5d5cbdd0b845@dalibo.com> <6a2ac9b7-6535-4bb1-8274-0647f7c31c82@dalibo.com> <2ca7f9c7-5da9-46cb-9072-39b71bfab948@dalibo.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="se9LvmAYPj/v8/s/" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --se9LvmAYPj/v8/s/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Here is a rebased patch for cfbot. AFAICT we are still pretty far from consensus on which approach to take, unfortunately. -- nathan --se9LvmAYPj/v8/s/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-autovacuum_max_threshold.patch" From df17b1f8b18300bc8426c06ab4e4d2d1c9169d85 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 7 Aug 2024 16:22:37 -0500 Subject: [PATCH v3 1/1] autovacuum_max_threshold --- doc/src/sgml/config.sgml | 24 +++++++++++++++++++ doc/src/sgml/ref/create_table.sgml | 15 ++++++++++++ src/backend/access/common/reloptions.c | 11 +++++++++ src/backend/postmaster/autovacuum.c | 11 +++++++++ src/backend/utils/misc/guc_tables.c | 9 +++++++ src/backend/utils/misc/postgresql.conf.sample | 2 ++ src/bin/psql/tab-complete.in.c | 2 ++ src/include/postmaster/autovacuum.h | 1 + src/include/utils/rel.h | 1 + 9 files changed, 76 insertions(+) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 8683f0bdf53..3c03bdd5790 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -8712,6 +8712,30 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; + + autovacuum_max_threshold (integer) + + autovacuum_max_threshold + configuration parameter + + + + + Specifies the maximum number of updated or deleted tuples needed to + trigger a VACUUM in any one table, i.e., a cap on + the value calculated with + autovacuum_vacuum_threshold and + autovacuum_vacuum_scale_factor. The default is + 100,000,000 tuples. If -1 is specified, autovacuum will not enforce a + maximum number of updated or deleted tuples that will trigger a + VACUUM operation. This parameter can only be set in + the postgresql.conf file or on the server command + line; but the setting can be overridden for individual tables by + changing storage parameters. + + + + autovacuum_vacuum_insert_threshold (integer) diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 70fa929caa4..77cee4a2888 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -1682,6 +1682,21 @@ WITH ( MODULUS numeric_literal, REM + + autovacuum_max_threshold, toast.autovacuum_max_threshold (integer) + + autovacuum_max_threshold + storage parameter + + + + + Per-table value for + parameter. + + + + autovacuum_vacuum_scale_factor, toast.autovacuum_vacuum_scale_factor (floating point) diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c index e587abd9990..c28c7517aeb 100644 --- a/src/backend/access/common/reloptions.c +++ b/src/backend/access/common/reloptions.c @@ -231,6 +231,15 @@ static relopt_int intRelOpts[] = }, -1, 0, INT_MAX }, + { + { + "autovacuum_max_threshold", + "Maximum number of tuple updates or deletes prior to vacuum", + RELOPT_KIND_HEAP | RELOPT_KIND_TOAST, + ShareUpdateExclusiveLock + }, + -1, 0, INT_MAX + }, { { "autovacuum_vacuum_insert_threshold", @@ -1843,6 +1852,8 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind) offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)}, {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT, offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)}, + {"autovacuum_max_threshold", RELOPT_TYPE_INT, + offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_max_threshold)}, {"autovacuum_vacuum_insert_threshold", RELOPT_TYPE_INT, offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_threshold)}, {"autovacuum_analyze_threshold", RELOPT_TYPE_INT, diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 0ab921a169b..680b3dcae48 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -120,6 +120,7 @@ int autovacuum_max_workers; int autovacuum_work_mem = -1; int autovacuum_naptime; int autovacuum_vac_thresh; +int autovacuum_max_thresh; double autovacuum_vac_scale; int autovacuum_vac_ins_thresh; double autovacuum_vac_ins_scale; @@ -2895,6 +2896,8 @@ recheck_relation_needs_vacanalyze(Oid relid, * threshold. This threshold is calculated as * * threshold = vac_base_thresh + vac_scale_factor * reltuples + * if (threshold > vac_max_thresh) + * threshold = vac_max_thres; * * For analyze, the analysis done is that the number of tuples inserted, * deleted and updated since the last analyze exceeds a threshold calculated @@ -2933,6 +2936,7 @@ relation_needs_vacanalyze(Oid relid, /* constants from reloptions or GUC variables */ int vac_base_thresh, + vac_max_thresh, vac_ins_base_thresh, anl_base_thresh; float4 vac_scale_factor, @@ -2974,6 +2978,10 @@ relation_needs_vacanalyze(Oid relid, ? relopts->vacuum_threshold : autovacuum_vac_thresh; + vac_max_thresh = (relopts && relopts->vacuum_max_threshold >= 0) + ? relopts->vacuum_max_threshold + : autovacuum_max_thresh; + vac_ins_scale_factor = (relopts && relopts->vacuum_ins_scale_factor >= 0) ? relopts->vacuum_ins_scale_factor : autovacuum_vac_ins_scale; @@ -3047,6 +3055,9 @@ relation_needs_vacanalyze(Oid relid, reltuples = 0; vacthresh = (float4) vac_base_thresh + vac_scale_factor * reltuples; + if (vac_max_thresh >= 0 && vacthresh > (float4) vac_max_thresh) + vacthresh = (float4) vac_max_thresh; + vacinsthresh = (float4) vac_ins_base_thresh + vac_ins_scale_factor * reltuples; anlthresh = (float4) anl_base_thresh + anl_scale_factor * reltuples; diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index c9d8cd796a8..2a18ba80c87 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -3425,6 +3425,15 @@ struct config_int ConfigureNamesInt[] = 50, 0, INT_MAX, NULL, NULL, NULL }, + { + {"autovacuum_max_threshold", PGC_SIGHUP, AUTOVACUUM, + gettext_noop("Maximum number of tuple updates or deletes prior to vacuum."), + NULL + }, + &autovacuum_max_thresh, + 100000000, -1, INT_MAX, + NULL, NULL, NULL + }, { {"autovacuum_vacuum_insert_threshold", PGC_SIGHUP, AUTOVACUUM, gettext_noop("Minimum number of tuple inserts prior to vacuum, or -1 to disable insert vacuums."), diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index b2bc43383db..d0e1c9b53c0 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -667,6 +667,8 @@ autovacuum_worker_slots = 16 # autovacuum worker slots to allocate #autovacuum_naptime = 1min # time between autovacuum runs #autovacuum_vacuum_threshold = 50 # min number of row updates before # vacuum +#autovacuum_max_threshold = 100000000 # max number of row updates before + # vacuum #autovacuum_vacuum_insert_threshold = 1000 # min number of row inserts # before vacuum; -1 disables insert # vacuums diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 81cbf10aa28..6ede5090cc0 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -1361,6 +1361,7 @@ static const char *const table_storage_parameters[] = { "autovacuum_freeze_max_age", "autovacuum_freeze_min_age", "autovacuum_freeze_table_age", + "autovacuum_max_threshold", "autovacuum_multixact_freeze_max_age", "autovacuum_multixact_freeze_min_age", "autovacuum_multixact_freeze_table_age", @@ -1377,6 +1378,7 @@ static const char *const table_storage_parameters[] = { "toast.autovacuum_freeze_max_age", "toast.autovacuum_freeze_min_age", "toast.autovacuum_freeze_table_age", + "toast.autovacuum_max_threshold", "toast.autovacuum_multixact_freeze_max_age", "toast.autovacuum_multixact_freeze_min_age", "toast.autovacuum_multixact_freeze_table_age", diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h index 54e01c81d68..b5c7b9b8abb 100644 --- a/src/include/postmaster/autovacuum.h +++ b/src/include/postmaster/autovacuum.h @@ -33,6 +33,7 @@ extern PGDLLIMPORT int autovacuum_max_workers; extern PGDLLIMPORT int autovacuum_work_mem; extern PGDLLIMPORT int autovacuum_naptime; extern PGDLLIMPORT int autovacuum_vac_thresh; +extern PGDLLIMPORT int autovacuum_max_thresh; extern PGDLLIMPORT double autovacuum_vac_scale; extern PGDLLIMPORT int autovacuum_vac_ins_thresh; extern PGDLLIMPORT double autovacuum_vac_ins_scale; diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 33d1e4a4e2e..48b95f211f3 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -309,6 +309,7 @@ typedef struct AutoVacOpts { bool enabled; int vacuum_threshold; + int vacuum_max_threshold; int vacuum_ins_threshold; int analyze_threshold; int vacuum_cost_limit; -- 2.39.5 (Apple Git-154) --se9LvmAYPj/v8/s/--