Add options to control whether VACUUM runs vac_update_datfrozenxid.
Tom Lane <tgl@sss.pgh.pa.us>
Add options to control whether VACUUM runs vac_update_datfrozenxid. VACUUM normally ends by running vac_update_datfrozenxid(), which requires a scan of pg_class. Therefore, if one attempts to vacuum a database one table at a time --- as vacuumdb has done since v12 --- we will spend O(N^2) time in vac_update_datfrozenxid(). That causes serious performance problems in databases with tens of thousands of tables, and indeed the effect is measurable with only a few hundred. To add insult to injury, only one process can run vac_update_datfrozenxid at the same time per DB, so this behavior largely defeats vacuumdb's -j option. Hence, invent options SKIP_DATABASE_STATS and ONLY_DATABASE_STATS to allow applications to postpone vac_update_datfrozenxid() until the end of a series of VACUUM requests, and teach vacuumdb to use them. Per bug #17717 from Gunnar L. Sadly, this answer doesn't seem like something we'd consider back-patching, so the performance problem will remain in v12-v15. Tom Lane and Nathan Bossart Discussion: https://postgr.es/m/17717-6c50eb1c7d23a886@postgresql.org
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/ref/vacuum.sgml | modified | +37 −0 |
| src/backend/commands/vacuum.c | modified | +37 −5 |
| src/backend/postmaster/autovacuum.c | modified | +7 −2 |
| src/bin/psql/tab-complete.c | modified | +3 −2 |
| src/bin/scripts/t/100_vacuumdb.pl | modified | +12 −12 |
| src/bin/scripts/vacuumdb.c | modified | +33 −0 |
| src/fe_utils/parallel_slot.c | modified | +3 −0 |
| src/include/commands/vacuum.h | modified | +2 −0 |
| src/test/regress/expected/vacuum.out | modified | +6 −0 |
| src/test/regress/sql/vacuum.sql | modified | +7 −0 |
Documentation touched
Discussion
- BUG #17717: Regression in vacuumdb (15 is slower than 10/11 and possible memory issue) 29 messages · 2022-12-13 → 2023-01-06