agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Allow autovacuum to use parallel vacuum workers.
5+ messages / 3 participants
[nested] [flat]

* pgsql: Allow autovacuum to use parallel vacuum workers.
@ 2026-04-06 18:49  Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Masahiko Sawada @ 2026-04-06 18:49 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Allow autovacuum to use parallel vacuum workers.

Previously, autovacuum always disabled parallel vacuum regardless of
the table's index count or configuration. This commit enables
autovacuum workers to use parallel index vacuuming and index cleanup,
using the same parallel vacuum infrastructure as manual VACUUM.

Two new configuration options control the feature. The GUC
autovacuum_max_parallel_workers sets the maximum number of parallel
workers a single autovacuum worker may launch; it defaults to 0,
preserving existing behavior unless explicitly enabled. The per-table
storage parameter autovacuum_parallel_workers provides per-table
limits. A value of 0 disables parallel vacuum for the table, a
positive value caps the worker count (still bounded by the GUC), and
-1 (the default) defers to the GUC.

To handle cases where autovacuum workers receive a SIGHUP and update
their cost-based vacuum delay parameters mid-operation, a new
propagation mechanism is added to vacuumparallel.c. The leader stores
its effective cost parameters in a DSM segment. Parallel vacuum
workers poll for changes in vacuum_delay_point(); if an update is
detected, they apply the new values locally via VacuumUpdateCosts().

A new test module, src/test/modules/test_autovacuum, is added to
verify that parallel autovacuum workers are correctly launched and
that cost-parameter updates are propagated as expected.

The patch was originally proposed by Maxim Orlov, but the
implementation has undergone significant architectural changes
since then during the review process.

Author: Daniil Davydov <3danissimo@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: zengman <zengman@halodbtech.com>
Discussion: https://postgr.es/m/CACG=ezZOrNsuLoETLD1gAswZMuH2nGGq7Ogcc0QOE5hhWaw=cw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1ff3180ca0169556984ab83759477f593129794d

Modified Files
--------------
doc/src/sgml/config.sgml                           |  24 +++
doc/src/sgml/maintenance.sgml                      |  34 +++
doc/src/sgml/ref/create_table.sgml                 |  16 ++
doc/src/sgml/ref/vacuum.sgml                       |  23 +--
src/backend/access/common/reloptions.c             |  11 +
src/backend/access/heap/vacuumlazy.c               |  12 ++
src/backend/commands/vacuum.c                      |  22 +-
src/backend/commands/vacuumparallel.c              | 227 ++++++++++++++++++++-
src/backend/postmaster/autovacuum.c                |  25 ++-
src/backend/utils/init/globals.c                   |   1 +
src/backend/utils/misc/guc.c                       |  10 +-
src/backend/utils/misc/guc_parameters.dat          |   8 +
src/backend/utils/misc/postgresql.conf.sample      |   1 +
src/bin/psql/tab-complete.in.c                     |   1 +
src/include/commands/vacuum.h                      |   2 +
src/include/miscadmin.h                            |   1 +
src/include/utils/rel.h                            |   2 +
src/test/modules/Makefile                          |   1 +
src/test/modules/meson.build                       |   1 +
src/test/modules/test_autovacuum/.gitignore        |   2 +
src/test/modules/test_autovacuum/Makefile          |  20 ++
src/test/modules/test_autovacuum/meson.build       |  15 ++
.../test_autovacuum/t/001_parallel_autovacuum.pl   | 189 +++++++++++++++++
src/tools/pgindent/typedefs.list                   |   1 +
24 files changed, 616 insertions(+), 33 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Allow autovacuum to use parallel vacuum workers.
@ 2026-04-07 11:52  Aleksander Alekseev <aleksander@tigerdata.com>
  parent: Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Aleksander Alekseev @ 2026-04-07 11:52 UTC (permalink / raw)
  To: Masahiko Sawada <msawada@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org

Hi,

> Allow autovacuum to use parallel vacuum workers.
>
> [...]

I think there is a mistake in the documentation:

```
+    For autovacuum, it is limited by the table's
+    <xref linkend="reloption-autovacuum-parallel-workers"/> if any which is
+    capped limited by
+    <xref linkend="guc-autovacuum-max-parallel-workers"/> parameter.  Please
```

Firstly "capped limited by" almost certainly should be either "capped
by" or "limited by". Secondly "limited by the tables's [...] if any"
doesn't sound right. Probably what was meant is "if set".

I suggest fixing it as attached.

--
Best regards,
Aleksander Alekseev

Attachments:

  [text/x-patch] v1-0001-Improve-wording-in-the-documentation-added-by-1ff.patch (1.8K, ../../CAJ7c6TPcSqzhbhrsiCMmVwmE8F7pwS7i9J49SP1zPKS_ER+vcA@mail.gmail.com/2-v1-0001-Improve-wording-in-the-documentation-added-by-1ff.patch)
  download | inline diff:
From 753efc10085c9d681a70718b0e2c622fad139efd Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@tigerdata.com>
Date: Tue, 7 Apr 2026 14:48:15 +0300
Subject: [PATCH v1] Improve wording in the documentation added by 1ff3180ca016

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Discussion: https://postgr.es/m/CACG=ezZOrNsuLoETLD1gAswZMuH2nGGq7Ogcc0QOE5hhWaw=cw@mail.gmail.com
---
 doc/src/sgml/maintenance.sgml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml
index 652b291de15..35dd7bc9c18 100644
--- a/doc/src/sgml/maintenance.sgml
+++ b/doc/src/sgml/maintenance.sgml
@@ -1188,11 +1188,11 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
     relation that support parallel vacuum.  For manual <command>VACUUM</command>,
     this is limited by the <literal>PARALLEL</literal> option, which is
     further capped by <xref linkend="guc-max-parallel-maintenance-workers"/>.
-    For autovacuum, it is limited by the table's
-    <xref linkend="reloption-autovacuum-parallel-workers"/> if any which is
-    capped limited by
-    <xref linkend="guc-autovacuum-max-parallel-workers"/> parameter.  Please
-    note that it is not guaranteed that the number of parallel workers that was
+    For autovacuum, it is limited by
+    <xref linkend="guc-autovacuum-max-parallel-workers"/>, which can be
+    further reduced on a per-table basis using the
+    <xref linkend="reloption-autovacuum-parallel-workers"/> storage parameter.
+    Please note that it is not guaranteed that the number of parallel workers that was
     calculated will be used during execution.  It is possible for a vacuum to
     run with fewer workers than specified, or even with no workers at all.
    </para>
-- 
2.43.0



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Allow autovacuum to use parallel vacuum workers.
@ 2026-04-09 19:12  Masahiko Sawada <sawada.mshk@gmail.com>
  parent: Aleksander Alekseev <aleksander@tigerdata.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Masahiko Sawada @ 2026-04-09 19:12 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: Masahiko Sawada <msawada@postgresql.org>; pgsql-committers@lists.postgresql.org

On Tue, Apr 7, 2026 at 4:52 AM Aleksander Alekseev
<aleksander@tigerdata.com> wrote:
>
> Hi,
>
> > Allow autovacuum to use parallel vacuum workers.
> >
> > [...]
>
> I think there is a mistake in the documentation:
>
> ```
> +    For autovacuum, it is limited by the table's
> +    <xref linkend="reloption-autovacuum-parallel-workers"/> if any which is
> +    capped limited by
> +    <xref linkend="guc-autovacuum-max-parallel-workers"/> parameter.  Please
> ```
>
> Firstly "capped limited by" almost certainly should be either "capped
> by" or "limited by". Secondly "limited by the tables's [...] if any"
> doesn't sound right. Probably what was meant is "if set".
>
> I suggest fixing it as attached.

Thank you for the report. Indeed, we need to fix the wording.

I've attached the patch based on your proposal that uses the
explanation consistent with the manual VACUUM and autovacuums. What do
you think?

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Attachments:

  [application/octet-stream] v2-0001-doc-Improve-consistency-of-parallel-vacuum-descri.patch (2.5K, ../../CAD21AoAKP=NYGzMXotD_tZZxutGwRc=38fMQ7+5NJ1XXDquV2w@mail.gmail.com/2-v2-0001-doc-Improve-consistency-of-parallel-vacuum-descri.patch)
  download | inline diff:
From 2ffdfc962dcfa96ac18a99020615e5cc9c23bde6 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@tigerdata.com>
Date: Tue, 7 Apr 2026 14:48:15 +0300
Subject: [PATCH v2] doc: Improve consistency of parallel vacuum description.

Use consistent phrasing for parallel vacuum descriptions between
manual VACUUM and autovacuum. Specifically, clarify that the parallel
worker count is limited by the respective options only if they are
explicitly specified.

Also, fix a typo in the parallel vacuum section.

Reported-by: Aleksander Alekseev <aleksander@tigerdata.com>
Author: Aleksander Alekseev <aleksander@tigerdata.com>
Discussion: https://postgr.es/m/CAJ7c6TPcSqzhbhrsiCMmVwmE8F7pwS7i9J49SP1zPKS_ER+vcA@mail.gmail.com
---
 doc/src/sgml/maintenance.sgml | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml
index 652b291de15..76262df0502 100644
--- a/doc/src/sgml/maintenance.sgml
+++ b/doc/src/sgml/maintenance.sgml
@@ -1186,15 +1186,15 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
     vacuum phase, please refer to <xref linkend="vacuum-phases"/>).  The
     degree of parallelism is determined by the number of indexes on the
     relation that support parallel vacuum.  For manual <command>VACUUM</command>,
-    this is limited by the <literal>PARALLEL</literal> option, which is
-    further capped by <xref linkend="guc-max-parallel-maintenance-workers"/>.
+    this is limited by the <literal>PARALLEL</literal> option if specified,
+    which is further capped by <xref linkend="guc-max-parallel-maintenance-workers"/>.
     For autovacuum, it is limited by the table's
-    <xref linkend="reloption-autovacuum-parallel-workers"/> if any which is
-    capped limited by
-    <xref linkend="guc-autovacuum-max-parallel-workers"/> parameter.  Please
-    note that it is not guaranteed that the number of parallel workers that was
-    calculated will be used during execution.  It is possible for a vacuum to
-    run with fewer workers than specified, or even with no workers at all.
+    <xref linkend="reloption-autovacuum-parallel-workers"/> if specified,
+    which is further capped by <xref linkend="guc-autovacuum-max-parallel-workers"/>
+    parameter. Please note that it is not guaranteed that the number of parallel
+    workers that was calculated will be used during execution.  It is possible for
+    a vacuum to run with fewer workers than specified, or even with no workers at
+    all.
    </para>
 
    <para>
-- 
2.47.3



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Allow autovacuum to use parallel vacuum workers.
@ 2026-04-10 10:35  Aleksander Alekseev <aleksander@tigerdata.com>
  parent: Masahiko Sawada <sawada.mshk@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Aleksander Alekseev @ 2026-04-10 10:35 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org; +Cc: Masahiko Sawada <sawada.mshk@gmail.com>

Hi,

> Thank you for the report. Indeed, we need to fix the wording.
>
> I've attached the patch based on your proposal that uses the
> explanation consistent with the manual VACUUM and autovacuums. What do
> you think?

Looks good.

-- 
Best regards,
Aleksander Alekseev





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Allow autovacuum to use parallel vacuum workers.
@ 2026-04-10 19:50  Masahiko Sawada <sawada.mshk@gmail.com>
  parent: Aleksander Alekseev <aleksander@tigerdata.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Masahiko Sawada @ 2026-04-10 19:50 UTC (permalink / raw)
  To: Aleksander Alekseev <aleksander@tigerdata.com>; +Cc: pgsql-committers@lists.postgresql.org

On Fri, Apr 10, 2026 at 3:35 AM Aleksander Alekseev
<aleksander@tigerdata.com> wrote:
>
> Hi,
>
> > Thank you for the report. Indeed, we need to fix the wording.
> >
> > I've attached the patch based on your proposal that uses the
> > explanation consistent with the manual VACUUM and autovacuums. What do
> > you think?
>
> Looks good.

Pushed.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-04-10 19:50 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-06 18:49 pgsql: Allow autovacuum to use parallel vacuum workers. Masahiko Sawada <msawada@postgresql.org>
2026-04-07 11:52 ` Aleksander Alekseev <aleksander@tigerdata.com>
2026-04-09 19:12   ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-04-10 10:35     ` Aleksander Alekseev <aleksander@tigerdata.com>
2026-04-10 19:50       ` Masahiko Sawada <sawada.mshk@gmail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox