Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 40d964e

Browse files
author
Amit Kapila
committed
Allow vacuum command to process indexes in parallel.
This feature allows the vacuum to leverage multiple CPUs in order to process indexes. This enables us to perform index vacuuming and index cleanup with background workers. This adds a PARALLEL option to VACUUM command where the user can specify the number of workers that can be used to perform the command which is limited by the number of indexes on a table. Specifying zero as a number of workers will disable parallelism. This option can't be used with the FULL option. Each index is processed by at most one vacuum process. Therefore parallel vacuum can be used when the table has at least two indexes. The parallel degree is either specified by the user or determined based on the number of indexes that the table has, and further limited by max_parallel_maintenance_workers. The index can participate in parallel vacuum iff it's size is greater than min_parallel_index_scan_size. Author: Masahiko Sawada and Amit Kapila Reviewed-by: Dilip Kumar, Amit Kapila, Robert Haas, Tomas Vondra, Mahendra Singh and Sergei Kornilov Tested-by: Mahendra Singh and Prabhat Sahu Discussion: https://postgr.es/m/CAD21AoDTPMgzSkV4E3SFo1CH_x50bf5PqZFQf4jmqjk-C03BWg@mail.gmail.com https://postgr.es/m/CAA4eK1J-VoR9gzS5E75pcD-OH0mEyCdp8RihcwKrcuw7J-Q0+w@mail.gmail.com
1 parent 44f1fc8 commit 40d964e

File tree

13 files changed

+1452
-136
lines changed

13 files changed

+1452
-136
lines changed

doc/src/sgml/config.sgml

+10-8
Original file line numberDiff line numberDiff line change
@@ -2308,13 +2308,13 @@ include_dir 'conf.d'
23082308
<listitem>
23092309
<para>
23102310
Sets the maximum number of parallel workers that can be
2311-
started by a single utility command. Currently, the only
2312-
parallel utility command that supports the use of parallel
2313-
workers is <command>CREATE INDEX</command>, and only when
2314-
building a B-tree index. Parallel workers are taken from the
2315-
pool of processes established by <xref
2316-
linkend="guc-max-worker-processes"/>, limited by <xref
2317-
linkend="guc-max-parallel-workers"/>. Note that the requested
2311+
started by a single utility command. Currently, the parallel
2312+
utility commands that support the use of parallel workers are
2313+
<command>CREATE INDEX</command> only when building a B-tree index,
2314+
and <command>VACUUM</command> without <literal>FULL</literal>
2315+
option. Parallel workers are taken from the pool of processes
2316+
established by <xref linkend="guc-max-worker-processes"/>, limited
2317+
by <xref linkend="guc-max-parallel-workers"/>. Note that the requested
23182318
number of workers may not actually be available at run time.
23192319
If this occurs, the utility operation will run with fewer
23202320
workers than expected. The default value is 2. Setting this
@@ -4915,7 +4915,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
49154915
for a parallel scan to be considered. Note that a parallel index scan
49164916
typically won't touch the entire index; it is the number of pages
49174917
which the planner believes will actually be touched by the scan which
4918-
is relevant.
4918+
is relevant. This parameter is also used to decide whether a
4919+
particular index can participate in a parallel vacuum. See
4920+
<xref linkend="sql-vacuum"/>.
49194921
If this value is specified without units, it is taken as blocks,
49204922
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
49214923
The default is 512 kilobytes (<literal>512kB</literal>).

doc/src/sgml/ref/vacuum.sgml

+55-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
3434
SKIP_LOCKED [ <replaceable class="parameter">boolean</replaceable> ]
3535
INDEX_CLEANUP [ <replaceable class="parameter">boolean</replaceable> ]
3636
TRUNCATE [ <replaceable class="parameter">boolean</replaceable> ]
37+
PARALLEL <replaceable class="parameter">integer</replaceable>
3738

3839
<phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase>
3940

@@ -75,10 +76,14 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
7576
with normal reading and writing of the table, as an exclusive lock
7677
is not obtained. However, extra space is not returned to the operating
7778
system (in most cases); it's just kept available for re-use within the
78-
same table. <command>VACUUM FULL</command> rewrites the entire contents
79-
of the table into a new disk file with no extra space, allowing unused
80-
space to be returned to the operating system. This form is much slower and
81-
requires an exclusive lock on each table while it is being processed.
79+
same table. It also allows us to leverage multiple CPUs in order to process
80+
indexes. This feature is known as <firstterm>parallel vacuum</firstterm>.
81+
To disable this feature, one can use <literal>PARALLEL</literal> option and
82+
specify parallel workers as zero. <command>VACUUM FULL</command> rewrites
83+
the entire contents of the table into a new disk file with no extra space,
84+
allowing unused space to be returned to the operating system. This form is
85+
much slower and requires an exclusive lock on each table while it is being
86+
processed.
8287
</para>
8388

8489
<para>
@@ -223,6 +228,33 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
223228
</listitem>
224229
</varlistentry>
225230

231+
<varlistentry>
232+
<term><literal>PARALLEL</literal></term>
233+
<listitem>
234+
<para>
235+
Perform vacuum index and cleanup index phases of <command>VACUUM</command>
236+
in parallel using <replaceable class="parameter">integer</replaceable>
237+
background workers (for the detail of each vacuum phases, please
238+
refer to <xref linkend="vacuum-phases"/>). If the
239+
<literal>PARALLEL</literal> option is omitted, then
240+
<command>VACUUM</command> decides the number of workers based on number
241+
of indexes that support parallel vacuum operation on the relation which
242+
is further limited by <xref linkend="guc-max-parallel-workers-maintenance"/>.
243+
The index can participate in a parallel vacuum if and only if the size
244+
of the index is more than <xref linkend="guc-min-parallel-index-scan-size"/>.
245+
Please note that it is not guaranteed that the number of parallel workers
246+
specified in <replaceable class="parameter">integer</replaceable> will
247+
be used during execution. It is possible for a vacuum to run with fewer
248+
workers than specified, or even with no workers at all. Only one worker
249+
can be used per index. So parallel workers are launched only when there
250+
are at least <literal>2</literal> indexes in the table. Workers for
251+
vacuum launches before starting each phase and exit at the end of
252+
the phase. These behaviors might change in a future release. This
253+
option can't be used with the <literal>FULL</literal> option.
254+
</para>
255+
</listitem>
256+
</varlistentry>
257+
226258
<varlistentry>
227259
<term><replaceable class="parameter">boolean</replaceable></term>
228260
<listitem>
@@ -237,6 +269,15 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
237269
</listitem>
238270
</varlistentry>
239271

272+
<varlistentry>
273+
<term><replaceable class="parameter">integer</replaceable></term>
274+
<listitem>
275+
<para>
276+
Specifies a non-negative integer value passed to the selected option.
277+
</para>
278+
</listitem>
279+
</varlistentry>
280+
240281
<varlistentry>
241282
<term><replaceable class="parameter">table_name</replaceable></term>
242283
<listitem>
@@ -316,11 +357,19 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
316357
more than a plain <command>VACUUM</command> would.
317358
</para>
318359

360+
<para>
361+
The <option>PARALLEL</option> option is used only for vacuum purpose.
362+
Even if this option is specified with <option>ANALYZE</option> option
363+
it does not affect <option>ANALYZE</option>.
364+
</para>
365+
319366
<para>
320367
<command>VACUUM</command> causes a substantial increase in I/O traffic,
321368
which might cause poor performance for other active sessions. Therefore,
322-
it is sometimes advisable to use the cost-based vacuum delay feature.
323-
See <xref linkend="runtime-config-resource-vacuum-cost"/> for details.
369+
it is sometimes advisable to use the cost-based vacuum delay feature. For
370+
parallel vacuum, each worker sleeps proportional to the work done by that
371+
worker. See <xref linkend="runtime-config-resource-vacuum-cost"/> for
372+
details.
324373
</para>
325374

326375
<para>

0 commit comments

Comments
 (0)