| 1 |
|
| 2 |
# Copyright (c) 2021-2025, PostgreSQL Global Development Group |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings FATAL => 'all'; |
| 6 |
|
| 7 |
use PostgreSQL::Test::Cluster; |
| 8 |
use PostgreSQL::Test::Utils; |
| 9 |
use Test::More; |
| 10 |
|
| 11 |
my $dbname1 = 'regression_src'; |
| 12 |
my $dbname2 = 'regression_dest1'; |
| 13 |
my $dbname3 = 'regression_dest2'; |
| 14 |
|
| 15 |
my $node = PostgreSQL::Test::Cluster->new('main'); |
| 16 |
$node->init; |
| 17 |
$node->start; |
| 18 |
|
| 19 |
my $backupdir = $node->backup_dir; |
| 20 |
|
| 21 |
$node->run_log([ 'createdb', $dbname1 ]); |
| 22 |
$node->run_log([ 'createdb', $dbname2 ]); |
| 23 |
$node->run_log([ 'createdb', $dbname3 ]); |
| 24 |
|
| 25 |
$node->safe_psql( |
| 26 |
$dbname1, |
| 27 |
qq{ |
| 28 |
create type digit as enum ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); |
| 29 |
|
| 30 |
-- plain table with index |
| 31 |
create table tplain (en digit, data int unique); |
| 32 |
insert into tplain select (x%10)::text::digit, x from generate_series(1,1000) x; |
| 33 |
|
| 34 |
-- non-troublesome hashed partitioning |
| 35 |
create table ths (mod int, data int, unique(mod, data)) partition by hash(mod); |
| 36 |
create table ths_p1 partition of ths for values with (modulus 3, remainder 0); |
| 37 |
create table ths_p2 partition of ths for values with (modulus 3, remainder 1); |
| 38 |
create table ths_p3 partition of ths for values with (modulus 3, remainder 2); |
| 39 |
insert into ths select (x%10), x from generate_series(1,1000) x; |
| 40 |
|
| 41 |
-- dangerous hashed partitioning |
| 42 |
create table tht (en digit, data int, unique(en, data)) partition by hash(en); |
| 43 |
create table tht_p1 partition of tht for values with (modulus 3, remainder 0); |
| 44 |
create table tht_p2 partition of tht for values with (modulus 3, remainder 1); |
| 45 |
create table tht_p3 partition of tht for values with (modulus 3, remainder 2); |
| 46 |
insert into tht select (x%10)::text::digit, x from generate_series(1,1000) x; |
| 47 |
}); |
| 48 |
|
| 49 |
$node->command_ok( |
| 50 |
[ |
| 51 |
'pg_dump', |
| 52 |
'--format' => 'directory', |
| 53 |
'--no-sync', |
| 54 |
'--jobs' => 2, |
| 55 |
'--file' => "$backupdir/dump1", |
| 56 |
$node->connstr($dbname1), |
| 57 |
], |
| 58 |
'parallel dump'); |
| 59 |
|
| 60 |
$node->command_ok( |
| 61 |
[ |
| 62 |
'pg_restore', '--verbose', |
| 63 |
'--dbname' => $node->connstr($dbname2), |
| 64 |
'--jobs' => 3, |
| 65 |
"$backupdir/dump1", |
| 66 |
], |
| 67 |
'parallel restore'); |
| 68 |
|
| 69 |
$node->command_ok( |
| 70 |
[ |
| 71 |
'pg_dump', |
| 72 |
'--format' => 'directory', |
| 73 |
'--no-sync', |
| 74 |
'--jobs' => 2, |
| 75 |
'--file' => "$backupdir/dump2", |
| 76 |
'--inserts', |
| 77 |
$node->connstr($dbname1), |
| 78 |
], |
| 79 |
'parallel dump as inserts'); |
| 80 |
|
| 81 |
$node->command_ok( |
| 82 |
[ |
| 83 |
'pg_restore', '--verbose', |
| 84 |
'--dbname' => $node->connstr($dbname3), |
| 85 |
'--jobs' => 3, |
| 86 |
"$backupdir/dump2", |
| 87 |
], |
| 88 |
'parallel restore as inserts'); |
| 89 |
|
| 90 |
done_testing(); |