diff options
author | Fujii Masao <fujii@postgresql.org> | 2019-05-08 02:10:33 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2019-05-08 02:10:33 +0900 |
commit | b84dbc8eb80b43e554891c459a19969d9fbdefe5 (patch) | |
tree | 3005b4dc1ca54c9ce9fd3c2d24b69ec12b680111 /src/backend/commands/vacuum.c | |
parent | 98719af6c2e30d538cd05cfe044f58ba4067b52b (diff) | |
download | postgresql-b84dbc8eb80b43e554891c459a19969d9fbdefe5.tar.gz postgresql-b84dbc8eb80b43e554891c459a19969d9fbdefe5.zip |
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
Diffstat (limited to 'src/backend/commands/vacuum.c')
-rw-r--r-- | src/backend/commands/vacuum.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 94fb6f26063..afdd3307acd 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -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 |