mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
Add option PROCESS_TOAST to VACUUM
This option controls if toast tables associated with a relation are vacuumed or not when running a manual VACUUM. It was already possible to trigger a manual VACUUM on a toast relation without processing its main relation, but a manual vacuum on a main relation always forced a vacuum on its toast table. This is useful in scenarios where the level of bloat or transaction age of the main and toast relations differs a lot. This option is an extension of the existing VACOPT_SKIPTOAST that was used by autovacuum to control if toast relations should be skipped or not. This internal flag is renamed to VACOPT_PROCESS_TOAST for consistency with the new option. A new option switch, called --no-process-toast, is added to vacuumdb. Author: Nathan Bossart Reviewed-by: Kirk Jamison, Michael Paquier, Justin Pryzby Discussion: https://postgr.es/m/BA8951E9-1524-48C5-94AF-73B1F0D7857F@amazon.com
This commit is contained in:
@ -104,6 +104,7 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
|
||||
bool freeze = false;
|
||||
bool full = false;
|
||||
bool disable_page_skipping = false;
|
||||
bool process_toast = true;
|
||||
ListCell *lc;
|
||||
|
||||
/* Set default value */
|
||||
@ -140,6 +141,8 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
|
||||
disable_page_skipping = defGetBoolean(opt);
|
||||
else if (strcmp(opt->defname, "index_cleanup") == 0)
|
||||
params.index_cleanup = get_vacopt_ternary_value(opt);
|
||||
else if (strcmp(opt->defname, "process_toast") == 0)
|
||||
process_toast = defGetBoolean(opt);
|
||||
else if (strcmp(opt->defname, "truncate") == 0)
|
||||
params.truncate = get_vacopt_ternary_value(opt);
|
||||
else if (strcmp(opt->defname, "parallel") == 0)
|
||||
@ -189,13 +192,13 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
|
||||
(analyze ? VACOPT_ANALYZE : 0) |
|
||||
(freeze ? VACOPT_FREEZE : 0) |
|
||||
(full ? VACOPT_FULL : 0) |
|
||||
(disable_page_skipping ? VACOPT_DISABLE_PAGE_SKIPPING : 0);
|
||||
(disable_page_skipping ? VACOPT_DISABLE_PAGE_SKIPPING : 0) |
|
||||
(process_toast ? VACOPT_PROCESS_TOAST : 0);
|
||||
|
||||
/* sanity checks on options */
|
||||
Assert(params.options & (VACOPT_VACUUM | VACOPT_ANALYZE));
|
||||
Assert((params.options & VACOPT_VACUUM) ||
|
||||
!(params.options & (VACOPT_FULL | VACOPT_FREEZE)));
|
||||
Assert(!(params.options & VACOPT_SKIPTOAST));
|
||||
|
||||
if ((params.options & VACOPT_FULL) && params.nworkers > 0)
|
||||
ereport(ERROR,
|
||||
@ -318,6 +321,13 @@ vacuum(List *relations, VacuumParams *params,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("VACUUM option DISABLE_PAGE_SKIPPING cannot be used with FULL")));
|
||||
|
||||
/* sanity check for PROCESS_TOAST */
|
||||
if ((params->options & VACOPT_FULL) != 0 &&
|
||||
(params->options & VACOPT_PROCESS_TOAST) == 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("PROCESS_TOAST required with VACUUM FULL")));
|
||||
|
||||
/*
|
||||
* Send info about dead objects to the statistics collector, unless we are
|
||||
* in autovacuum --- autovacuum.c does this for itself.
|
||||
@ -1895,7 +1905,8 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params)
|
||||
* us to process it. In VACUUM FULL, though, the toast table is
|
||||
* automatically rebuilt by cluster_rel so we shouldn't recurse to it.
|
||||
*/
|
||||
if (!(params->options & VACOPT_SKIPTOAST) && !(params->options & VACOPT_FULL))
|
||||
if ((params->options & VACOPT_PROCESS_TOAST) != 0 &&
|
||||
(params->options & VACOPT_FULL) == 0)
|
||||
toast_relid = onerel->rd_rel->reltoastrelid;
|
||||
else
|
||||
toast_relid = InvalidOid;
|
||||
|
Reference in New Issue
Block a user