Subject: analyze-in-stages post upgrade questions

From: "Zechman, Derek S" <[email-masked]>
Date: Fri, 27 Jun 2025 13:35:27 +0000

We recently performed an upgrade from pg14 (14.18) to pg16 (16.9) and performed the analyze-in-stages post upgrade.  It has been noticed that some plans changed to use hash joins instead of nested loops.  Further investigation found it was because the parent table of partitioned tables did not have stats.  After running an ANALYZE on the parent tables we got similar plan an execution times as before.

I have two questions
1 - Why does analyze-in-stages not analyze the parent tables?
2 - What happens if we do not run analyze-in-stages post upgrade and just run an analyze?

Thanks,
Sean

---

From: Ron Johnson <[email-masked]>
Date: Fri, 27 Jun 2025 09:41:39 -0400

On Fri, Jun 27, 2025 at 9:35 AM Zechman, Derek S <[email-masked]>
wrote:

>
>
> We recently performed an upgrade from pg14 (14.18) to pg16 (16.9) and
> performed the analyze-in-stages post upgrade.  It has been noticed that
> some plans changed to use hash joins instead of nested loops.  Further
> investigation found it was because the parent table of partitioned tables
> did not have stats.  After running an ANALYZE on the parent tables we got
> similar plan an execution times as before.
>
>
>
> I have two questions
>
> 2 – What happens if we do not run analyze-in-stages post upgrade and just
> run an analyze?
>

It takes more time, and you don't have *any* statistics on a given table
until the ANALYZE on that table completes.

How long did "vacuumdb --analyze-only --jobs=$mumble your_db" take?

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

---

From: Adrian Klaver <[email-masked]>
Date: Fri, 27 Jun 2025 08:31:08 -0700

On 6/27/25 06:35, Zechman, Derek S wrote:
> investigation found it was because the parent table of partitioned 
> tables did not have stats.  After running an ANALYZE on the parent 
> tables we got similar plan an execution times as before.
> 
> I have two questions
> 
> 2 – What happens if we do not run analyze-in-stages post upgrade and 
> just run an analyze?

It is spelled out in the docs:

https://www.postgresql.org/docs/current/pgupgrade.html

Emphasis added

"Using vacuumdb --all --analyze-only can efficiently generate such 
statistics, and the use of --jobs can speed it up. Option 
--analyze-in-stages can be used to generate **minimal statistics** 
quickly. If vacuum_cost_delay is set to a non-zero value, this can be 
overridden to speed up statistics generation using PGOPTIONS, e.g., 
PGOPTIONS='-c vacuum_cost_delay=0' vacuumdb ...."

and from here:

https://www.postgresql.org/docs/current/app-vacuumdb.html

"--analyze-in-stages

     Only calculate statistics for use by the optimizer (no vacuum), 
like --analyze-only. Run three stages of analyze; the first stage uses 
the lowest possible statistics target (see default_statistics_target) to 
produce usable statistics faster, and subsequent stages build the full 
statistics.

     This option is only useful to analyze a database that currently has 
no statistics or has wholly incorrect ones, such as if it is newly 
populated from a restored dump or by pg_upgrade. Be aware that running 
with this option in a database with existing statistics may cause the 
query optimizer choices to become transiently worse due to the low 
statistics targets of the early stages.
"

-- 
Adrian Klaver
[email-masked]

---

From: Laurenz Albe <[email-masked]>
Date: Fri, 27 Jun 2025 23:39:17 +0200

> statistics targets of the early stages.

Well, that wouldn't explain why it doesn't work on partitioned tables.
I am under the impression that it should.

Derek, can cou share the pg_stats entries for the partitioned table?

Yours,
Laurenz Albe

---

From: "Zechman, Derek S" <[email-masked]>
Date: Sat, 28 Jun 2025 01:11:19 +0000

I have two questions
1 - Why does analyze-in-stages not analyze the parent tables?
2 – What happens if we do not run analyze-in-stages post upgrade and just run an analyze?

“It takes more time, and you don't have any statistics on a given table until the ANALYZE on that table completes.

How long did "vacuumdb --analyze-only --jobs=$mumble your_db" take?”

Thanks – that makes sense.  I understand what analyze in stages does just wish it would include parent tables.

"vacuumdb --all --analyze-only --jobs=7" took about 75 minutes where the analyze-in-stages after upgrade took 115 minutes.  Neither of these activities analyzed the parent tables.
Reading more and it seems vacuumdb doesn’t analyze parent tables and a manual analyze on those is needed if we want better planner statistics.

---

From: "Zechman, Derek S" <[email-masked]>
Date: Sat, 28 Jun 2025 01:23:59 +0000

> https://urldefense.com/v3/__https://www.postgresql.org/docs/current/pgupgrade.html__;!!Lf_9VycLqA!jU5QgA1re0Txg_h2dD1N3XvK_l8hYdyMvpcxrLL5GDyQ5qN4aGQcxmDE8qmaV_p5telTzYmOL6S3fR8eRc0s_8UvnFFR6Ws$<https://urldefense.com/v3/__https:/www.postgresql.org/docs/current/pgupgrade.html__;!!Lf_9VycLqA!jU5QgA1re0Txg_h2dD1N3XvK_l8hYdyMvpcxrLL5GDyQ5qN4aGQcxmDE8qmaV_p5telTzYmOL6S3fR8eRc0s_8UvnFFR6Ws$>

> https://urldefense.com/v3/__https://www.postgresql.org/docs/current/app-vacuumdb.html__;!!Lf_9VycLqA!jU5QgA1re0Txg_h2dD1N3XvK_l8hYdyMvpcxrLL5GDyQ5qN4aGQcxmDE8qmaV_p5telTzYmOL6S3fR8eRc0s_8UvvC7gfd0$<https://urldefense.com/v3/__https:/www.postgresql.org/docs/current/app-vacuumdb.html__;!!Lf_9VycLqA!jU5QgA1re0Txg_h2dD1N3XvK_l8hYdyMvpcxrLL5GDyQ5qN4aGQcxmDE8qmaV_p5telTzYmOL6S3fR8eRc0s_8UvvC7gfd0$>

Yours,

Laurenz Albe

There are no entries in pg_stats for the parent table until after I manually run an analyze on it – Example below

=> select relname, reltuples, relkind from pg_class where relname ~ '^chapter_[0-9]+$' or relname='chapter' order by 1;

   relname   | reltuples | relkind

-------------+-----------+---------

 chapter     |        -1 | p

 chapter_1   |         4 | r

 chapter_10  |         4 | r

 chapter_100 |        30 | r

 chapter_101 |        15 | r

 chapter_102 |        15 | r

…

=> select count(*) from pg_stats where tablename='chapter';

 count

-------

     0

(1 row)

=> analyze chapter;

ANALYZE

=> select relname, reltuples, relkind from pg_class where relkind ='p' and relname='chapter';

 relname | reltuples | relkind

---------+-----------+---------

 chapter |      7589 | p

(1 row)

=> select count(*) from pg_stats where tablename='chapter';

 count

-------

    49

(1 row)

toy_epc_stg_1_db=>

---

From: Laurenz Albe <[email-masked]>
Date: Sat, 28 Jun 2025 07:25:30 +0200

> There are no entries in pg_stats for the parent table until after I manually run an analyze on it – Example below

You are right.  I looked at the code, and "vacuumdb" does not process
partitiond tables, even if --analyze-only is specified.  I find that
surprising, aince the SQL command ANALYZE (without a table name) will
also collect statistics for partitioned tables.

I think that it would be a good idea to change that behavior.
In particular, it makes a lot of sense to collect statistics for
partitioned tables after a "pg_upgrade".

Attached is a patch to make "vacuumdb --analyze-only" consider
partitioned tables as well.

Yours,
Laurenz Albe
From 07cbd491011ff5da1243b117c111d51531293782 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <[email-masked]>
Date: Sat, 28 Jun 2025 07:20:02 +0200
Subject: [PATCH v1] Make vacuumdb -Z process partitioned tables

Autoanalyze won't process partitioned tables, but a manual ANALYZE
of the whole database does.  So it was surprising that partitioned
tables were not processed by "vacuumdb --analyze-only".

In addition, "vacuumdb --analyze-only" is what you run to collect
missing statistics after a "pg_upgrade", and it makes a lot of sense
to collect statistics for partitioned tables at that point.

However, running VACUUM on partitioned tables adds no benefit over
vacuuming the partitions, and VACUUM is more expensive than ANALYZE,
so we won't treat partitioned tables unless --analyze-only is given.
Otherwise, we'd end up vacuuming the partitions twice, which would
be a waste of resources.
---
 doc/src/sgml/ref/vacuumdb.sgml |  4 ++++
 src/bin/scripts/vacuumdb.c     | 23 +++++++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/ref/vacuumdb.sgml b/doc/src/sgml/ref/vacuumdb.sgml
index b0680a61814..6a4c8d51b7f 100644
--- a/doc/src/sgml/ref/vacuumdb.sgml
+++ b/doc/src/sgml/ref/vacuumdb.sgml
@@ -440,6 +440,10 @@ PostgreSQL documentation
       <listitem>
        <para>
         Only calculate statistics for use by the optimizer (no vacuum).
+        If that option is specified, <command>vacuumdb</command> will also
+        process partitioned tables.  Without that option, only the partitions
+        will be considered, unless a partitioned table is explicitly specified
+        with the <option>--table</option> option.
        </para>
       </listitem>
      </varlistentry>
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 79b1096eb08..d7ca8300f43 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -911,10 +911,25 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
 	 */
 	if ((objfilter & OBJFILTER_TABLE) == 0)
 	{
-		appendPQExpBufferStr(&catalog_query,
-							 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
-							 CppAsString2(RELKIND_RELATION) ", "
-							 CppAsString2(RELKIND_MATVIEW) "])\n");
+		/*
+		 * VACUUMing partitioned tables would be unreasonably expensive, since
+		 * that entails processing the partitions twice (once as part of the
+		 * partitioned table, once as tables in their own right) for no
+		 * benefit. But if we only ANALYZE, collecting statistics for
+		 * partitioned tables is worth the effort.
+		 */
+		if (vacopts->analyze_only)
+			appendPQExpBufferStr(&catalog_query,
+								 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
+								 CppAsString2(RELKIND_RELATION) ", "
+								 CppAsString2(RELKIND_MATVIEW) ", "
+								 CppAsString2(RELKIND_PARTITIONED_TABLE) "])\n");
+		else
+			appendPQExpBufferStr(&catalog_query,
+								 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
+								 CppAsString2(RELKIND_RELATION) ", "
+								 CppAsString2(RELKIND_MATVIEW) "])\n");
+
 	}
 
 	/*
-- 
2.50.0

---

From: Mircea Cadariu <[email-masked]>
Date: Mon, 07 Jul 2025 12:43:11 +0000

The following review has been posted through the commitfest application:
make installcheck-world:  tested, passed
Implements feature:       tested, passed
Spec compliant:           tested, passed
Documentation:            tested, passed

Hi Laurenz,

Nice focused patch. 

Applied successfully on commit 62a17a92 from master. 

Documentation is updated and there is an explanatory comment for the code, as well as a descriptive commit message. 

To check the patch, I added the following test at the end of src/bin/scripts/t/100_vacuumdb.pl in both master (as experiment) and your patch. In master it does not pass, but with your patch applied it does. 

You can consider adding it to your patch, or I could also do that. 

$node->safe_psql('postgres',
    "CREATE TABLE parent_table (a INT) PARTITION BY LIST (a);\n"
      . "CREATE TABLE child_table PARTITION OF parent_table FOR VALUES IN (1);\n"
      . "INSERT INTO parent_table VALUES (1);\n");
$node->issues_sql_like(
    [
        'vacuumdb', '--analyze-only', 'postgres'
    ],
    qr/statement:\s+ANALYZE\s+public\.parent_table/s,
    '--analyze_only updates statistics for partitioned tables');

Kind regards,
Mircea Cadariu

The new status of this patch is: Waiting on Author

---

From: "Zechman, Derek S" <[email-masked]>
Date: Wed, 9 Jul 2025 11:30:22 +0000

Yours,

Laurenz Albe

Is there a plan to include this patch in future releases/patches of postgres?

Thanks,

(Derek) Sean

---

From: Laurenz Albe <[email-masked]>
Date: Wed, 09 Jul 2025 17:26:02 +0200

> Is there a plan to include this patch in future releases/patches of postgres? 

I have added the patch to the current commitfest:
https://commitfest.postgresql.org/patch/5871/

So far, it has not got any peer review.  So yes, I'd like to include
the patch, but I cannot make it happen by myself.
Essentially, patches get applied if
a) they get peer review and
b) a committer applies them

If you want this to happen, the best thing you could do would be
to review the patch and see if it works for you, if it does what you
need and so on:
https://wiki.postgresql.org/wiki/Reviewing_a_Patch

Yours,
Laurenz Albe

---

From: Mircea Cadariu <[email-masked]>
Date: Wed, 9 Jul 2025 17:37:20 +0100

Hi Laurenz,

> https://commitfest.postgresql.org/patch/5871/

Just to let you know that I have added a review through the commitfest app.

You can see it here: 
https://www.postgresql.org/message-id/flat/[email-masked]

Kind regards,

Mircea Cadariu

---

From: Laurenz Albe <[email-masked]>
Date: Wed, 09 Jul 2025 19:22:35 +0200

> Just to let you know that I have added a review through the commitfest app. 

Thanks!

The patch is still in state "needs review".
If there is something that I should change, you should set it to
"waiting on author".  If you think that the patch is ready to go
as it is, please set it to "ready for committer".

Yours,
Laurenz Albe

---

From: Mircea Cadariu <[email-masked]>
Date: Thu, 10 Jul 2025 17:20:02 +0100

Hi Laurenz,

Got it. I have only one suggestion for the patch. Consider adding a 
corresponding test in src/bin/scripts/t/100_vacuumdb.pl.

Proposal (I used this to check the patch):

       . "CREATE TABLE child_table PARTITION OF parent_table FOR VALUES 
IN (1);\n"

Kind regards,

Mircea Cadariu

---

From: Laurenz Albe <[email-masked]>
Date: Fri, 11 Jul 2025 11:51:30 +0200

[moving to pgsql-hackers]
On Thu, 2025-07-10 at 17:20 +0100, Mircea Cadariu wrote:
>       I have only one suggestion for the patch. Consider adding a 

Good idea; done in the attached version 2 of the patch.

Yours,
Laurenz Albe
From 4bf5048da6ffd250ee204fff419cf975aa7a6548 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <[email-masked]>
Date: Fri, 11 Jul 2025 11:46:55 +0200
Subject: [PATCH v2] Make vacuumdb -Z process partitioned tables

Author: Laurenz Albe <[email-masked]>
Author: Mircea Cadariu <[email-masked]>
Discussion: https://postgr.es/m/CO1PR04MB8281387B9AD9DE30976966BBC045A%40CO1PR04MB8281.namprd04.prod.outlook.com
---
 doc/src/sgml/ref/vacuumdb.sgml    |  4 ++++
 src/bin/scripts/t/100_vacuumdb.pl | 12 ++++++++++++
 src/bin/scripts/vacuumdb.c        | 23 +++++++++++++++++++----
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/ref/vacuumdb.sgml b/doc/src/sgml/ref/vacuumdb.sgml
index b0680a61814..6a4c8d51b7f 100644
--- a/doc/src/sgml/ref/vacuumdb.sgml
+++ b/doc/src/sgml/ref/vacuumdb.sgml
@@ -440,6 +440,10 @@ PostgreSQL documentation
       <listitem>
        <para>
         Only calculate statistics for use by the optimizer (no vacuum).
+        If that option is specified, <command>vacuumdb</command> will also
+        process partitioned tables.  Without that option, only the partitions
+        will be considered, unless a partitioned table is explicitly specified
+        with the <option>--table</option> option.
        </para>
       </listitem>
      </varlistentry>
diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl
index ff56a13b46b..9ab42c39a94 100644
--- a/src/bin/scripts/t/100_vacuumdb.pl
+++ b/src/bin/scripts/t/100_vacuumdb.pl
@@ -340,4 +340,16 @@ $node->issues_sql_unlike(
 	qr/statement:\ ANALYZE/sx,
 	'--missing-stats-only with no missing partition stats');
 
+$node->safe_psql('postgres',
+	"CREATE TABLE parent_table (a INT) PARTITION BY LIST (a);\n"
+	  . "CREATE TABLE child_table PARTITION OF parent_table FOR VALUES
+IN (1);\n"
+	  . "INSERT INTO parent_table VALUES (1);\n");
+$node->issues_sql_like(
+	[
+		'vacuumdb', '--analyze-only', 'postgres'
+	],
+	qr/statement:\s+ANALYZE\s+public\.parent_table/s,
+	'--analyze_only updates statistics for partitioned tables');
+
 done_testing();
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 79b1096eb08..d7ca8300f43 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -911,10 +911,25 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
 	 */
 	if ((objfilter & OBJFILTER_TABLE) == 0)
 	{
-		appendPQExpBufferStr(&catalog_query,
-							 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
-							 CppAsString2(RELKIND_RELATION) ", "
-							 CppAsString2(RELKIND_MATVIEW) "])\n");
+		/*
+		 * VACUUMing partitioned tables would be unreasonably expensive, since
+		 * that entails processing the partitions twice (once as part of the
+		 * partitioned table, once as tables in their own right) for no
+		 * benefit. But if we only ANALYZE, collecting statistics for
+		 * partitioned tables is worth the effort.
+		 */
+		if (vacopts->analyze_only)
+			appendPQExpBufferStr(&catalog_query,
+								 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
+								 CppAsString2(RELKIND_RELATION) ", "
+								 CppAsString2(RELKIND_MATVIEW) ", "
+								 CppAsString2(RELKIND_PARTITIONED_TABLE) "])\n");
+		else
+			appendPQExpBufferStr(&catalog_query,
+								 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
+								 CppAsString2(RELKIND_RELATION) ", "
+								 CppAsString2(RELKIND_MATVIEW) "])\n");
+
 	}
 
 	/*
-- 
2.50.0

---

From: Mircea Cadariu <[email-masked]>
Date: Fri, 11 Jul 2025 20:42:44 +1000

> Good idea; done in the attached version 2 of the patch.

Thanks! Looks good. I have set the status of the Commitfest entry to 
"Ready for Committer".

Kind regards,

Mircea Cadariu

---

From: Fujii Masao <[email-masked]>
Date: Wed, 30 Jul 2025 11:49:56 +0900

> Thanks! Looks good. I have set the status of the Commitfest entry to

I've started reviewing the patch since it's marked as ready for committer.

Overall, I like the change. But I have one question: should this be treated as
a bug fix that we back-patch to supported branches, or is it more of
an improvement that should only go into master?

This wording seems a bit out of place in the --analyze-only section,
since it also describes the default behavior of vacuumdb without that option.
Wouldn't it make more sense to move that explanation in the --table section?

For example, we could add something like:

------------------
If no tables are specified with the --table option, vacuumdb will
clean all regular tables and materialized views in the connected
database. If --analyze-only or --analyze-in-stages is also specified,
it will analyze all regular tables, partitioned tables, and
materialized views (but not foreign tables).
------------------

+ /*

This is probably true. But isn't the main reason more about aligning with
the behavior of the underlying VACUUM and ANALYZE commands? As the vacuumdb
docs says, "There is no effective difference between vacuuming and analyzing
databases via this utility and via other methods for accessing the server.",
so its default target objects should match: VACUUM skips partitioned tables
by default, while ANALYZE includes them. If that's the case, maybe the comment
should reflect that instead.

A plain space might be sufficient instead of \s+.
Also, I don't think the backslash before ".parent_table" is necessary.

Regards,

-- 
Fujii Masao

---

From: Mircea Cadariu <[email-masked]>
Date: Wed, 6 Aug 2025 14:01:18 +1000

Hi,

Thanks!
> an improvement that should only go into master?
I reckon it might make sense to back-patch it to previous versions, as 
users might not upgrade always to the latest version.
> For example, we could add something like:
Yes, agreed.
> should reflect that instead.
I see what you mean. From that perspective, I wonder if we even need a 
comment there at all.
> Also, I don't think the backslash before ".parent_table" is necessary.

Good catch! Indeed let's simplify that to contain strictly only what's 
necessary.

Kind regards,

Mircea Cadariu

---

From: Fujii Masao <[email-masked]>
Date: Wed, 6 Aug 2025 23:25:53 +0900

On Wed, Aug 6, 2025 at 1:01 PM Mircea Cadariu <[email-masked]> wrote:
> I reckon it might make sense to back-patch it to previous versions, as users might not upgrade always to the latest version.

I understand your point. But on second thought, since the patch changes
behavior, I'm leaning toward treating it as an improvement, so it should
only go to master...

> I see what you mean. From that perspective, I wonder if we even need a comment there at all.

Or, if we keep it, though, I'd like to update it to something like
the following:

--------------------
vacuumdb should generally follow the behavior of the underlying
VACUUM and ANALYZE commands. If analyze_only is true, 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.
--------------------

Regards,

-- 
Fujii Masao

---

From: Nathan Bossart <[email-masked]>
Date: Wed, 6 Aug 2025 13:14:12 -0500

> behavior, I'm leaning toward treating it as an improvement, so it should

I also am leaning towards treating this as v19 material.  It's a nontrivial
behavior change, and this option is useful for major version upgrades,
which is an area that we really don't want to surprise users too much.
Furthermore, auto-analyze doesn't process partitioned tables, either, so
this introduces a bit of divergence.  (I'd love to see that project picked
up again someday.  Perhaps I will take a gander...)

-- 
nathan

---

From: Laurenz Albe <[email-masked]>
Date: Wed, 06 Aug 2025 22:52:52 +0200

> behavior, I'm leaning toward treating it as an improvement, so it should

I agree that this behavior change should not be backpatched.
That is not a bugfix.

> Or, if we keep it, though, I'd like to update it to something like

I am fine with that suggestion.

Alternatively, my original comment could be amended with

  Besides, ANALYZE (without an option) processes partitioned tables, and
  "vacuumdb -Z" should behave like ANALYZE.

Yours,
Laurenz Albe

---

From: Fujii Masao <[email-masked]>
Date: Mon, 18 Aug 2025 11:36:48 +0900

> which is an area that we really don't want to surprise users too much.

+1

> up again someday.  Perhaps I will take a gander...)

Sounds good!

Regards,

-- 
Fujii Masao

---

From: Fujii Masao <[email-masked]>
Date: Mon, 18 Aug 2025 11:38:23 +0900

+1

> I am fine with that suggestion.

Thanks! So I've updated the patch based on my earlier comments.
Unless there are objections, I'll commit the attached version to master only.

Regards,

-- 
Fujii Masao

---

From: Laurenz Albe <[email-masked]>
Date: Mon, 18 Aug 2025 08:40:02 +0200

> Unless there are objections, I'll commit the attached version to master only.

I am fine with your patch.

One suggestion:

> @@ -397,6 +397,15 @@ PostgreSQL documentation
>          Multiple tables can be vacuumed by writing multiple
>          <option>-t</option> switches.
>         </para>
> +       <para>
> +        If no tables are specified with the <option>--table</option> option,
> +        <application>vacuumdb</application> will clean all regular tables
> +        and materialized views in the connected database.
> +        If <option>--analyze-only</option> or
> +        <option>--analyze-in-stages</option> is also specified,
> +        it will analyze all regular tables, partitioned tables,
> +        and materialized views (but not foreign tables).
> +       </para>

I suggest replacing "clean" with "process", since VACUUM does so much more than
clean up dead tuples.

Concerning backpatching, I voted against, but I suggest that this be backpatched
to v18.  I don't feel very strongly about it though.

Yours,
Laurenz Albe

---

From: Fujii Masao <[email-masked]>
Date: Tue, 19 Aug 2025 23:40:05 +0900

> I am fine with your patch.

Thanks for the review!

> I suggest replacing "clean" with "process", since VACUUM does so much more than

I see your point. However, since the vacuumdb docs already use "clean"
in several places, I think it's better to keep using "clean" here
for consistency. Thought?

> to v18.  I don't feel very strongly about it though.

As for back-patching, I failed to find a strong reason to apply this change
to v18 over the many other patches that could not be committed before
the feature freeze... Of course if there's broad support for back-patching,
we can certainly revisit it. But for now I'm thinking to commit the patch
to master.

Regards,

-- 
Fujii Masao

---

From: Laurenz Albe <[email-masked]>
Date: Tue, 19 Aug 2025 17:16:12 +0200

> for consistency. Thought?

Works for me; I didn't consider that.

> we can certainly revisit it. But for now I'm thinking to commit the patch

I don't have a strong reason either - my reasoning was that the change is small
and unlikely to introduce a bug, and that it would be nice to get more accurate
statistics on partitioned tables after "pg_upgrade" a year earlier.

But I won't object if the patch is only in v19.

Yours,
Laurenz Albe

---

From: Fujii Masao <[email-masked]>
Date: Wed, 20 Aug 2025 13:31:29 +0900

> But I won't object if the patch is only in v19.

OK, so for now I've pushed the patch to master. Thanks!

Regards,

-- 
Fujii Masao

---

From: Laurenz Albe <[email-masked]>
Date: Wed, 20 Aug 2025 09:14:20 +0200

> OK, so for now I've pushed the patch to master. Thanks!

Thank you for working on that!

Yours,
Laurenz Albe

---

From: Justin Pryzby <[email-masked]>
Date: Wed, 20 Aug 2025 20:51:16 -0500

When analyzing a partitioned table, I think you should use ANALYZE ONLY,
or otherwise avoid processing the children twice.

Thanks for handling this.  I was recently suprised to learn that
vacuumdb doesn't process parents.

-- 
Justin

---

From: Justin Pryzby <[email-masked]>
Date: Thu, 4 Jun 2026 12:14:34 -0500

Checking back.