Re: regarding statistics retaining with 18 Upgrade

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Treat <rob(at)xzilla(dot)net>, Rambabu V <ram(dot)wissen(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: regarding statistics retaining with 18 Upgrade
Date: 2025-11-18 03:41:28
Message-ID: CAHGQGwFnfgdGz8aGWVzgFCFwoWQU7KnFFjmxinf4RkQAkzmR+w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 18, 2025 at 8:56 AM Bruce Momjian <bruce(at)momjian(dot)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(at)momjian(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-11-18 03:58:16 Re: vacuumdb: add --dry-run
Previous Message Michael Paquier 2025-11-18 03:34:29 Re: Extended Statistics set/restore/clear functions.