Re: regarding statistics retaining with 18 Upgrade - Mailing list pgsql-hackers

From Fujii Masao
Subject Re: regarding statistics retaining with 18 Upgrade
Date
Msg-id CAHGQGwFnfgdGz8aGWVzgFCFwoWQU7KnFFjmxinf4RkQAkzmR+w@mail.gmail.com
Whole thread Raw
In response to Re: regarding statistics retaining with 18 Upgrade  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
On Tue, Nov 18, 2025 at 8:56 AM Bruce Momjian <bruce@momjian.us> wrote:
>
> On Sat, Nov 15, 2025 at 06:52:15PM -0500, Robert Treat wrote:
> > On Sat, Nov 15, 2025 at 9:32 AM Bruce Momjian <bruce@momjian.us> wrote:
> > > On Sat, Nov 15, 2025 at 06:02:53PM +0800, Rambabu V wrote:
> > > > Hi Team,
> > > >
> > > > seems stats are not retained after upgrade. Below are the artifacts , is it
> > > > expected? as per the release notes statistics should be retained.
> > >
> > > Uh, it is the _optimizer_ statistics that are preserved by pg_upgrade,
> > > not the cumulative statistics system:
> > >
> > >         https://www.postgresql.org/docs/current/monitoring-stats.html
> > >
> > > Yes, they are easily confused.
> > >
> >
> > I wonder if it might be worth trying to clarify this a little bit
> > more... perhaps something like the attached?
>
> Patch applied back to PG 18, thanks.

Thanks for working on this!

   <para>
-   If <option>--statistics</option> is specified,
+   When <option>--statistics</option> is specified,
    <command>pg_dumpall</command> will include most optimizer statistics in the
-   resulting dump file.  However, some statistics may not be included, such as
-   those created explicitly with <xref linkend="sql-createstatistics"/> or
-   custom statistics added by an extension.  Therefore, it may be useful to
+   resulting dump file. This does not include all statistics, such as
+   those created explicitly with <xref linkend="sql-createstatistics"/>,
+   custom statistics added by an extension, or statistics collected by the
+   cumulative statistics system.  Therefore, it may still be useful to
    run <command>ANALYZE</command> on each database after restoring from a dump
    file to ensure optimal performance.  You can also run <command>vacuumdb -a
    -z</command> to analyze all databases.

Since pgupgrade.sgml contains similar text, I think it should be
updated as well.
For example, something like this:

-------------------
diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml
index 356baa91299..38ca09b423c 100644
--- a/doc/src/sgml/ref/pgupgrade.sgml
+++ b/doc/src/sgml/ref/pgupgrade.sgml
@@ -833,10 +833,10 @@ psql --username=postgres --file=script.sql postgres
     <para>
      Unless the <option>--no-statistics</option> option is specified,
      <command>pg_upgrade</command> will transfer most optimizer statistics
-     from the old cluster to the new cluster.  However, some statistics may
-     not be transferred, such as those created explicitly with <xref
-     linkend="sql-createstatistics"/> or custom statistics added by an
-     extension.
+     from the old cluster to the new cluster.  This does not transfer
+     all statistics, such as those created explicitly with
+     <xref linkend="sql-createstatistics"/>, custom statistics added by
+     an extension, or statistics collected by the cumulative statistics system.
     </para>
-------------------

Regards,

--
Fujii Masao



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Extended Statistics set/restore/clear functions.
Next
From: Chao Li
Date:
Subject: Re: vacuumdb: add --dry-run