pgsql: Allow autovacuum to use parallel vacuum workers.

Поиск
Список
Период
Сортировка
Искать

pgsql: Allow autovacuum to use parallel vacuum workers.

От:
Masahiko Sawada <msawada@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 
Reviewed-by: Sami Imseih 
Reviewed-by: Matheus Alcantara 
Reviewed-by: Bharath Rupireddy 
Reviewed-by: Alexander Korotkov 
Reviewed-by: zengman 
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(-)

Re: pgsql: Allow autovacuum to use parallel vacuum workers.

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Вложения:
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
+     if any which is
+    capped limited by
+     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

Re: pgsql: Allow autovacuum to use parallel vacuum workers.

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Tue, Apr 7, 2026 at 4:52 AM Aleksander Alekseev
 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
> +     if any which is
> +    capped limited by
> +     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

Re: pgsql: Allow autovacuum to use parallel vacuum workers.

От:
Aleksander Alekseev <aleksander@tigerdata.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


Re: pgsql: Allow autovacuum to use parallel vacuum workers.

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Fri, Apr 10, 2026 at 3:35 AM Aleksander Alekseev
 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


FAQ