Re: Add pg_stat_autovacuum_priority
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: Robert Treat <rob@xzilla.net>, satyanarlapuram@gmail.com, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-03-31T18:09:43Z
Lists: pgsql-hackers
Hi, On Mon, Mar 30, 2026 at 11:16 AM Sami Imseih <samimseih@gmail.com> wrote: > > > I think we are also in agreement here, although based on my > > experience, filtering out things like system and toast tables will be > > common, but I don't see that changing what you said above. On a > > similar note, +1 to your changes in v2. > > Thanks! > > v3 now includes the refactoring [1] suggestion brought up by Alvarro Thank you for sending the latest patches. Here are some comments: 1/ + while ((classTup = heap_getnext(relScan, ForwardScanDirection)) != NULL) Missing check_for_interrupts call while scanning the pg_class system catalog. 2/ + avopts = extract_autovac_opts(classTup, pg_class_desc); + + compute_autovac_score(classTup, pg_class_desc, + effective_multixact_freeze_max_age, avopts, + true, &dovacuum, &doanalyze, + &wraparound, &scores); + + if (avopts) + pfree(avopts); + When a database has a large number of tables (which is quite common in production scenarios), I expect the costs of palloc and pfree being used for fetching autovacuum relopts would make this function slower. Can we invent a new function or pass a caller-allocated AutoVacOpts memory to just copy the relopts and use that in this tight loop when scanning for all the relations? 3/ + 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); 4/ + The <link linkend="monitoring-pg-stat-autovacuum-priority-view"> + <structname>pg_stat_autovacuum_priority</structname></link> view can be + used to inspect each table's autovacuum need and priority score. How about adding "as of the moment" to convey that it doesn't report what currently running autovacuum or pending autovacuum would consider? 5/ Also, can we add a simple paragraph on how to interpret and take actions based on the scores reported (like prioritizing one table over the other - adjust these parameters in the table's relopts or something like that - no need to cover all the possible cases, but just one example would be sufficient for the user to understand)? 6/ + descr => 'statistics: autovacuum priority scores for all relations', s/"for all relations"/"for all relations in the current database" 7/ Addition of force_scores to relation_needs_vacanalyze makes the code unreadable (IMO) with a lot of if-else branching. Why not make force_vacuum an option and pass it as true from the stats function and leave a note in the function comment on when to use this parameter? Would something like that work? Also, when autovacuum is disabled (either via GUC or via relopts), we don't want to calculate and report any scores. IMHO, this keeps things simple and code readable. -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
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