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

Commita7eadaa

Browse files
committed
Fix pg_rewind when rewinding new database with tables included
This fixes an issue introduced by266b6ac, which has added filters toexclude file patterns on the target and source data directories toreduce the number of files transferred. Filters get applied to boththe target and source data files, and include pg_internal.init which ispresent for each database once relations are created on it. However, ifthe target differed from the source with at least one new database withrelations, the rewind would fail due to the exclusion filters applied onthe target files, causing pg_internal.init to still be present on thetarget database folder, while its contents should have been completelyremoved so as there is nothing remaining inside at the time of thefolder deletion.Applying exclusion filters on the source files is fine, because this waythe amount of data copied from the source to the target is reduced. Andactually, not applying the filters on the target is what pg_rewindshould do, because this causes such files to be automatically removedduring the rewind on the target. Exclusion filters apply to paths whichare removed or recreated automatically at startup, so removing all thosefiles on the target during the rewind is a win.The existing set of TAP tests already stresses the rewind of databases,but it did not include any tables on those newly-created databases.Creating extra tables in this case is enough to reproduce the failure,so the existing tests are extended to close the gap.Reported-by: Mithun CyAuthor: Michael PaquierDiscussion:https://postgr.es/m/CADq3xVYt6_pO7ZzmjOqPgY9HWsL=kLd-_tNyMtdfjKqEALDyTA@mail.gmail.comBackpatch-through: 11
1 parentfa33956 commita7eadaa

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

‎src/bin/pg_rewind/filemap.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
147147

148148
Assert(map->array==NULL);
149149

150-
/* ignore any path matching the exclusion filters */
150+
/*
151+
* Skip any files matching the exclusion filters. This has the effect to
152+
* remove all those files on the target.
153+
*/
151154
if (check_file_excluded(path, true))
152155
return;
153156

@@ -334,12 +337,10 @@ process_target_file(const char *path, file_type_t type, size_t oldsize,
334337
file_entry_t*entry;
335338

336339
/*
337-
*Ignore any path matching theexclusion filters. Thisis not actually
338-
*mandatory for targetfiles, but this does not hurt and let's be
339-
*consistent withthe sourceprocessing.
340+
*Do not apply anyexclusion filters here. Thishas advantage to remove
341+
*from the targetdata folder all paths which have been filtered out from
342+
*the source data folder when processingthe sourcefiles.
340343
*/
341-
if (check_file_excluded(path, false))
342-
return;
343344

344345
snprintf(localpath,sizeof(localpath),"%s/%s",datadir_target,path);
345346
if (lstat(localpath,&statbuf)<0)

‎src/bin/pg_rewind/t/002_databases.pl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,27 @@ sub run_test
1515
RewindTest::setup_cluster($test_mode, ['-g']);
1616
RewindTest::start_master();
1717

18-
# Create a database in master.
18+
# Create a database in master with a table.
1919
master_psql('CREATE DATABASE inmaster');
20+
master_psql('CREATE TABLE inmaster_tab (a int)','inmaster');
2021

2122
RewindTest::create_standby($test_mode);
2223

23-
# Create another database, the creation is replicated to the standby
24+
# Create another database with another table, the creation is
25+
# replicated to the standby.
2426
master_psql('CREATE DATABASE beforepromotion');
27+
master_psql('CREATE TABLE beforepromotion_tab (a int)',
28+
'beforepromotion');
2529

2630
RewindTest::promote_standby();
2731

2832
# Create databases in the old master and the new promoted standby.
2933
master_psql('CREATE DATABASE master_afterpromotion');
34+
master_psql('CREATE TABLE master_promotion_tab (a int)',
35+
'master_afterpromotion');
3036
standby_psql('CREATE DATABASE standby_afterpromotion');
37+
standby_psql('CREATE TABLE standby_promotion_tab (a int)',
38+
'standby_afterpromotion');
3139

3240
# The clusters are now diverged.
3341

‎src/bin/pg_rewind/t/RewindTest.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,20 @@ our $node_standby;
6868
submaster_psql
6969
{
7070
my$cmd =shift;
71+
my$dbname =shift ||'postgres';
7172

7273
system_or_bail'psql','-q','--no-psqlrc','-d',
73-
$node_master->connstr('postgres'),'-c',"$cmd";
74+
$node_master->connstr($dbname),'-c',"$cmd";
7475
return;
7576
}
7677

7778
substandby_psql
7879
{
7980
my$cmd =shift;
81+
my$dbname =shift ||'postgres';
8082

8183
system_or_bail'psql','-q','--no-psqlrc','-d',
82-
$node_standby->connstr('postgres'),'-c',"$cmd";
84+
$node_standby->connstr($dbname),'-c',"$cmd";
8385
return;
8486
}
8587

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp