Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd64dc4

Browse files
committed
pg_combinebackup: Fix incorrect tablespace handling.
The previous coding mangled the pathname calculation forincremental files located in user-defined tablespaces.Enhance the test cases to cover such cases, as I should havedone originally. Thanks to Andres Freund for alerting me to thelack of test coverage.Discussion:http://postgr.es/m/CA+TgmoYdXTjo9iQeoipTccDpWZzvBNS6EndY2uARM+T4yG_yDg@mail.gmail.com
1 parent6bf5c42 commitcd64dc4

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

‎src/bin/pg_combinebackup/pg_combinebackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ process_directory_recursively(Oid tsoid,
990990

991991
/* Reconstruction logic will do the rest. */
992992
reconstruct_from_incremental_file(ifullpath,ofullpath,
993-
relative_path,
993+
manifest_prefix,
994994
de->d_name+INCREMENTAL_PREFIX_LENGTH,
995995
n_prior_backups,
996996
prior_backup_dirs,

‎src/bin/pg_combinebackup/reconstruct.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ static void read_block(rfile *s, off_t off, uint8 *buffer);
7575
* output_filename should be the path where the reconstructed file is to be
7676
* written.
7777
*
78-
* relative_path should be the relative path to the directory containing this
79-
* file. bare_file_name should be the name of the file within that directory,
80-
* without "INCREMENTAL.".
78+
* relative_path should be the path to the directory containing this file,
79+
* relative to the root of the backup (NOT relative to the root of the
80+
* tablespace). bare_file_name should be the name of the file within that
81+
* directory, without "INCREMENTAL.".
8182
*
8283
* n_prior_backups is the number of prior backups, and prior_backup_dirs is
8384
* an array of pathnames where those backups can be found.

‎src/bin/pg_combinebackup/t/002_compare_backups.pl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
use PostgreSQL::Test::Utils;
88
use Test::More;
99

10+
my$tempdir = PostgreSQL::Test::Utils::tempdir;
11+
1012
# Set up a new database instance.
1113
my$primary = PostgreSQL::Test::Cluster->new('primary');
1214
$primary->init(has_archiving=> 1,allows_streaming=> 1);
1315
$primary->append_conf('postgresql.conf','summarize_wal = on');
1416
$primary->start;
17+
my$tsprimary =$tempdir .'/ts';
18+
mkdir($tsprimary) ||die"mkdir$tsprimary:$!";
1519

1620
# Create some test tables, each containing one row of data, plus a whole
1721
# extra database.
@@ -29,33 +33,49 @@
2933
CREATE TABLE will_get_rewritten (a int, b text);
3034
INSERT INTO will_get_rewritten VALUES (1, 'initial test row');
3135
CREATE DATABASE db_will_get_dropped;
36+
CREATE TABLESPACE ts1 LOCATION '$tsprimary';
37+
CREATE TABLE will_not_change_in_ts (a int, b text) TABLESPACE ts1;
38+
INSERT INTO will_not_change_in_ts VALUES (1, 'initial test row');
39+
CREATE TABLE will_change_in_ts (a int, b text) TABLESPACE ts1;
40+
INSERT INTO will_change_in_ts VALUES (1, 'initial test row');
41+
CREATE TABLE will_get_dropped_in_ts (a int, b text);
42+
INSERT INTO will_get_dropped_in_ts VALUES (1, 'initial test row');
3243
EOM
3344

3445
# Take a full backup.
3546
my$backup1path =$primary->backup_dir .'/backup1';
47+
my$tsbackup1path =$tempdir .'/ts1backup';
48+
mkdir($tsbackup1path) ||die"mkdir$tsbackup1path:$!";
3649
$primary->command_ok(
37-
['pg_basebackup','-D',$backup1path,'--no-sync','-cfast' ],
38-
"full backup");
50+
['pg_basebackup','-D',$backup1path,'--no-sync','-cfast',
51+
"-T${tsprimary}=${tsbackup1path}" ],"full backup");
3952

4053
# Now make some database changes.
4154
$primary->safe_psql('postgres',<<EOM);
4255
UPDATE will_change SET b = 'modified value' WHERE a = 1;
56+
UPDATE will_change_in_ts SET b = 'modified value' WHERE a = 1;
4357
INSERT INTO will_grow
4458
SELECT g, 'additional row' FROM generate_series(2, 5000) g;
4559
TRUNCATE will_shrink;
4660
VACUUM will_get_vacuumed;
4761
DROP TABLE will_get_dropped;
62+
DROP TABLE will_get_dropped_in_ts;
4863
CREATE TABLE newly_created (a int, b text);
4964
INSERT INTO newly_created VALUES (1, 'row for new table');
65+
CREATE TABLE newly_created_in_ts (a int, b text) TABLESPACE ts1;
66+
INSERT INTO newly_created_in_ts VALUES (1, 'row for new table');
5067
VACUUM FULL will_get_rewritten;
5168
DROP DATABASE db_will_get_dropped;
5269
CREATE DATABASE db_newly_created;
5370
EOM
5471

5572
# Take an incremental backup.
5673
my$backup2path =$primary->backup_dir .'/backup2';
74+
my$tsbackup2path =$tempdir .'/tsbackup2';
75+
mkdir($tsbackup2path) ||die"mkdir$tsbackup2path:$!";
5776
$primary->command_ok(
5877
['pg_basebackup','-D',$backup2path,'--no-sync','-cfast',
78+
"-T${tsprimary}=${tsbackup2path}",
5979
'--incremental',$backup1path .'/backup_manifest' ],
6080
"incremental backup");
6181

@@ -78,9 +98,11 @@
7898
# Perform PITR from the full backup. Disable archive_mode so that the archive
7999
# doesn't find out about the new timeline; that way, the later PITR below will
80100
# choose the same timeline.
101+
my$tspitr1path =$tempdir .'/tspitr1';
81102
my$pitr1 = PostgreSQL::Test::Cluster->new('pitr1');
82103
$pitr1->init_from_backup($primary,'backup1',
83-
standby=> 1,has_restoring=> 1);
104+
standby=> 1,has_restoring=> 1,
105+
tablespace_map=> {$tsbackup1path=>$tspitr1path });
84106
$pitr1->append_conf('postgresql.conf',qq{
85107
recovery_target_lsn = '$lsn'
86108
recovery_target_action = 'promote'
@@ -90,10 +112,12 @@
90112

91113
# Perform PITR to the same LSN from the incremental backup. Use the same
92114
# basic configuration as before.
115+
my$tspitr2path =$tempdir .'/tspitr2';
93116
my$pitr2 = PostgreSQL::Test::Cluster->new('pitr2');
94117
$pitr2->init_from_backup($primary,'backup2',
95118
standby=> 1,has_restoring=> 1,
96-
combine_with_prior=> ['backup1' ]);
119+
combine_with_prior=> ['backup1' ],
120+
tablespace_map=> {$tsbackup2path=>$tspitr2path });
97121
$pitr2->append_conf('postgresql.conf',qq{
98122
recovery_target_lsn = '$lsn'
99123
recovery_target_action = 'promote'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp