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 1vBec2-002KtI-EF for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 19:35:09 +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 1vBec0-000vn6-7s for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 19:35:07 +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 1vBebz-000vmu-UC for pgsql-hackers@lists.postgresql.org; Wed, 22 Oct 2025 19:35:06 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBebw-003fOX-0X for pgsql-hackers@postgresql.org; Wed, 22 Oct 2025 19:35:06 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-363cb0cd8a1so365771fa.2 for ; Wed, 22 Oct 2025 12:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761161703; x=1761766503; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3RLiLIwpLTBuQ3iGEdOu44GPt7GImMDysDpE5YSRBJQ=; b=gDvPEMucTRVpoS9Qu4YpiYdr82Txonp2WECWuBToZtuwKNulRnlkR3fsOJOACjEF91 PIa7THkXZTFg8iVV0mgTuW9PW1CktpAtd7pklf/4BXUPcUmQwoQK1xEho64y261Qt5+i I06X/WHgJ+WMkjvw7mqlLJ09ntVP2iCvicQVmqpCHEsHIT65NvlThidWQSe1Fu4cye5a An0RYYgqxM1+FdAlTnweOsZNI7uPfFcaPO3zr3TS89fFGXK6IVDdBqQ9QsXQuPZN+NSA hqw7X0SgUvBKx7E2kIleYtZ1t0QEyZzabqa8BoLJcD6nMT9lvlg8Xrxf2EoxpB8O8Gbk IkOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761161703; x=1761766503; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3RLiLIwpLTBuQ3iGEdOu44GPt7GImMDysDpE5YSRBJQ=; b=XeuhXjXztl1s3xUTn6nEhF8Xv0ObsenuZ7PakXwkXvHa9GJYWB2yeUMSWHpzOneyHJ szgQvJDF4zfINl4+va81P1fS6uV/DbPjAlHcwLE+1CGF3TZNP/EIaxML259Zl8RrJ76Z gZnyWPyPxyFTDtFBMhKLhdHpHWY9Rkzp9pgr7aRhkuQLacz93enj4uuBXvdBIWWz9dU9 3wVj+kJXKXakbcLBdmo+8g/baJ9FYt4VeB6GOUdIyAkRQfF5aM32RNeS4rQZN/L5Xu0f 36zOxZIre2CktyMdPhKvyfrvjcJ2lzElTtfRBaAnziXNLnmarsAqEaQpdVX3XlhQl6m8 smIg== X-Forwarded-Encrypted: i=1; AJvYcCVqkcI+TH514KPBmO62Xe1Z98ERA6RAmSqno3cYOm6h2GMxdOUwMGhTswSOFObte0jAZo1LKtbYUL+U2rHn@postgresql.org X-Gm-Message-State: AOJu0YzerhvIup6jETP7le3rEAZy6zucBpFtAd7bMK8gODt3/GSX2U7A 5WJexUV6J9bsDxo6OmCKOOUrT18ABlgOEb6oKF60b44KIbpLTwL8/J2z4T0tMdf4bAxTxJOsKQi mPRxt6SYfzUZoaeCXtYYBWgQ+NX0l+Aw= X-Gm-Gg: ASbGnculRsSNqNsy87Lkkt985o9zTrQ3sfE7vQZYRa0SLhLBa9t22Hq4h2LaamWJNf7 C1F2QPKUz3idxCialr+1Vlr80ODGrVr2YxBBT46i0Rs3+IemAgiBUse2khcNhP4BPst0zvR+ek2 4OKwEsnP5iwRoS050Pswcq65pLzijbBdxyfMcui67BddRFzKyC7RaKjkTxeBZubuGN1sGASyrbl x7sAMsNpaOZ0JstBXpATAgbaCfviyQzMQgCVKmCFM3zlY0VmM1fKihiEMA6/68LtgTf/FIA9nuq 3gE13J2ym19HnEJoL4GBW7Mmz0kpar+Dc+kqW5KuL/TdCXAK7xDTbccosXDr3AXd2ia4cAvx X-Google-Smtp-Source: AGHT+IERslW6DCa7yhbIUxEo6X8VlFiY0Bctf/EifiEN6qeSTSTv1ijmPxVjnak7EN9KWmWGxrma+ICeilREcj8c9xc= X-Received: by 2002:a2e:bcc1:0:b0:376:2802:84a8 with SMTP id 38308e7fff4ca-377979b3d6fmr77211201fa.46.1761161702450; Wed, 22 Oct 2025 12:35:02 -0700 (PDT) MIME-Version: 1.0 References: <20251008182520.6e05a8b8@ardentperf.com> <20251008184740.328d45de@ardentperf.com> In-Reply-To: From: David Rowley Date: Thu, 23 Oct 2025 08:34:49 +1300 X-Gm-Features: AS18NWBLgqErE21VxzMGMuzaL01vJO48sXswl_fy3QtgeCgro8MP8ESWqJiTJ2s Message-ID: Subject: Re: another autovacuum scheduling thread To: Nathan Bossart Cc: Robert Haas , Jeremy Schneider , Sami Imseih , pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 23 Oct 2025 at 07:58, Nathan Bossart wrote: > > That's a good point. I wonder if we should try to make the wraparound > > score independent of the *_freeze_max_age parameters (once the table age > > surpasses said parameters). Else, different settings will greatly impact > > how aggressively tables are prioritized the closer they are to wraparound. > > Even if autovacuum_freeze_max_age is set to 200M, it's not critically > > important for autovacuum to pick up tables right away as soon as their age > > reaches 200M. But if the parameter is set to 2B, we _do_ want autovacuum > > to prioritize tables right away once their age reaches 2B. > > I'm imagining something a bit like the following: > > select xidage "age(relfrozenxid)", > power(1.001, xidage::float8 / (select min_val > from pg_settings where name = 'autovacuum_freeze_max_age')::float8) > xid_age_score from generate_series(0,2_000_000_000,100_000_000) xidage; > > age(relfrozenxid) | xid_age_score > -------------------+-------------------- > 0 | 1 > 100000000 | 2.7169239322355936 > 200000000 | 7.38167565355452 > 300000000 | 20.055451243143093 This does start to put the score > 1 before the table reaches autovacuum_freeze_max_age. I don't think that's great as the score of 1.0 was meant to represent that the table now requires some autovacuum work. The main reason I was trying to keep the score scaling with the percentage over the given threshold that the table is was that I had imagined we could use the score number to start reducing the sleep time between autovacuum_vacuum_cost_limit when the highest scoring table persists in being high for too long. I was considering this to fix the misconfigured autovacuum problem that so many people have. If we scaled it the way similar to the query above, the score would look high even before it reaches the limit. This is the reason I was scaling the score linear with the autovacuum_freeze_max_age with the version I sent and only scaling exponentially after the failsafe age. I wanted to talk about the "reducing the cost delay" feature separately so as not to load up this thread and widen the scope for varying opinions, but in its most trivial form, the vacuum_cost_limit() code could be adjusted to only sleep for autovacuum_vacuum_cost_delay / . I think the one I proposed in [1] does this quite well. The table remains eligible to be autovacuumed with any score >= 1.0, and there's still a huge window of time to freeze a table once it's over autovacuum_freeze_max_age before there are issues and the exponential scaling once over failsafe age should ensure that the table is top of the list for when the failsafe code kicks in and removes the cost limit. If we had the varying sleep time as I mentioned above, the failsafe code could even be removed as the "autovacuum_vacuum_cost_delay / " calculation would effectively zero the sleep time with any table > failsafe age. David [1] https://postgr.es/m/CAApHDvqrd=SHVUytdRj55OWnLH98Rvtzqam5zq2f4XKRZa7t9Q@mail.gmail.com