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 1w6L51-004CQx-0O for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 04:15:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w6L3y-00DGKw-37 for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 04:14:19 +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.96) (envelope-from ) id 1w6L3y-00DGKm-24 for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2026 04:14:19 +0000 Received: from mail-vk1-xa2a.google.com ([2607:f8b0:4864:20::a2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w6L3v-00000001b9U-3y0y for pgsql-hackers@postgresql.org; Sat, 28 Mar 2026 04:14:18 +0000 Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-56cc67e01deso2590277e0c.3 for ; Fri, 27 Mar 2026 21:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774671253; cv=none; d=google.com; s=arc-20240605; b=Pnw9zP646OG8AiPghSPcm2fjVDUn0sNYB3IXvyIPYKhNEfb33aONVjB1RfniKZYwSV Hvzbg1qmr3SnS5/79ZzOTK0zKRPzXdeyrTKpFWo9lAvhkPCpdgmvFrCXxc0xqGATWjc0 FEi9CdYW2+oduCvTBI6Kln9pmFrhKg0j4/P5QF0U/D7YLmvgb73b1RfKxnfXOLQwh3QL q77H9ywCfOi6GwoJlKbgzA41A5VfkdhuHtPRHbrLIjrt7VdNB7WWrpZV3QceLs5AGAAZ cJFzGntesBUZ4ISQxi+vXk2YxMWF5DAXorRoibjCT+hSC/+0i2wtL48trGcKUP6PsRea nOZA== 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=TvW7mDBn1VLjru1S0sDFNdd9qufDztz22hwB+yLL16A=; fh=eVUSIqo8oW6GlS9+lJ2dMbh393DkmW/G0CKaTSrcg9Y=; b=c3Ofqp01LejS0jGa91w/aEblqFTDiTsHW/5QzQqstETOdoaxOyI38gcUFe+X3icu6R Sbz6U8j/SJwEL/pUZMO5a/Uz97v0F1jFdOdsn48/1d8W4dakvd7gb6NrXZDDmjhWEECg j8qC0t5ommpzeGYVcaiCfEuUddnf+vRo00yuYVm98YmyKHnMeaidGC3dHnpDg3t7cwrn 8PL0qbqt4sifMYgmawttzyPv/q+cMCT1JIBqK5VU8178bUMMsKc7VHNhlYKdzjFSGwYl X3IbYFGtBlq4gkjGlOmbKugv7dxIipD3WpvRZ5AtDL6LTw9Glnl5XfhJeQMSiRE6PyvZ 6Tcg==; 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=1774671253; x=1775276053; 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=TvW7mDBn1VLjru1S0sDFNdd9qufDztz22hwB+yLL16A=; b=WFGO0vGtbbHhXIxRElvDIK+ud20K0ZCvBG+wUr0tiwMwEFbjm3M9jpB4sbYQLZTz7m 2YSMpLRYsZdKJXeFdb50p8iu757HbxS+IqXEOZnaHv9lPxLou3Qq8u6RUwUqseaVWDJU sQYKo19CQVmA6344nzUPSWPuU802mCuI6hMTxsE1Y9k+9MRhm6+FTkrRUYncLK5O0MJh y96498KFtfWU+xtV0Rro2/6LsV3EqE/TahFypt5K47FqApPKpHH6p6giFPefQ66H3UPG zkKlzuPqZIAG4TSTQ+VuWBnPwrna4Bn8T5DQfyeplixP2p3zADJhg90w18JxP8Tb3+ns qH1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774671253; x=1775276053; 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=TvW7mDBn1VLjru1S0sDFNdd9qufDztz22hwB+yLL16A=; b=HbG7R0aUJP3aXF32m18ddo60NmbJlPrHZQqeuxj8HZcraaG5hzZotOSNMmfJ33NrAP byTZGiNtXo2Ioyt2j1vLg7knxC35PhDj03fpRnJTf6MetFOpQCa8MDMtxKM5koYrvvg4 AvR5cApsvqzRJREf2Hcbe3IbElrdEYlrp6lLyftMluowmsXwIKbfF9qDAWp5NN+tfPL0 e0VNUKwngUiG7nV5FVB5P7roy6TGTAGy/4IgZRbQ5RbFMe/QZxuuuI42EqkGxIV6N7iz Wyb5OunBu0/25z6EMgGIJ0RVUSJbG7npUSdfddtJ8D62cqyRrW1L4twm9kMhB8tEl/G3 m6ww== X-Gm-Message-State: AOJu0Yz6LJizJoRcYwL6w920EuD+NtsgcvHubXSHeRrYL8ybRlma/meC QxcPyv/OWT8tyD7hGFeLGQWickhkWKukNlGWlBNmUh8qgoecPQ9QpQYj1Nk54xTibLlceX8P9v0 9pktsHlQPb+9cAtE9zAtjYV/7UsD7jh5hAbjjqCA= X-Gm-Gg: ATEYQzyzcQB6xtymcI/xPlITC+jhDelDlgqd3KCitqBXsH1lH9An3cxdsmqV3kDaQLE y8mpMt+CgqsckkEyvthBnBvhRdIRJrMx80UQGqme8akvXW83ZqW1voH6PcUrZodsIa3ApEhRd6P r6Qgpe8ZUr8WSFJGRzF5RIIdBoa0vJUuV4+cLR6U3Snt+VqIfPmpJLWS4qbUymniz7omnHbY4HL wJUBbIEUXMFOLxpchj+X5rgJ7ZfwPblE9BzBeOKNRhgygBuaQQVqO3VevuBn7Y9zSLtJPcKvw3I neAo9tv/9KyRhid/ZAeRs8+531Z4B1Zo6T5RspqJ2/PuL3sOIw== X-Received: by 2002:a05:6102:304d:b0:5ef:248b:d533 with SMTP id ada2fe7eead31-604f92f8e5dmr2254922137.31.1774671253555; Fri, 27 Mar 2026 21:14:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: SATYANARAYANA NARLAPURAM Date: Fri, 27 Mar 2026 21:14:01 -0700 X-Gm-Features: AQROBzAQJWts-HPNuSTEXp2byC8iIjKcSNDU7pKd8kSKWpAtlNb8oSEFIlJxy6o Message-ID: Subject: Re: Add pg_stat_autovacuum_priority To: Sami Imseih Cc: pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000a94c0b064e0dd9c0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a94c0b064e0dd9c0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Sami, On Fri, Mar 27, 2026 at 4:14=E2=80=AFPM Sami Imseih w= rote: > 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-VeJMauSf4= kLa3A8LsK1tUyBNw%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 NULL) + { 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 Thanks, Satya --000000000000a94c0b064e0dd9c0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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 t= his. Applied the patch and the tests passed. I haven't fully reviewed t= he patch but have a few comments below:

1. Please = ass CFI in the function=C2=A0pg_stat_get_autovacuum_priority, as the list o= f tables can be very long

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

2. Should we add filtering? The current approach pg_stat_get_autov= acuum_priority does a full catalog scan without any filters and can be expe= nsive.

3. Please add tests for tables with autovac= uum =3D off

4. Is the=C2=A0view intended to be exp= osed to PUBLIC without any ACL restrictions?

5. Ca= talog version number needs to be increased

-#defin= e CATALOG_VERSION_NO 202603241
+#define CATALOG_VERSION_NO 20= 2603231

Thanks,
Satya=C2=A0
<= /div> --000000000000a94c0b064e0dd9c0--