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.96) (envelope-from ) id 1x13rC-004xU4-2A for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 15:23:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x13rB-000wGc-25 for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 15:23:33 +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.96) (envelope-from ) id 1x13rB-000wGT-10 for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 15:23:33 +0000 Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x13r9-00000003Jy2-2Zw4 for pgsql-hackers@postgresql.org; Mon, 31 Aug 2026 15:23:32 +0000 Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-51c2cce930cso41562881cf.0 for ; Mon, 31 Aug 2026 08:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788189810; x=1788794610; darn=postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=jQ7318om/Vhriii/89PBC/7SV63HC0dEQWAxUiYLrQE=; b=Kgq8nEh4Zi/Pif372gpnJYN6LbdkCboC2Ytg2EBN86Rgj0IKc+anXu5HQFugIz4XMH Cajwd2KS9XfOcNLjp8iyePI7Yg4c93P1LpNQHX+6G0S4mvWFOW2aWBotCjRaI6kAnocP eZDFMlCBtGP7BpnA4aslTknmdGak7LdOIX91CLjqGzBgJfc3xom6SJLtIb6DjjcF2WvB YUa/u/8X3irREgGf0Yk66resUrvA5ZYNC3PdTfsQnEk+o6amEABt4lrpzJSfDzusOIY1 m89NMitwyPCfuo8j47VqTOOV84cZ2/heNuyOAUbz4bGMXwSodgK3zPXHTGfmiXLH9g0g pc7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788189810; x=1788794610; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jQ7318om/Vhriii/89PBC/7SV63HC0dEQWAxUiYLrQE=; b=FOJp/Im0nPTjrPTX8rWAxoAFV2VYIpPHs278PzdkZdg9JxkPIx7F1heGBL93ht0NmQ Uf5s3cgTVjpTdggQ2HOr/zVoQ7DyKvxpGVSuYBRhO4oS0lAZ6t+Z884l+2mFjLuAw9CS svxg5wqy0G8HofTgzW0L4oI7FQ+pwREgjqjErehLhMIL1VfKd5w2coJJmv45JBUvK509 6MVuYI7xn6BObz3jmvLQ06uQYu74eL0RHj/v4UMGZxjysJcBatL8mKma4UR/katHyANj mdUIPkioAuyNGRpPg0kURjEJe/u+GSLQyMgHZk4pdWDQqUyQfdq1nHvUBw4rGxRfYMmJ IDsg== X-Forwarded-Encrypted: i=1; AHgh+Rq3a8rJdB2U9W41m+r0dJd6wZR4MfyauarleLuhVwsiMFXUP4xMHfO3bj5hAlwx7YK1R8PR1ZLrzywuih6J@postgresql.org X-Gm-Message-State: AFuF++nd48SqXOmmovLso6S5Ysa5C/lpaEEqo9x7f4hDVLm/uaDrMA1w Slma7TVLviRFiKLLeQUgvkzCjIVNP0c/f1n7PkpLSk8Adix1w8ZSPelF X-Gm-Gg: AR+sD11LT5BTL33m0ORHtaYeXrkam5CXwWv8LvsVcQHeuvXkjfyzkkNrRzYZ/jbx41a bZQlUrlbr+05Z5EYLvNgaMUdHHYJFh5W0MjsNL7ReSsWDRmC6v9Sxlmt5ZEciLG7PLmHUnOuUAB OioobtbhstIObx/j/pqJs2IFiF21jNaYGFaUVwTEpd4mb5vPIgrs4S3NTHWYRoowhrAjuRVCrwb GrmLQzU6t8EEKTzQKouzL/PxQDHNjvN+B/Eu4IdI6+wxsw1qOlPsDnTQuz1dGkHUCxWPfHIHAWm 3RTuCFX5MT5EMdy8RVRu03+qyVECzk8bO5PoUFv9LRV7XPH66pGGKCPJY6yzvqbPyJrws/PWH4T 1yxTw1f8nNOz5yXLBytBc6maHF17PPUPjPX07ndP4f9EsSqVFJR2hAPekbzxg2rYtWIShesoVCc mPND7g11k1hdJWQ0n9uClgnyz/XWB1diKBYtZqqi0fl1Ce72cdV1ni1e8VqK9u8+dZihfT1/J6B bWg25Rl6tlM80mVIYabdI92M9vINYcoGXvxpxpl13BUoytkf1QixsxmKThbNDO0Vrbwl8cjpzNA 4UaYt7ReX4tHOZY= X-Received: by 2002:a05:622a:4d4f:b0:52f:b747:146 with SMTP id d75a77b69052e-52fb94aee8emr358926071cf.25.1788189810183; Mon, 31 Aug 2026 08:23:30 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-52fbe5a6422sm73988791cf.12.2026.08.31.08.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 08:23:28 -0700 (PDT) Date: Mon, 31 Aug 2026 10:23:26 -0500 From: Nathan Bossart To: Sami Imseih Cc: David Rowley , Bharath Rupireddy , Jim Nasby , Greg Burd , Robert Haas , Robert Treat , Jeremy Schneider , pgsql-hackers Subject: Re: another autovacuum scheduling thread Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vj2G5GTUtDziqSI7" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --vj2G5GTUtDziqSI7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Claude noticed a corner case that needs handling. In short, if the freeze score weights are high enough, the pow() calls can have the opposite of the intended effect, since the freeze scores may be less than 1. Patch attached. -- nathan --vj2G5GTUtDziqSI7 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-Fix-backwards-scaling-of-autovacuum-freeze-scores.patch From 2b2942e38db24d84aeb17a9075d4173b2b797fa9 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 31 Aug 2026 10:09:37 -0500 Subject: [PATCH v1 1/1] Fix backwards scaling of autovacuum freeze scores. Presently, once a table's age passes the effective failsafe age, relation_needs_vacanalyze() raises the ratio of that age to the freeze-max-age to a power of at least 1.0, so that the table sorts towards the front of the list. That amplifies the score only while the ratio is above 1.0. Below it, exponentiation shrinks the score, and shrinks it further as the age grows, so a table can cross into the failsafe range and see its score fall, and keep falling as it ages. Ratios below 1.0 are reachable because the effective failsafe age is divided by autovacuum_freeze_score_weight, which can leave it under the freeze-max-age. With autovacuum_freeze_max_age at 2000000000 and the weight at 10.0, tables aged 220M, 400M, and 736M score 0.078, 0.016, and 0.0064, which is exactly backwards, and all three sit below what they would score with no scaling at all. To fix, only scale a score that the exponentiation will actually amplify. Raising the weight still starts the scaling earlier, just not so early that it does the opposite of what it is for. The default configuration is unaffected, since there scaling begins at an age of 1.6 billion, where the ratio is already 8.0. Oversight in commit d7965d65fc. Backpatch-through: 19 --- src/backend/postmaster/autovacuum.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 393e81d53e9..13d330913be 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -3210,9 +3210,15 @@ relation_needs_vacanalyze(Oid relid, if (autovacuum_multixact_freeze_score_weight > 1.0) effective_mxid_failsafe_age /= autovacuum_multixact_freeze_score_weight; - if (xid_age >= effective_xid_failsafe_age) + /* + * Note that raising a score below 1.0 to a power greater than 1.0 shrinks + * it, and shrinks it further as the age grows, so scaling such a score + * would leave an older table sorting behind a younger one. Only scale + * scores that the exponentiation will actually amplify. + */ + if (xid_age >= effective_xid_failsafe_age && scores->xid > 1.0) scores->xid = pow(scores->xid, Max(1.0, (double) xid_age / 100000000)); - if (mxid_age >= effective_mxid_failsafe_age) + if (mxid_age >= effective_mxid_failsafe_age && scores->mxid > 1.0) scores->mxid = pow(scores->mxid, Max(1.0, (double) mxid_age / 100000000)); scores->xid *= autovacuum_freeze_score_weight; -- 2.55.0 --vj2G5GTUtDziqSI7--