Re: Add pg_stat_autovacuum_priority
Nathan Bossart <nathandbossart@gmail.com>
From: Nathan Bossart <nathandbossart@gmail.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Robert Treat <rob@xzilla.net>, satyanarlapuram@gmail.com, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-04-01T21:28:45Z
Lists: pgsql-hackers
+ bool needs_vacuum; /* threshold exceeded for vacuum */
+ bool needs_analyze; /* threshold exceeded for analyze */
+ bool is_wraparound; /* at risk of XID/MXID wraparound */
I've been thinking about whether to also return whether autovacuum is
enabled in the view, i.e., AutoVacuumingActive() && av_enabled. My
instinct was that would help explain why autovacuum isn't picking up tables
that are eligible for autovacuum based on the view. One wrinkle is that
it'd report false even when autovacuum is working on a table for wraparound
prevention. I'm also not especially excited about further complicating
this stuff for folks who disable autovacuum. Furthermore, the value of the
reloptions and autovacuum GUC are discoverable elsewhere. So, I'm
currently leaning towards leaving that information out for now.
+ if (vactuples > vacthresh)
+ {
+ scores->needs_vacuum = true;
+ if (av_enabled && AutoVacuumingActive())
*dovacuum = true;
}
nitpick: We might be able to simplify this a bit by 1) storing "av_enabled
&& AutoVacuumingActive()" in a variable and 2) reworking the code to look
more like this:
scores->needs_vacuum = (vactuples > vacthresh);
*do_vacuum |= (av_enabled && scores->needs_vacuum);
... but others might find your version easier to read.
Otherwise, 0001 looks good.
In 0003, I think you missed renaming the last argument to
compute_autovac_score() in table_recheck_autovac().
I didn't see anything else in this read-through. I'm planning to start
preparing this for commit tomorrow.
--
nathan
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix double-free in pg_stat_autovacuum_scores.
- 71ff232a5bc4 19 (unreleased) landed
-
Add LOG_NEVER error level code.
- 60165db6e1f2 19 (unreleased) landed
-
Add pg_stat_autovacuum_scores system view.
- 87f61f0c8280 19 (unreleased) landed
-
Remove recheck_relation_needs_vacanalyze().
- 775fe51daaef 19 (unreleased) landed
-
Add elevel parameter to relation_needs_vacanalyze().
- 01876ace1369 19 (unreleased) landed
-
Teach relation_needs_vacanalyze() to always compute scores.
- 53b8ca6881a1 19 (unreleased) landed
-
Refactor relation_needs_vacanalyze().
- 8261ee24fe33 19 (unreleased) landed
-
Add rudimentary table prioritization to autovacuum.
- d7965d65fc5b 19 (unreleased) cited
-
Fix per-relation memory leakage in autovacuum.
- 02502c1bca54 18.0 cited
-
Fix recently-understood problems with handling of XID freezing, particularly
- 48188e1621bb 8.2.0 cited