diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index e55700f35b8..17d94d7ce58 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -8934,6 +8934,42 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; + + autovacuum_vacuum_truncate (boolean) + + autovacuum_vacuum_truncate + configuration parameter + + + + + Enables or disables autovacuum to try to truncate off any empty pages + at the end of the tables, as it processes them. The default value is + true. + + If true, autovacuum will perforn the truncation and + the disk space for the truncated pages is returned to the operating + system. + + This is normally the desired behavior and is the default unless the + vacuum_truncate option for a table being vacuumed + has been set to false. + + If false, autovacuum will not perform the truncation + on any tables it vacuums. The vacuum_truncate option + on the tables is ignored. + + Note that the truncation requires ACCESS EXCLUSIVE + lock on the table. + + Setting this option to false may be useful to avoid + ACCESS EXCLUSIVE lock on the table that the + truncation requires. + + + + + diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index ddb303f5201..d8261a9b19d 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -115,6 +115,7 @@ * GUC parameters */ bool autovacuum_start_daemon = false; +bool autovacuum_vacuum_truncate = true; int autovacuum_worker_slots; int autovacuum_max_workers; int autovacuum_work_mem = -1; @@ -2812,12 +2813,16 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map, (!wraparound ? VACOPT_SKIP_LOCKED : 0); /* - * index_cleanup and truncate are unspecified at first in autovacuum. - * They will be filled in with usable values using their reloptions - * (or reloption defaults) later. + * index_cleanup is unspecified at first in autovacuum. truncate is + * unspecified, unless it is disabled via the GUC parameter. + * + * The unspecified options will be filled in with usable values using + * their reloptions (or reloption defaults) later. */ tab->at_params.index_cleanup = VACOPTVALUE_UNSPECIFIED; - tab->at_params.truncate = VACOPTVALUE_UNSPECIFIED; + tab->at_params.truncate = (autovacuum_vacuum_truncate == false) + ? VACOPTVALUE_DISABLED + : VACOPTVALUE_UNSPECIFIED; /* As of now, we don't support parallel vacuum for autovacuum */ tab->at_params.nworkers = -1; tab->at_params.freeze_min_age = freeze_min_age; diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index ad25cbb39c5..d1443256110 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -1531,6 +1531,16 @@ struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, + { + {"autovacuum_vacuum_truncate", PGC_SIGHUP, VACUUM_AUTOVACUUM, + gettext_noop("Disables autovacuum behavior of truncatiing relations."), + NULL + }, + &autovacuum_vacuum_truncate, + true, + NULL, NULL, NULL + }, + { {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS, gettext_noop("Generates debugging output for LISTEN and NOTIFY."), diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h index 6a95e5f55bd..d0bd6f498c7 100644 --- a/src/include/postmaster/autovacuum.h +++ b/src/include/postmaster/autovacuum.h @@ -28,6 +28,7 @@ typedef enum /* GUC variables */ extern PGDLLIMPORT bool autovacuum_start_daemon; +extern PGDLLIMPORT bool autovacuum_vacuum_truncate; extern PGDLLIMPORT int autovacuum_worker_slots; extern PGDLLIMPORT int autovacuum_max_workers; extern PGDLLIMPORT int autovacuum_work_mem;