Re: pg_restore handles extended statistics inconsistently with statistics data

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Corey Huinker <corey.huinker@gmail.com>
Cc: Chao Li <li.evan.chao@gmail.com>, PostgreSQL-development <pgsql-hackers@lists.postgresql.org>, Michael Paquier <michael.paquier@gmail.com>, Jeff Davis <pgsql@j-davis.com>
Date: 2026-06-16T02:07:22Z
Lists: pgsql-hackers
On Tue, Jun 16, 2026 at 07:15:51AM +0900, Michael Paquier wrote:
> That's the behavior since v15.  Contrary to you, the behavior of
> specifying a table in pg_dump and pg_restore but not including a stats
> definition makes more sense here.  The reasoning is that a stats
> object may live on a different schema than the table it is defined on,
> so you cannot guarantee that its schema has been created if you only
> create a table on a schema.

Sharing the check for a STATISTICS DATA TOC entry on table and index
names was making me ticking a bit, as this is not entirely
collision-proof for the names, but it also looks like we do things the
same way with TABLE DATA and INDEX, so..  At the end, applied down to
v18 as suggested.
--
Michael

Commits

  1. pg_restore: Use dependency-based matching for STATISTICS DATA

  2. Fix inconsistencies with pg_restore --statistics[-only]