1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Add vacuum_truncate configuration parameter.

This new parameter works just like the storage parameter of the
same name: if set to true (which is the default), autovacuum and
VACUUM attempt to truncate any empty pages at the end of the table.
It is primarily intended to help users avoid locking issues on hot
standbys.  The setting can be overridden with the storage parameter
or VACUUM's TRUNCATE option.

Since there's presently no way to determine whether a Boolean
storage parameter is explicitly set or has just picked up the
default value, this commit also introduces an isset_offset member
to relopt_parse_elt.

Suggested-by: Will Storey <will@summercat.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Co-authored-by: Gurjeet Singh <gurjeet@singh.im>
Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at>
Reviewed-by: Fujii Masao <masao.fujii@oss.nttdata.com>
Reviewed-by: Robert Treat <rob@xzilla.net>
Discussion: https://postgr.es/m/Z2DE4lDX4tHqNGZt%40dev.null
This commit is contained in:
Nathan Bossart
2025-03-20 10:16:50 -05:00
parent 618c64ffd3
commit 0164a0f9ee
13 changed files with 116 additions and 15 deletions

View File

@ -9311,6 +9311,35 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
</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>

View File

@ -1692,15 +1692,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
</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>

View File

@ -265,7 +265,8 @@ VACUUM [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] [ <re
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