autovacuum_disable_relation_truncation.v2.patch
application/octet-stream
Filename: autovacuum_disable_relation_truncation.v2.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| doc/src/sgml/config.sgml | 36 | 0 |
| src/backend/postmaster/autovacuum.c | 9 | 4 |
| src/backend/utils/misc/guc_tables.c | 10 | 0 |
| src/include/postmaster/autovacuum.h | 1 | 0 |
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;
</listitem>
</varlistentry>
+ <varlistentry id="guc-autovacuum-vacuum-truncate" xreflabel="autovacuum_vacuum_truncate">
+ <term><varname>autovacuum_vacuum_truncate</varname> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>autovacuum_vacuum_truncate</varname></primary>
+ <secondary>configuration parameter</secondary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ 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
+ <literal>true</literal>.
+
+ If <literal>true</literal>, 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
+ <literal>vacuum_truncate</literal> option for a table being vacuumed
+ has been set to <literal>false</literal>.
+
+ If <literal>false</literal>, autovacuum will not perform the truncation
+ on any tables it vacuums. The <literal>vacuum_truncate</literal> option
+ on the tables is ignored.
+
+ Note that the truncation requires <literal>ACCESS EXCLUSIVE</literal>
+ lock on the table.
+
+ Setting this option to <literal>false</literal> may be useful to avoid
+ <literal>ACCESS EXCLUSIVE</literal> lock on the table that the
+ truncation requires.
+
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</sect2>
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;