pgsql: vacuumdb: Use ANALYZE ONLY for partitioned tables

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: vacuumdb: Use ANALYZE ONLY for partitioned tables
Date: 2026-08-13 05:25:30
Message-ID: E1wuNwX-00000000Mdg-1cOz@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

vacuumdb: Use ANALYZE ONLY for partitioned tables

When vacuumdb --analyze-only or --analyze-in-stages enumerates
tables itself, it can select both a partitioned table and its
partitions as separate work items. Previously, it generated plain
ANALYZE for the partitioned table, which recursively analyzed its
partitions as well.

This caused duplicate work when the partitions were already selected by
vacuumdb. With --analyze-in-stages, the redundant work could be
repeated at every stage.

Fix this by generating ANALYZE ONLY for automatically selected
partitioned tables when connected to servers that support it. This
updates inherited statistics for the partitioned table while leaving
per-partition statistics to the separately selected partition entries.
For older servers that do not support ANALYZE ONLY, vacuumdb falls back
to the previous plain ANALYZE command.

This also applies when partitioned tables are selected by schema
filters. In that case, partitions matching the filters are analyzed as
separate targets, while per-partition statistics for partitions outside
the filters are not updated via the partitioned parent.

This commit does not change the behavior for partitioned tables
specified explicitly with --table, i.e., in that case, vacuumdb
continues to generate plain ANALYZE, recursively analyzing the specified
partitioned table and its partitions.

Suggested-by: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Author: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: Daniel Gustafsson <daniel(at)yesql(dot)se>
Discussion: https://postgr.es/m/aKZ7lMYGnnIo35c0@pryzbyj2023
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/72e6184cd5fe82620693a2aae9e34452d1984459

Modified Files
--------------
src/bin/scripts/t/100_vacuumdb.pl | 8 ++-
src/bin/scripts/vacuuming.c | 120 +++++++++++++++++++++++++-------------
src/tools/pgindent/typedefs.list | 2 +
3 files changed, 88 insertions(+), 42 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-08-13 05:25:47 pgsql: vacuumdb: Use ANALYZE ONLY for partitioned tables
Previous Message Amit Kapila 2026-08-13 04:43:31 pgsql: Doc: Clarify ALTER PUBLICATION's REFRESH PUBLICATION wording.