mirror of
https://github.com/postgres/postgres.git
synced 2026-03-28 13:23:48 -04:00
Autovacuum workers scan pg_class twice to collect the set of tables to process. The first pass is for plain relations and materialized views, and the second is for TOAST tables. When the worker finds a table to process, it adds it to the end of a list. Later on, it processes the tables in the same order as the list. This simple strategy has worked surprisingly well for a long time, but there have been many discussions over the years about trying to improve it. This commit introduces a scoring system that is used to sort the aforementioned list of tables to process. The idea is to have autovacuum workers prioritize tables that are furthest beyond their thresholds (e.g., a table nearing transaction ID wraparound should be vacuumed first). This prioritization scheme is certainly far from perfect; there are simply too many possibilities for any scoring technique to work across all workloads, and the situation might change significantly between the time we calculate the score and the time that autovacuum processes it. However, we have attemped to develop something that is expected to work for a large portion of workloads with reasonable parameter settings. The score is calculated as the maximum of the ratios of each of the table's relevant values to its threshold. For example, if the number of inserted tuples is 100, and the insert threshold for the table is 80, the insert score is 1.25. If all other scores are below that value, the table's score will be 1.25. The other criteria considered for the score are the table ages (both relfrozenxid and relminmxid) compared to the corresponding freeze-max-age setting, the number of update/deleted tuples compared to the vacuum threshold, and the number of inserted/updated/deleted tuples compared to the analyze threshold. Once exception to the previous paragraph is for tables nearing wraparound, i.e., those that have surpassed the effective failsafe ages. In that case, the relfrozenxid/relminmxid-based score is scaled aggressively so that the table has a decent chance of sorting to the front of the list. To adjust how strongly each component contributes to the score, the following parameters can be adjusted from their default of 1.0 to anywhere between 0.0 and 10.0 (inclusive). Setting all of these to 0.0 restores pre-v19 prioritization behavior: autovacuum_freeze_score_weight autovacuum_multixact_freeze_score_weight autovacuum_vacuum_score_weight autovacuum_vacuum_insert_score_weight autovacuum_analyze_score_weight This is intended to be a baby step towards smarter autovacuum workers. Possible future improvements include, but are not limited to, periodic reprioritization, automatic cost limit adjustments, and better observability (e.g., a system view that shows current scores). While we do not expect this commit to produce any earth-shattering improvements, it is arguably a prerequisite for the aforementioned follow-up changes. Reviewed-by: Sami Imseih <samimseih@gmail.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Reviewed-by: Greg Burd <greg@burd.me> Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Discussion: https://postgr.es/m/aOaAuXREwnPZVISO%40nathan |
||
|---|---|---|
| .. | ||
| src | ||
| KNOWN_BUGS | ||
| Makefile | ||
| MISSING_FEATURES | ||
| TODO | ||