From 7e2d843d2d1d7f8742fcd7d440974156f232d791 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Mon, 15 Jun 2026 11:00:47 +0800 Subject: [PATCH v2] Fix pg_restore with --schema and --statistics-only Attempting to restore a schema with only statistics skipped all the statistics of the schema, but it should not. Add a pg_dump TAP test for schema-filtered statistics-only restore from a custom archive. --- src/bin/pg_dump/pg_backup_archiver.c | 1 - src/bin/pg_dump/t/002_pg_dump.pl | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 2fd773ad84f..45a8291f1f2 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -3175,7 +3175,6 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH) */ if (strcmp(te->desc, "ACL") == 0 || strcmp(te->desc, "COMMENT") == 0 || - strcmp(te->desc, "STATISTICS DATA") == 0 || strcmp(te->desc, "SECURITY LABEL") == 0) { /* Database properties react to createDB, not selectivity options. */ diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index 3ee9fda50e4..1b08ddc504e 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -587,6 +587,24 @@ my %pgdump_runs = ( 'postgres', ], }, + statistics_only_dump_test_schema_restore => { + dump_cmd => [ + 'pg_dump', '--no-sync', + '--format' => 'custom', + '--file' => "$tempdir/statistics_only_dump_test_schema_restore.dump", + '--statistics-only', + '--schema' => 'dump_test', + 'postgres', + ], + restore_cmd => [ + 'pg_restore', + '--format' => 'custom', + '--file' => "$tempdir/statistics_only_dump_test_schema_restore.sql", + '--statistics-only', + '--schema' => 'dump_test', + "$tempdir/statistics_only_dump_test_schema_restore.dump", + ], + }, no_schema => { dump_cmd => [ 'pg_dump', '--no-sync', @@ -4850,6 +4868,7 @@ my %tests = ( no_schema => 1, section_post_data => 1, statistics_only => 1, + statistics_only_dump_test_schema_restore => 1, schema_only_with_statistics => 1, }, unlike => { @@ -4878,6 +4897,7 @@ my %tests = ( no_schema => 1, section_post_data => 1, statistics_only => 1, + statistics_only_dump_test_schema_restore => 1, schema_only_with_statistics => 1, }, unlike => { @@ -4907,6 +4927,7 @@ my %tests = ( section_data => 1, section_post_data => 1, statistics_only => 1, + statistics_only_dump_test_schema_restore => 1, schema_only_with_statistics => 1, }, unlike => { -- 2.50.1 (Apple Git-155)