1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add VACUUM/ANALYZE BUFFER_USAGE_LIMIT option

Add new options to the VACUUM and ANALYZE commands called
BUFFER_USAGE_LIMIT to allow users more control over how large to make the
buffer access strategy that is used to limit the usage of buffers in
shared buffers.  Larger rings can allow VACUUM to run more quickly but
have the drawback of VACUUM possibly evicting more buffers from shared
buffers that might be useful for other queries running on the database.

Here we also add a new GUC named vacuum_buffer_usage_limit which controls
how large to make the access strategy when it's not specified in the
VACUUM/ANALYZE command.  This defaults to 256KB, which is the same size as
the access strategy was prior to this change.  This setting also
controls how large to make the buffer access strategy for autovacuum.

Per idea by Andres Freund.

Author: Melanie Plageman
Reviewed-by: David Rowley
Reviewed-by: Andres Freund
Reviewed-by: Justin Pryzby
Reviewed-by: Bharath Rupireddy
Discussion: https://postgr.es/m/20230111182720.ejifsclfwymw2reb@awork3.anarazel.de
This commit is contained in:
David Rowley
2023-04-07 11:40:31 +12:00
parent 5279e9db8e
commit 1cbbee0338
17 changed files with 322 additions and 25 deletions

View File

@ -2001,6 +2001,36 @@ include_dir 'conf.d'
</listitem>
</varlistentry>
<varlistentry id="guc-vacuum-buffer-usage-limit" xreflabel="vacuum_buffer_usage_limit">
<term>
<varname>vacuum_buffer_usage_limit</varname> (<type>integer</type>)
<indexterm>
<primary><varname>vacuum_buffer_usage_limit</varname> configuration parameter</primary>
</indexterm>
</term>
<listitem>
<para>
Specifies the size of the
<glossterm linkend="glossary-buffer-access-strategy">Buffer Access Strategy</glossterm>
used by the <command>VACUUM</command> and <command>ANALYZE</command>
commands. A setting of <literal>0</literal> will allow the operation
to use any number of <varname>shared_buffers</varname>. Otherwise
valid sizes range from <literal>128 KB</literal> to
<literal>16 GB</literal>. If the specified size would exceed 1/8 the
size of <varname>shared_buffers</varname>, the size is silently capped
to that value. The default value is <literal>256 KB</literal>. If
this value is specified without units, it is taken as kilobytes. This
parameter can be set at any time. It can be overridden for
<xref linkend="sql-vacuum"/> and <xref linkend="sql-analyze"/>
when passing the <option>BUFFER_USAGE_LIMIT</option> option. Higher
settings can allow <command>VACUUM</command> and
<command>ANALYZE</command> to run more quickly, but having too large a
setting may cause too many other useful pages to be evicted from
shared buffers.
</para>
</listitem>
</varlistentry>
<varlistentry id="guc-logical-decoding-work-mem" xreflabel="logical_decoding_work_mem">
<term><varname>logical_decoding_work_mem</varname> (<type>integer</type>)
<indexterm>

View File

@ -28,6 +28,7 @@ ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replacea
VERBOSE [ <replaceable class="parameter">boolean</replaceable> ]
SKIP_LOCKED [ <replaceable class="parameter">boolean</replaceable> ]
BUFFER_USAGE_LIMIT [ <replaceable class="parameter">string</replaceable> ]
<phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase>
@ -95,6 +96,25 @@ ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replacea
</listitem>
</varlistentry>
<varlistentry>
<term><literal>BUFFER_USAGE_LIMIT</literal></term>
<listitem>
<para>
Specifies the
<glossterm linkend="glossary-buffer-access-strategy">Buffer Access Strategy</glossterm>
ring buffer size for <command>ANALYZE</command>. This size is used to
calculate the number of shared buffers which will be reused as part of
this strategy. <literal>0</literal> disables use of a
<literal>Buffer Access Strategy</literal>. When this option is not
specified, <command>ANALYZE</command> uses the value from
<xref linkend="guc-vacuum-buffer-usage-limit"/>. Higher settings can
allow <command>ANALYZE</command> to run more quickly, but having too
large a setting may cause too many other useful pages to be evicted from
shared buffers.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">boolean</replaceable></term>
<listitem>

View File

@ -39,6 +39,7 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
PARALLEL <replaceable class="parameter">integer</replaceable>
SKIP_DATABASE_STATS [ <replaceable class="parameter">boolean</replaceable> ]
ONLY_DATABASE_STATS [ <replaceable class="parameter">boolean</replaceable> ]
BUFFER_USAGE_LIMIT [ <replaceable class="parameter">string</replaceable> ]
<phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase>
@ -345,6 +346,29 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
</listitem>
</varlistentry>
<varlistentry>
<term><literal>BUFFER_USAGE_LIMIT</literal></term>
<listitem>
<para>
Specifies the
<glossterm linkend="glossary-buffer-access-strategy">Buffer Access Strategy</glossterm>
ring buffer size for <command>VACUUM</command>. This size is used to
calculate the number of shared buffers which will be reused as part of
this strategy. <literal>0</literal> disables use of a
<literal>Buffer Access Strategy</literal>. If <option>ANALYZE</option>
is also specified, the <option>BUFFER_USAGE_LIMIT</option> value is used
for both the vacuum and analyze stages. This option can't be used with
the <option>FULL</option> option except if <option>ANALYZE</option> is
also specified. When this option is not specified,
<command>VACUUM</command> uses the value from
<xref linkend="guc-vacuum-buffer-usage-limit"/>. Higher settings can
allow <command>VACUUM</command> to run more quickly, but having too
large a setting may cause too many other useful pages to be evicted from
shared buffers.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">boolean</replaceable></term>
<listitem>