Hi, relation_needs_vacanalyze() computes the freeze score ages as recentXid - relfrozenxid and recentMulti - relminmxid, but both are read before pg_class is scanned. If a table's relfrozenxid or relminmxid advances in between, for example by a concurrent VACUUM or a table rewrite, the subtraction wraps to about 4 billion and the just-vacuumed table gets a score around 1e44, which can put it at the front of autovacuum's list. The window grows with the number of relations; with a few thousand tables, pg_stat_autovacuum_scores shows it hundreds of times a minute.
0001 treats the age as zero in that case. 0002 is a TAP test, using the existing autovacuum-worker-start injection point, that shows it for an autovacuum worker; it's for the record rather than for commit. Please find the attached patches. Thoughts? Regards, Baji Shaik
v1-0002-Add-a-test-for-the-autovacuum-freeze-score-wrapar.patch
Description: Binary data
v1-0001-Fix-wraparound-of-the-ages-used-for-autovacuum-fr.patch
Description: Binary data
