</note>
</sect2>
+ <sect2 id="runtime-config-vacuum-default">
+ <title>Default Behavior</title>
+
+ <variablelist>
+ <varlistentry id="guc-vacuum-truncate" xreflabel="vacuum_truncate">
+ <term><varname>vacuum_truncate</varname> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>vacuum_truncate</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ Enables or disables vacuum to try to truncate off any empty pages at
+ the end of the table. The default value is <literal>true</literal>.
+ If <literal>true</literal>, <command>VACUUM</command> and autovacuum
+ do the truncation and the disk space for the truncated pages is
+ returned to the operating system. Note that the truncation requires
+ an <literal>ACCESS EXCLUSIVE</literal> lock on the table. The
+ <literal>TRUNCATE</literal> parameter of
+ <link linkend="sql-vacuum"><command>VACUUM</command></link>, if
+ specified, overrides the value of this parameter. The setting can
+ also be overridden for individual tables by changing table storage
+ parameters.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </sect2>
+
<sect2 id="runtime-config-vacuum-freezing">
<title>Freezing</title>
</term>
<listitem>
<para>
- Enables or disables vacuum to try to truncate off any empty pages
- at the end of this table. The default value is <literal>true</literal>.
- If <literal>true</literal>, <command>VACUUM</command> and
- autovacuum do the truncation and the disk space for
- the truncated pages is returned to the operating system.
- Note that the truncation requires <literal>ACCESS EXCLUSIVE</literal>
- lock on the table. The <literal>TRUNCATE</literal> parameter
- of <link linkend="sql-vacuum"><command>VACUUM</command></link>, if specified, overrides the value
- of this option.
+ Per-table value for <xref linkend="guc-vacuum-truncate"/> parameter. The
+ <literal>TRUNCATE</literal> parameter of
+ <link linkend="sql-vacuum"><command>VACUUM</command></link>, if
+ specified, overrides the value of this option.
</para>
</listitem>
</varlistentry>
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 is normally the desired behavior
- and is the default unless the <literal>vacuum_truncate</literal>
+ and is the default unless <xref linkend="guc-vacuum-truncate"/>
+ is set to false or the <literal>vacuum_truncate</literal>
option has been set to false for the table to be vacuumed.
Setting this option to false may be useful to avoid
<literal>ACCESS EXCLUSIVE</literal> lock on the table that
char *itempos = ((char *) rdopts) + elems[j].offset;
char *string_val;
+ /*
+ * If isset_offset is provided, store whether the reloption is
+ * set there.
+ */
+ if (elems[j].isset_offset > 0)
+ {
+ char *setpos = ((char *) rdopts) + elems[j].isset_offset;
+
+ *(bool *) setpos = options[i].isset;
+ }
+
switch (options[i].gen->type)
{
case RELOPT_TYPE_BOOL:
{"vacuum_index_cleanup", RELOPT_TYPE_ENUM,
offsetof(StdRdOptions, vacuum_index_cleanup)},
{"vacuum_truncate", RELOPT_TYPE_BOOL,
- offsetof(StdRdOptions, vacuum_truncate)},
+ offsetof(StdRdOptions, vacuum_truncate), offsetof(StdRdOptions, vacuum_truncate_set)},
{"vacuum_max_eager_freeze_failure_rate", RELOPT_TYPE_REAL,
offsetof(StdRdOptions, vacuum_max_eager_freeze_failure_rate)}
};
elems[i].optname = opt->option->name;
elems[i].opttype = opt->option->type;
elems[i].offset = opt->offset;
+ elems[i].isset_offset = 0; /* not supported for local relopts yet */
i++;
}
int vacuum_multixact_failsafe_age;
double vacuum_max_eager_freeze_failure_rate;
bool track_cost_delay_timing;
+bool vacuum_truncate;
/*
* Variables for cost-based vacuum delay. The defaults differ between
((StdRdOptions *) rel->rd_options)->vacuum_max_eager_freeze_failure_rate;
/*
- * Set truncate option based on truncate reloption if it wasn't specified
- * in VACUUM command, or when running in an autovacuum worker
+ * Set truncate option based on truncate reloption or GUC if it wasn't
+ * specified in VACUUM command, or when running in an autovacuum worker
*/
if (params->truncate == VACOPTVALUE_UNSPECIFIED)
{
- if (rel->rd_options == NULL ||
- ((StdRdOptions *) rel->rd_options)->vacuum_truncate)
+ StdRdOptions *opts = (StdRdOptions *) rel->rd_options;
+
+ if (opts && opts->vacuum_truncate_set)
+ {
+ if (opts->vacuum_truncate)
+ params->truncate = VACOPTVALUE_ENABLED;
+ else
+ params->truncate = VACOPTVALUE_DISABLED;
+ }
+ else if (vacuum_truncate)
params->truncate = VACOPTVALUE_ENABLED;
else
params->truncate = VACOPTVALUE_DISABLED;
[STATS_CUMULATIVE] = gettext_noop("Statistics / Cumulative Query and Index Statistics"),
[VACUUM_AUTOVACUUM] = gettext_noop("Vacuuming / Automatic Vacuuming"),
[VACUUM_COST_DELAY] = gettext_noop("Vacuuming / Cost-Based Vacuum Delay"),
+ [VACUUM_DEFAULT] = gettext_noop("Vacuuming / Default Behavior"),
[VACUUM_FREEZING] = gettext_noop("Vacuuming / Freezing"),
[CLIENT_CONN_STATEMENT] = gettext_noop("Client Connection Defaults / Statement Behavior"),
[CLIENT_CONN_LOCALE] = gettext_noop("Client Connection Defaults / Locale and Formatting"),
NULL, NULL, NULL
},
+ {
+ {"vacuum_truncate", PGC_USERSET, VACUUM_DEFAULT,
+ gettext_noop("Enables vacuum to truncate empty pages at the end of the table."),
+ },
+ &vacuum_truncate,
+ true,
+ NULL, NULL, NULL
+ },
+
/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
#vacuum_cost_page_dirty = 20 # 0-10000 credits
#vacuum_cost_limit = 200 # 1-10000 credits
+# - Default Behavior -
+
+#vacuum_truncate = on # enable truncation after vacuum
+
# - Freezing -
#vacuum_freeze_table_age = 150000000
const char *optname; /* option's name */
relopt_type opttype; /* option's datatype */
int offset; /* offset of field in result struct */
+ int isset_offset; /* if > 0, offset of "is set" field */
} relopt_parse_elt;
/* Local reloption definition */
extern PGDLLIMPORT int vacuum_failsafe_age;
extern PGDLLIMPORT int vacuum_multixact_failsafe_age;
extern PGDLLIMPORT bool track_cost_delay_timing;
+extern PGDLLIMPORT bool vacuum_truncate;
/*
* Relevant for vacuums implementing eager scanning. Normal vacuums may
STATS_CUMULATIVE,
VACUUM_AUTOVACUUM,
VACUUM_COST_DELAY,
+ VACUUM_DEFAULT,
VACUUM_FREEZING,
CLIENT_CONN_STATEMENT,
CLIENT_CONN_LOCALE,
int parallel_workers; /* max number of parallel workers */
StdRdOptIndexCleanup vacuum_index_cleanup; /* controls index vacuuming */
bool vacuum_truncate; /* enables vacuum to truncate a relation */
+ bool vacuum_truncate_set; /* whether vacuum_truncate is set */
/*
* Fraction of pages in a relation that vacuum can eagerly scan and fail
t
(1 row)
+SET vacuum_truncate = false;
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
SELECT pg_relation_size('vac_truncate_test') = 0;
?column?
(1 row)
VACUUM (TRUNCATE FALSE, FULL TRUE) vac_truncate_test;
+ALTER TABLE vac_truncate_test RESET (vacuum_truncate);
+INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
+ERROR: null value in column "i" of relation "vac_truncate_test" violates not-null constraint
+DETAIL: Failing row contains (null, null).
+VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
+SELECT pg_relation_size('vac_truncate_test') > 0;
+ ?column?
+----------
+ t
+(1 row)
+
+RESET vacuum_truncate;
+VACUUM (TRUNCATE FALSE, DISABLE_PAGE_SKIPPING) vac_truncate_test;
+SELECT pg_relation_size('vac_truncate_test') > 0;
+ ?column?
+----------
+ t
+(1 row)
+
+VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
+SELECT pg_relation_size('vac_truncate_test') = 0;
+ ?column?
+----------
+ t
+(1 row)
+
DROP TABLE vac_truncate_test;
-- partitioned table
CREATE TABLE vacparted (a int, b char) PARTITION BY LIST (a);
INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
VACUUM (TRUNCATE FALSE, DISABLE_PAGE_SKIPPING) vac_truncate_test;
SELECT pg_relation_size('vac_truncate_test') > 0;
+SET vacuum_truncate = false;
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
SELECT pg_relation_size('vac_truncate_test') = 0;
VACUUM (TRUNCATE FALSE, FULL TRUE) vac_truncate_test;
+ALTER TABLE vac_truncate_test RESET (vacuum_truncate);
+INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
+VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
+SELECT pg_relation_size('vac_truncate_test') > 0;
+RESET vacuum_truncate;
+VACUUM (TRUNCATE FALSE, DISABLE_PAGE_SKIPPING) vac_truncate_test;
+SELECT pg_relation_size('vac_truncate_test') > 0;
+VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
+SELECT pg_relation_size('vac_truncate_test') = 0;
DROP TABLE vac_truncate_test;
-- partitioned table