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 1w6L9g-004CX7-18 for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 04:20:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w6L9e-00DKHP-2k for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 04:20:11 +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 1w6L9e-00DKHG-1R for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2026 04:20:10 +0000 Received: from mail-ua1-x92d.google.com ([2607:f8b0:4864:20::92d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w6L9c-00000001REZ-2dX3 for pgsql-hackers@postgresql.org; Sat, 28 Mar 2026 04:20:09 +0000 Received: by mail-ua1-x92d.google.com with SMTP id a1e0cc1a2514c-951a4e8d1b5so854114241.1 for ; Fri, 27 Mar 2026 21:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774671607; cv=none; d=google.com; s=arc-20240605; b=hKONAaCFN7w+VEnqNLtZWTwlt2ZYxKoPakBDEVNGc8bjmRHT48bAzCkNNcxAASjoMD /X5V8IyGupM47DaTyq93WA6SFImoU9BfvoXSmNOwS+umO51AwEMUyTJfQ1M4BZT2tmEd 7bpSN52461FidXoSbc5lUi+xrq5/LAy9D57TuKYz0KkvH6ddwRz9rQfJldIG46a+wPsT A5b7wiacOcGGgcCngQE/mXBOvm0BPeHlTGo+eYoWqNuVfdNjztzMJ+E6Hhckqfisz3fL inrDl5XjAW5h5CENN2CCSlmwHwhiElkdLyrt4Gpmc6vHCSgQNow3Mnx9UZZsaHK5rBr8 Neaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=EC0BQQ5UcoHhcr0zb1zXFXPYzIKoBIfTkzWugouPnOo=; fh=eVUSIqo8oW6GlS9+lJ2dMbh393DkmW/G0CKaTSrcg9Y=; b=UDDk71iXjHRq7Se9gfk3D9tYg0/hhR0B4+4fePB+hUUrswxigkXt+22zxkBgkPmmH/ LkKosPpqBBUwIg8mlg2PJkHyPYNqxX5bfCWW82jbd71uyLbIc7Jwp9NCl4Eqj4QdzxQo zCHZP7xHkPU0lrcxXcJTvALCyvFQkNAbKjxvQC3iaNmcOCox4MAnEzzlHcrpUTllFeWo Q196ckUgYh0W3PUvJyUwcXsSwIOWTGywT3a6eUrHh3lNhHkYHJTAbpD9l5sWt9xuEwVv FRkw9xIK4qffch8ydNkyAKqoKyTN8JIOJnvca7Wtf+Lm1AavQiP7seCW+HCbe5jcEWQH t93w==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774671607; x=1775276407; 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=EC0BQQ5UcoHhcr0zb1zXFXPYzIKoBIfTkzWugouPnOo=; b=XobxcgthgtxYp7lvy6tRsxl1AjE96eh0pBva58IMzONoPi3CmZA1278woVV2Vur7wT IO+wMp/7qBKkG5OIly6lC7rKNHClPKLwFU6dlszprbE3KY54PgrqsjF3/1WLG4PxwmJT pdKtaWbALihzHVU5MHty04sLPVGUp8uqCliyT7KADAZ/F4rY24oKWeizJ/TcHgOF3YhT c5wW4lck2UErtfE3HX5/EH1yWhtcrvrlm21f2iBeHQQhD4ghfLqcGrqV4wRojYKa3yb5 pMeGnRd5rN6rODoBgqcikvt1rTXC6GFR4DUQVRGtzMbWooDpDoOa+m4/PXMrzCyNz05h iNiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774671607; x=1775276407; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EC0BQQ5UcoHhcr0zb1zXFXPYzIKoBIfTkzWugouPnOo=; b=MkSfz0rjSLAXJxS9kb3POunIpfsN4jLztPi5t57Pu77GWsUCLxQ0McSBN48y95Ui2o SknPAigyMrpnIXirrE+PYdB084BP/mC/qbS5fx3BqG2WsBQpHcSPTWFfGle8DGL4C1nz WhiuSp+ZULb+weWpVW0EZ1qI49Fyv1jOpIagwYHfce2fkTCOEtbJbpscKMszobLMRTn+ LmnZY/S+kT1U+9SbxLV1A+k4yf+zwZU+MMU4pnU4Lpv5Kv0qq66FqT9bHuMVMpeVkhP7 0WDudLbjAsxEEUbTtmDQs+s/ZGzwJEPUsTWcKZPRh824LP/rtx99+mykZyUwWc12S0X8 W5Nw== X-Gm-Message-State: AOJu0YzLf8VlH+GNZXM/8fJFG0mJptpdhzcm8zInzLoOtCsMG7WPrBZe x3+U5tUOwZZKzwbkOP7tfUN4uHaZhdc/1uYLsltHAZc3hLHiSZyk4thfWAns5tlsDgOti4SxEbo x35aPzpPKx0RGoapOvQ6Co4STw+1MlHt2Gb4n1RQ= X-Gm-Gg: ATEYQzyRXAyXZvxnYjF9PeEyuMogjYlIdrta3Q7SGUYbI5fQwJOuuTY4+vGYi5fjUVk 8tVUYdmWAzuL/Te4XgdD2OEJW6gPTKwuYMoEbiPxf6pB6PnKwALrMuCpknzDCNXdUkxMpnzyY+o RsQE4xIcQyMeV8yNequsn2ZJpa1rafp3Xb68a4kQYYzo7Sz4bmop4Y2yK/I/JYduF5bh2kCN7pH H+FuzIgDDs252VNXXq0fK6Z05mdBHKRfH/AFceaMtdPbtKFnxJwDAQmu0Uh+IXwfAcrjv6TtNRp p3H1t29/iounInur3UOwKJ2J3hVO6FbidlIbt7k= X-Received: by 2002:a05:6102:6e86:b0:5fd:ff75:f41d with SMTP id ada2fe7eead31-604f928c384mr1592216137.24.1774671607099; Fri, 27 Mar 2026 21:20:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: SATYANARAYANA NARLAPURAM Date: Fri, 27 Mar 2026 21:19:55 -0700 X-Gm-Features: AQROBzAW-SN8u3_kW5VWG5C7bCTqe5VxW918tgjpEWGTeN5t6c1dbXclXtb8o3o Message-ID: Subject: Re: Add pg_stat_autovacuum_priority To: Sami Imseih Cc: pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000bbf636064e0deeb3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000bbf636064e0deeb3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 27, 2026 at 9:14=E2=80=AFPM SATYANARAYANA NARLAPURAM < satyanarlapuram@gmail.com> wrote: > > Hi Sami, > > > On Fri, Mar 27, 2026 at 4:14=E2=80=AFPM Sami Imseih = wrote: > >> Hi, >> >> This is a quick follow-up to the commit d7965d65f which >> introduced autovacuum prioritization based on a score that >> is the Max of several components, such as vacuum >> thresholds, xid age, etc. >> >> It was also discussed in that thread [1] that we will need >> a view to expose the priority scores, per table in a view. >> This will allow a user to introspect what the autovacuum >> launcher will prioritize next as well as verify tuning >> efforts for autovacuum prioritization; the latter case >> likely being rare. >> >> So after spending time on this today, I am proposing a view >> that returns a line for each relation with information >> about if the table needs autovacuum/autoanalyze, as well as >> scores of each component and the Max score. It looks like >> the below: >> >> ``` >> postgres=3D# select * FROM pg_stat_autovacuum_priority; >> -[ RECORD 1 ]-----+---------------------------- >> relid | 16410 >> schemaname | public >> relname | av_priority_test >> needs_vacuum | f >> needs_analyze | f >> wraparound | f >> score | 0 >> xid_score | 0 >> mxid_score | 0 >> vacuum_dead_score | 0 >> vacuum_ins_score | 0 >> analyze_score | 0 >> ``` >> >> The function essentially calls relation_needs_vacanalyze() >> with some setup work, such as scanning the catalog with an >> AccessShareLock, etc. and emits the result of this call. >> >> To make this work 0001 introduces a small change to >> relation_needs_vacanalyze() to take in a boolean to force >> the calculation of the score (even if autovacuum is >> disabled for the relation). >> >> 0002 introduces the view with documentation and testing in >> vacuum.c (xid age and mxid age scores are not tested as >> they require xid_wraparound to consume enough XIDs to >> trigger a score, which will cost too much time for a >> regression test). >> >> Find the attached taking the first attempt at this view. >> >> [1] [ >> https://www.postgresql.org/message-id/CAApHDvqQN-B2sQov8nsfZOmx-VeJMauSf= 4kLa3A8LsK1tUyBNw%40mail.gmail.com >> ] >> > > > Thanks for adding this. Applied the patch and the tests passed. I haven't > fully reviewed the patch but have a few comments below: > > 1. Please ass CFI in the function pg_stat_get_autovacuum_priority, as the > list of tables can be very long > > + while ((tuple =3D heap_getnext(relScan, ForwardScanDirection)) !=3D NUL= L) > + { > > 2. Should we add filtering? The current approach > pg_stat_get_autovacuum_priority does a full catalog scan without any > filters and can be expensive. > > 3. Please add tests for tables with autovacuum =3D off > > 4. Is the view intended to be exposed to PUBLIC without any ACL > restrictions? > > 5. Catalog version number needs to be increased > > -#define CATALOG_VERSION_NO 202603241 > +#define CATALOG_VERSION_NO 202603231 > Additionally, do you expect this view to be available on the hot_Standby? Because on a hot standby, the view only provides useful wraparound risk data. All activity-based columns are blind. This should either be documented, or the function should check RecoveryInProgress() and raise an error/notice Thanks, Satya > --000000000000bbf636064e0deeb3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Mar 27,= 2026 at 9:14=E2=80=AFPM SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">

Hi Sami,


On Fri, Mar 27, 2026 at 4:14= =E2=80=AFPM Sami Imseih <samimseih@gmail.com> wrote:
Hi,

This is a quick follow-up to the commit d7965d65f which
introduced autovacuum prioritization based on a score that
is the Max of several components, such as vacuum
thresholds, xid age, etc.

It was also discussed in that thread [1] that we will need
a view to expose the priority scores, per table in a view.
This will allow a user to introspect what the autovacuum
launcher will prioritize next as well as verify tuning
efforts for autovacuum prioritization; the latter case
likely being rare.

So after spending time on this today, I am proposing a view
that returns a line for each relation with information
about if the table needs autovacuum/autoanalyze, as well as
scores of each component and the Max score. It looks like
the below:

```
postgres=3D# select * FROM pg_stat_autovacuum_priority;
-[ RECORD 1 ]-----+----------------------------
relid=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 16410
schemaname=C2=A0 =C2=A0 =C2=A0 =C2=A0 | public
relname=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| av_priority_test
needs_vacuum=C2=A0 =C2=A0 =C2=A0 | f
needs_analyze=C2=A0 =C2=A0 =C2=A0| f
wraparound=C2=A0 =C2=A0 =C2=A0 =C2=A0 | f
score=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 0
xid_score=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 0
mxid_score=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 0
vacuum_dead_score | 0
vacuum_ins_score=C2=A0 | 0
analyze_score=C2=A0 =C2=A0 =C2=A0| 0
```

The function essentially calls relation_needs_vacanalyze()
with some setup work, such as scanning the catalog with an
AccessShareLock, etc. and emits the result of this call.

To make this work 0001 introduces a small change to
relation_needs_vacanalyze() to take in a boolean to force
the calculation of the score (even if autovacuum is
disabled for the relation).

0002 introduces the view with documentation and testing in
vacuum.c (xid age and mxid age scores are not tested as
they require xid_wraparound to consume enough XIDs to
trigger a score, which will cost too much time for a
regression test).

Find the attached taking the first attempt at this view.

[1] [https://www.postgresql.org/message-id/CAApHDvqQN-B2sQov8nsfZOmx= -VeJMauSf4kLa3A8LsK1tUyBNw%40mail.gmail.com]

<= /div>

Thanks for adding this. Applied the patch and the tests passe= d. I haven't fully reviewed the patch but have a few comments below:

1. Please ass CFI in the function=C2=A0pg_stat_get_a= utovacuum_priority, as the list of tables can be very long

+ while ((tuple =3D heap_getnext(relScan, ForwardScanDirection)) != =3D NULL)
+ {

2. Should we add filtering? The c= urrent approach pg_stat_get_autovacuum_priority does a full catalog scan wi= thout any filters and can be expensive.

3. Please = add tests for tables with autovacuum =3D off

4. Is= the=C2=A0view intended to be exposed to PUBLIC without any ACL restriction= s?

5. Catalog version number needs to be increased=

-#define CATALOG_VERSION_NO 202603241
+#define CATALOG_VERSION_NO 202603231

Additionally, do you expect this view to be available on th= e hot_Standby? Because on a hot standby, the view only provides useful wrap= around risk data. All activity-based columns are blind. This should either = be documented, or the function should check RecoveryInProgress() and raise = an error/notice

Thanks,
Satya
--000000000000bbf636064e0deeb3--