Fix autovacuum's handling of TOAST storage parameters.

The previous commit made VACUUM apply a main table's storage
parameters to its TOAST table, as CREATE TABLE has long documented.
Autovacuum still gets this wrong in two ways.  It falls back to the
main table's autovacuum parameters only when the TOAST table has no
reloptions at all, so setting a single toast.* parameter silently
stops the rest from being inherited.  And it never consults the
main table for the non-autovacuum parameters, such as
vacuum_index_cleanup and vacuum_truncate.

To fix, combine the two sets with merge_toast_reloptions() rather
than choosing between them, and hand the main table's parameters
down to vacuum_rel() the way VACUUM now does.
pg_stat_autovacuum_scores uses the combined parameters for TOAST
tables as well; it has to collect the main relations' parameters
before it can do so, so it now makes a preliminary pass over
pg_class.

An existing shortcoming that this patch only makes worse is that
autovacuum remains oblivious to concurrent storage parameter
changes on the main table.  That is, the main table's parameters
may be captured long before its TOAST table is processed, and a
user may very well have altered the settings in the meantime.
Fixing that would likely require additional pg_class lookups, and
it's not clear if it's worth the trouble.

While this is a bug fix, it's too intrusive for back-patching, but
the issue seems to have gone unnoticed for a very long time,
anyway.

Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Sami Imseih <[email protected]>
Reviewed-by: Greg Burd <[email protected]>
Tested-by: solai v <[email protected]>
Discussion: https://postgr.es/m/aFRxC1W_kZU9OjJ9%40nathan

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fad70a09ff43724b521f7e450d894a93d54330a0

Modified Files
--------------
src/backend/postmaster/autovacuum.c                | 151 +++++++++++++++------
src/test/modules/test_autovacuum/meson.build       |   1 +
.../modules/test_autovacuum/t/002_toast_relopts.pl |  69 ++++++++++
3 files changed, 181 insertions(+), 40 deletions(-)

Reply via email to