Re: Add pg_stat_autovacuum_priority
Sami Imseih <samimseih@gmail.com>
From: Sami Imseih <samimseih@gmail.com>
To: Nathan Bossart <nathandbossart@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-01T02:46:16Z
Lists: pgsql-hackers
Attachments
- v4-0001-Always-compute-autovacuum-priority-scores.patch (application/octet-stream) patch v4-0001
- v4-0002-Add-elevel-parameter-to-relation_needs_vacanalyze.patch (application/octet-stream) patch v4-0002
- v4-0004-Add-pg_stat_autovacuum_priority-view.patch (application/octet-stream) patch v4-0004
- v4-0003-Refactor-autovacuum-score-computation-into-comput.patch (application/octet-stream) patch v4-0003
> > 1/ + while ((classTup = heap_getnext(relScan, ForwardScanDirection)) != NULL) > > > > Missing check_for_interrupts call while scanning the pg_class system catalog. > > From a glance I don't see one in the scanning code in do_autovacuum(), > either. I'm not sure we need to be worried about this. Yes, I will leave it out. Even for catalogs with thousands of tables, I don't foresee this being an issue. > > + values[8] = Float8GetDatum(scores.vac_ins); > > + values[9] = Float8GetDatum(scores.anl); > > > > Nit: It's a matter of taste. How about using something like below > > instead of hardcoded column numbers? I expect this view to grow in the > > future, so it helps to keep things simple. > > > > values[i++] = Float8GetDatum(scores.anl); > > Assert(i == NUM_AV_SCORE_COLS); > > I don't think either way is substantially better. I agree. using numbers is more readable IMO. > > + <row> > > + <entry role="catalog_table_entry"><para role="column_definition"> > > + <structfield>vacuum_dead_score</structfield> <type>double precision</type> > > + </para> > > + <para> > > + Score component based on the estimated number of dead tuples > > + needing removal by vacuum. > > + </para></entry> > > + </row> > > > > I think we should make sure the column names align with the names given to > > the new parameters [0] and the new "Autovacuum Prioritization" section in > > the docs [1]. > I will look into this in the next rev. The field names now match the GUC names (without the _weight). We might as well also make this name change in the AutoVacuumScore struct. I attached v4 which includes 4 patches in the set to address earlier comments: 0001: This modifies relation_needs_vacanalyze() to always compute the score so the monitoring view can report the score regardless if autovacuum is enabled on the table. AutoVacuumScores is renamed to AutoVacuumPriority as it now also tracks needs_analyze, needs_vacuum and is_wraparound which are different from the dovacuum, doanalyze and wraparound output parameters which are acted on by autovacuum. This is a clean separation of reporting the scores/needs for autovacuum/analyze and the eligibility for autovacuum which is based on the state of autovacuum being enabled and set on the table level. 0002: relation_needs_vacanalyze() takes a new elevel argument to control logging. Callers pass DEBUG3 for autovacuum or 0 to suppress logging. 0003: Alvaro's earlier suggestion to factor out recheck_relation_needs_vacanalyze() and introduce compute_autovac_score() 0004: The view implementation with field names that better match the GUCs as suggested by Nathan in an earlier comment. -- Sami
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