]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Include extended statistics data in pg_dump
authorMichael Paquier <michael@paquier.xyz>
Tue, 27 Jan 2026 04:42:32 +0000 (13:42 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 27 Jan 2026 04:42:32 +0000 (13:42 +0900)
commitc32fb29e979db4a7b92adb29007725eeacf91f64
treec383ec4604f1540e271d5c689f3bf26fedc7631c
parent1ea44d7ddfb6ebacb6fb8ae2f5d6e904b2394f29
Include extended statistics data in pg_dump

This commit integrates the new pg_restore_extended_stats() function into
pg_dump, so as the data of extended statistics is detected and included
in dumps when the --statistics switch is specified.  Currently, the same
extended stats kinds as the ones supported by the SQL function can be
dumped: "n_distinct" and "dependencies".

The extended statistics data can be dumped down to PostgreSQL 10, with
the following changes depending on the backend version dealt with:
- In v19 and newer versions, the format of pg_ndistinct and
pg_dependencies has changed, catalogs can be directly queried.
- In v18 and older versions, the format is translated to the new format
supported by the backend.
- In v14 and older versions, inherited extended statistics are not
supported.
- In v11 and older versions, the data for ndistinct and dependencies
was stored in pg_statistic_ext.  These have been moved to pg_stats_ext
in v12.
- Extended Statistics have been introduced in v10, no support is needed
for versions older than that.

The extended statistics data is dumped if it can be found in the
catalogs.  If the catalogs are empty, then no restore of the stats data
is attempted.

Author: Corey Huinker <corey.huinker@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com
src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/t/002_pg_dump.pl
src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm