mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Add TRUNCATE parameter to VACUUM.
This commit adds new parameter to VACUUM command, TRUNCATE, which specifies that VACUUM should attempt to truncate off any empty pages at the end of the table and allow the disk space for the truncated pages to be returned to the operating system. This parameter, if specified, overrides the vacuum_truncate reloption. If neither the reloption nor the VACUUM option is used, the default is true, as before. Author: Fujii Masao Reviewed-by: Julien Rouhaud, Masahiko Sawada Discussion: https://postgr.es/m/CAD21AoD+qtrSDL=GSma4Wd3kLYLeRC0hPna-YAdkDeV4z156vg@mail.gmail.com
This commit is contained in:
@ -98,6 +98,7 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
|
||||
|
||||
/* Set default value */
|
||||
params.index_cleanup = VACOPT_TERNARY_DEFAULT;
|
||||
params.truncate = VACOPT_TERNARY_DEFAULT;
|
||||
|
||||
/* Parse options list */
|
||||
foreach(lc, vacstmt->options)
|
||||
@ -126,6 +127,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, "truncate") == 0)
|
||||
params.truncate = get_vacopt_ternary_value(opt);
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
@ -1760,6 +1763,16 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params)
|
||||
params->index_cleanup = VACOPT_TERNARY_DISABLED;
|
||||
}
|
||||
|
||||
/* Set truncate option based on reloptions if not yet */
|
||||
if (params->truncate == VACOPT_TERNARY_DEFAULT)
|
||||
{
|
||||
if (onerel->rd_options == NULL ||
|
||||
((StdRdOptions *) onerel->rd_options)->vacuum_truncate)
|
||||
params->truncate = VACOPT_TERNARY_ENABLED;
|
||||
else
|
||||
params->truncate = VACOPT_TERNARY_DISABLED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remember the relation's TOAST relation for later, if the caller asked
|
||||
* us to process it. In VACUUM FULL, though, the toast table is
|
||||
|
Reference in New Issue
Block a user