Skip to content

Commit 6da255e

Browse files
author
付与龙10336563
committed
Fix pg_dump for hash partitioning on enum columns
Automatic partition handling: Auto-enables --load-via-partition-root when dumping partitioned tables with hash partitioning on enum types to prevent partition constraint violations after dump/reload cycles Parallel restore safety: Modifies pg_restore to skip TRUNCATE operations when partition root loading is detected, eliminating deadlocks and data loss risks Dump metadata enhancement: Adds special comment markers for TABLE DATA items using partition root loading mode Documentation update: Removes obsolete warning about --load-via-partition-root with parallel restore from pg_dump documentation
1 parent 010b298 commit 6da255e

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,7 @@ dumpTableData(Archive *fout, const TableDataInfo *tdinfo)
28062806

28072807
parentTbinfo = getRootTableInfo(tbinfo);
28082808
copyFrom = fmtQualifiedDumpable(parentTbinfo);
2809-
printfPQExpBuffer(copyBuf, "-- load via partition root %s",
2809+
printfPQExpBuffer(copyBuf, "--load-via-partition-root %s",
28102810
copyFrom);
28112811
tdDefn = pg_strdup(copyBuf->data);
28122812
}

src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ typedef struct _tableInfo
341341
bool dummy_view; /* view's real definition must be postponed */
342342
bool postponed_def; /* matview must be postponed into post-data */
343343
bool ispartition; /* is table a partition? */
344-
bool unsafe_partitions; /* is it an unsafe partitioned table? */
344+
bool unsafe_partitions; /* is it an unsafe partitioned table? */
345345

346346
/*
347347
* These fields are computed only if we decide the table is interesting
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgreSQL::Test::Cluster;
5+
use PostgreSQL::Test::Utils;
6+
use Test::More;
7+
8+
my $dbname1 = 'regression_src';
9+
my $dbname2 = 'regression_dest1';
10+
my $dbname3 = 'regression_dest2';
11+
12+
my $node = PostgreSQL::Test::Cluster->new('main');
13+
$node->init;
14+
$node->start;
15+
16+
my $backupdir = $node->backup_dir;
17+
18+
$node->run_log([ 'createdb', $dbname1 ]);
19+
$node->run_log([ 'createdb', $dbname2 ]);
20+
$node->run_log([ 'createdb', $dbname3 ]);
21+
22+
$node->safe_psql(
23+
$dbname1,
24+
qq{
25+
create type digit as enum ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
26+
27+
-- plain table with index
28+
create table tplain (en digit, data int unique);
29+
insert into tplain select (x%10)::text::digit, x from generate_series(1,1000) x;
30+
31+
-- non-troublesome hashed partitioning
32+
create table ths (mod int, data int, unique(mod, data)) partition by hash(mod);
33+
create table ths_p1 partition of ths for values with (modulus 3, remainder 0);
34+
create table ths_p2 partition of ths for values with (modulus 3, remainder 1);
35+
create table ths_p3 partition of ths for values with (modulus 3, remainder 2);
36+
insert into ths select (x%10), x from generate_series(1,1000) x;
37+
38+
-- dangerous hashed partitioning
39+
create table tht (en digit, data int, unique(en, data)) partition by hash(en);
40+
create table tht_p1 partition of tht for values with (modulus 3, remainder 0);
41+
create table tht_p2 partition of tht for values with (modulus 3, remainder 1);
42+
create table tht_p3 partition of tht for values with (modulus 3, remainder 2);
43+
insert into tht select (x%10)::text::digit, x from generate_series(1,1000) x;
44+
});
45+
46+
$node->command_ok(
47+
[
48+
'pg_dump', '-Fd', '--no-sync', '-j2', '-f', "$backupdir/dump1",
49+
$node->connstr($dbname1)
50+
],
51+
'parallel dump');
52+
53+
$node->command_ok(
54+
[
55+
'pg_restore', '-v',
56+
'-d', $node->connstr($dbname2),
57+
'-j3', "$backupdir/dump1"
58+
],
59+
'parallel restore');
60+
61+
$node->command_ok(
62+
[
63+
'pg_dump', '-Fd',
64+
'--no-sync', '-j2',
65+
'-f', "$backupdir/dump2",
66+
'--inserts', $node->connstr($dbname1)
67+
],
68+
'parallel dump as inserts');
69+
70+
$node->command_ok(
71+
[
72+
'pg_restore', '-v',
73+
'-d', $node->connstr($dbname3),
74+
'-j3', "$backupdir/dump2"
75+
],
76+
'parallel restore as inserts');
77+
78+
done_testing();

0 commit comments

Comments
 (0)