]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
vacuumdb: Fix --analyze-in-stages skipping partitioned tables
authorFujii Masao <fujii@postgresql.org>
Wed, 3 Jun 2026 07:53:16 +0000 (16:53 +0900)
committerFujii Masao <fujii@postgresql.org>
Wed, 3 Jun 2026 07:53:16 +0000 (16:53 +0900)
Commit 6429e5b77 changed vacuumdb to process partitioned tables when
--analyze-only or --analyze-in-stages is specified, matching the
documented behavior of analyzing regular tables, partitioned tables,
and materialized views.

Later, commit c4067383cb2 accidentally changed this behavior so that
partitioned tables were processed for --analyze-only, but skipped for
--analyze-in-stages.

As a result, vacuumdb --analyze-in-stages no longer matched its
documentation. Partitioned tables were skipped, leaving parent-table
statistics outdated even though users running vacuumdb
--analyze-in-stages after pg_upgrade, restore, or bulk loading would
expect statistics to be rebuilt for the database.

Fix this issue by making --analyze-in-stages process partitioned
tables again.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/EDFF0AFB-050F-4FBF-8D4F-B44DC454D957@gmail.com

src/bin/scripts/t/100_vacuumdb.pl
src/bin/scripts/vacuuming.c

index 84fcacd57fad0038a84ce9f62b328fe3636e4b05..5fd55628507200513a9c0193feb6687f65a6cce7 100644 (file)
@@ -363,6 +363,10 @@ $node->issues_sql_like(
        [ 'vacuumdb', '--analyze-only', 'postgres' ],
        qr/statement: ANALYZE public.parent_table/s,
        '--analyze-only updates statistics for partitioned tables');
+$node->issues_sql_like(
+       [ 'vacuumdb', '--analyze-in-stages', 'postgres' ],
+       qr/statement: ANALYZE public.parent_table/s,
+       '--analyze-in-stages updates statistics for partitioned tables');
 $node->issues_sql_unlike(
        [ 'vacuumdb', '--analyze-only', 'postgres' ],
        qr/statement:\ VACUUM/sx,
index faac9089a01283bb6aba777c508e2db2266aeb9a..37608806056efe37aa167d857c6aab85d47a6335 100644 (file)
@@ -650,13 +650,15 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
        {
                /*
                 * vacuumdb should generally follow the behavior of the underlying
-                * VACUUM and ANALYZE commands.  In MODE_ANALYZE mode, process regular
-                * tables, materialized views, and partitioned tables, just like
-                * ANALYZE (with no specific target tables) does. Otherwise, process
-                * only regular tables and materialized views, since VACUUM skips
-                * partitioned tables when no target tables are specified.
+                * VACUUM and ANALYZE commands.  In MODE_ANALYZE or
+                * MODE_ANALYZE_IN_STAGES modes, process regular tables, materialized
+                * views, and partitioned tables, just like ANALYZE (with no specific
+                * target tables) does. Otherwise, process only regular tables and
+                * materialized views, since VACUUM skips partitioned tables when no
+                * target tables are specified.
                 */
-               if (vacopts->mode == MODE_ANALYZE)
+               if (vacopts->mode == MODE_ANALYZE ||
+                       vacopts->mode == MODE_ANALYZE_IN_STAGES)
                        appendPQExpBufferStr(&catalog_query,
                                                                 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
                                                                 CppAsString2(RELKIND_RELATION) ", "