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

Commit708b0da

Browse files
committed
Merge branch 'PGPRO_pg_basebackup_slot' into PGPRO9_5
2 parents9764b25 +c2286f4 commit708b0da

File tree

9 files changed

+120
-33
lines changed

9 files changed

+120
-33
lines changed

‎doc/src/sgml/install-windows.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ $ENV{CONFIG}="Debug";
439439
<userinput>vcregress modulescheck</userinput>
440440
<userinput>vcregress ecpgcheck</userinput>
441441
<userinput>vcregress isolationcheck</userinput>
442-
<userinput>vcregressbincheck</userinput>
442+
<userinput>vcregresstapcheck</userinput>
443443
<userinput>vcregress upgradecheck</userinput>
444444
</screen>
445445

@@ -454,8 +454,8 @@ $ENV{CONFIG}="Debug";
454454
</para>
455455

456456
<para>
457-
Running the regression tests on client programs, with "vcregressbincheck",
458-
requires anadditional Perl module to be installed:
457+
Running theTAPregression tests, with "vcregresstapcheck", requires an
458+
additional Perl module to be installed:
459459
<variablelist>
460460
<varlistentry>
461461
<term><productname>IPC::Run</productname></term>

‎doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,35 @@ doc/src/sgml/ref/pg_basebackup.sgml
215215
<listitem>
216216

217217
<para>
218-
Write a minimal <filename>recovery.conf</filename> in the output directory (or into
219-
the base archive file when using tar format) to ease setting
220-
up a standby server.
218+
Write a minimal <filename>recovery.conf</filename> in the output
219+
directory (or into the base archive file when using tar format) to
220+
ease setting up a standby server.
221+
The <filename>recovery.conf</filename> file will record the connection
222+
settings and, if specified, the replication slot
223+
that <application>pg_basebackup</application> is using, so that the
224+
streaming replication will use the same settings later on.
221225
</para>
222226

223227
</listitem>
224228
</varlistentry>
225229

230+
<varlistentry>
231+
<term><option>-S <replaceable>slotname</replaceable></option></term>
232+
<term><option>--slot=<replaceable class="parameter">slotname</replaceable></option></term>
233+
<listitem>
234+
<para>
235+
This option can only be used together with <literal>-X
236+
stream</literal>. It causes the WAL streaming to use the specified
237+
replication slot. If the base backup is intended to be used as a
238+
streaming replication standby using replication slots, it should then
239+
use the same replication slot name
240+
in <filename>recovery.conf</filename>. That way, it is ensured that
241+
the server does not remove any necessary WAL data in the time between
242+
the end of the base backup and the start of streaming replication.
243+
</para>
244+
</listitem>
245+
</varlistentry>
246+
226247
<varlistentry>
227248
<term><option>-T <replaceable class="parameter">olddir</replaceable>=<replaceable class="parameter">newdir</replaceable></option></term>
228249
<term><option>--tablespace-mapping=<replaceable class="parameter">olddir</replaceable>=<replaceable class="parameter">newdir</replaceable></option></term>

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ usage(void)
239239
" (in kB/s, or use suffix \"k\" or \"M\")\n"));
240240
printf(_(" -R, --write-recovery-conf\n"
241241
" write recovery.conf after backup\n"));
242+
printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
242243
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
243244
" relocate tablespace in OLDDIR to NEWDIR\n"));
244245
printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n"));
@@ -1526,6 +1527,13 @@ GenerateRecoveryConf(PGconn *conn)
15261527
appendPQExpBuffer(recoveryconfcontents,"primary_conninfo = '%s'\n",escaped);
15271528
free(escaped);
15281529

1530+
if (replication_slot)
1531+
{
1532+
escaped=escape_quotes(replication_slot);
1533+
appendPQExpBuffer(recoveryconfcontents,"primary_slot_name = '%s'\n",replication_slot);
1534+
free(escaped);
1535+
}
1536+
15291537
if (PQExpBufferBroken(recoveryconfcontents)||
15301538
PQExpBufferDataBroken(conninfo_buf))
15311539
{
@@ -1924,6 +1932,7 @@ main(int argc, char **argv)
19241932
{"checkpoint",required_argument,NULL,'c'},
19251933
{"max-rate",required_argument,NULL,'r'},
19261934
{"write-recovery-conf",no_argument,NULL,'R'},
1935+
{"slot",required_argument,NULL,'S'},
19271936
{"tablespace-mapping",required_argument,NULL,'T'},
19281937
{"xlog",no_argument,NULL,'x'},
19291938
{"xlog-method",required_argument,NULL,'X'},
@@ -1964,7 +1973,7 @@ main(int argc, char **argv)
19641973
}
19651974
}
19661975

1967-
while ((c=getopt_long(argc,argv,"D:F:r:RT:xX:l:zZ:d:c:h:p:U:s:wWvP",
1976+
while ((c=getopt_long(argc,argv,"D:F:r:RT:xX:l:zZ:d:c:h:p:U:s:S:wWvP",
19681977
long_options,&option_index))!=-1)
19691978
{
19701979
switch (c)
@@ -1991,6 +2000,9 @@ main(int argc, char **argv)
19912000
case'R':
19922001
writerecoveryconf= true;
19932002
break;
2003+
case'S':
2004+
replication_slot=pg_strdup(optarg);
2005+
break;
19942006
case'T':
19952007
tablespace_list_append(optarg);
19962008
break;
@@ -2155,6 +2167,16 @@ main(int argc, char **argv)
21552167
exit(1);
21562168
}
21572169

2170+
if (replication_slot&& !streamwal)
2171+
{
2172+
fprintf(stderr,
2173+
_("%s: replication slots can only be used with WAL streaming\n"),
2174+
progname);
2175+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
2176+
progname);
2177+
exit(1);
2178+
}
2179+
21582180
if (strcmp(xlog_dir,"")!=0)
21592181
{
21602182
if (format!='p')

‎src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Cwd;
44
use Config;
55
use TestLib;
6-
use Test::Moretests=>46;
6+
use Test::Moretests=>51;
77

88
program_help_ok('pg_basebackup');
99
program_version_ok('pg_basebackup');
@@ -92,7 +92,7 @@
9292
# The following tests test symlinks. Windows doesn't have symlinks, so
9393
# skip on Windows.
9494
SKIP: {
95-
skip"symlinks not supported on Windows", 10if ($windows_os);
95+
skip"symlinks not supported on Windows", 10if ($Config{osname}eq"MSWin32");
9696

9797
# Create a temporary directory in the system location and symlink it
9898
# to our physical temp location. That way we can use shorter names
@@ -169,3 +169,17 @@
169169
'pg_basebackup with replication slot fails without -X stream');
170170
command_fails(['pg_basebackup','-D',"$tempdir/backupxs_sl_fail",'-X','stream','-S','slot1' ],
171171
'pg_basebackup fails with nonexistent replication slot');
172+
173+
psql'postgres',q{SELECT * FROM pg_create_physical_replication_slot('slot1')};
174+
my$lsn = psql'postgres',q{SELECT restart_lsn FROM pg_replication_slots WHERE slot_name = 'slot1'};
175+
is($lsn,'','restart LSN of new slot is null');
176+
command_ok(['pg_basebackup','-D',"$tempdir/backupxs_sl",'-X','stream','-S','slot1' ],
177+
'pg_basebackup -X stream with replication slot runs');
178+
$lsn = psql'postgres',q{SELECT restart_lsn FROM pg_replication_slots WHERE slot_name = 'slot1'};
179+
like($lsn,qr!^0/[0-9A-Z]{7,8}$!,'restart LSN of slot has advanced');
180+
181+
command_ok(['pg_basebackup','-D',"$tempdir/backupxs_sl_R",'-X','stream','-S','slot1','-R' ],
182+
'pg_basebackup with replication slot and -R runs');
183+
like(slurp_file("$tempdir/backupxs_sl_R/recovery.conf"),
184+
qr/^primary_slot_name = 'slot1'$/m,
185+
'recovery.conf sets primary_slot_name');

‎src/bin/pg_ctl/t/001_start_stop.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"$tempdir/data" ],
2222
'configure authentication');
2323
open CONF,">>$tempdir/data/postgresql.conf";
24-
print CONF"fsync = off\n";
25-
if (!$windows_os)
24+
if ($Config{osname}ne"MSWin32")
2625
{
2726
print CONF"listen_addresses = ''\n";
2827
print CONF"unix_socket_directories = '$tempdir_short'\n";

‎src/bin/pg_rewind/RewindTest.pm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ max_connections = 10
188188

189189
# Accept replication connections on master
190190
configure_hba_for_replication$test_master_datadir;
191-
}
192191

193192
substart_master
194193
{
@@ -222,8 +221,12 @@ recovery_target_timeline='latest'
222221
'-l',"$log_path/standby.log",
223222
'-o',"-p$port_standby",'start');
224223

225-
# The standby may have WAL to apply before it matches the primary. That
226-
# is fine, because no test examines the standby before promotion.
224+
# Wait until the standby has caught up with the primary, by polling
225+
# pg_stat_replication.
226+
my$caughtup_query =
227+
"SELECT pg_current_xlog_location() = replay_location FROM pg_stat_replication WHERE application_name = 'rewind_standby';";
228+
poll_query_until($caughtup_query,$connstr_master)
229+
ordie"Timed out while waiting for standby to catch up";
227230
}
228231

229232
subpromote_standby

‎src/test/perl/TestLib.pm

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ sub standard_initdb
143143

144144
open CONF,">>$pgdata/postgresql.conf";
145145
print CONF"\n# Added by TestLib.pm)\n";
146-
print CONF"fsync = off\n";
147-
if ($windows_os)
146+
if ($Config{osname}eq"MSWin32")
148147
{
149148
print CONF"listen_addresses = '127.0.0.1'\n";
150149
}
@@ -155,7 +154,7 @@ sub standard_initdb
155154
}
156155
close CONF;
157156

158-
$ENV{PGHOST} =$windows_os ?"127.0.0.1" :$tempdir_short;
157+
$ENV{PGHOST} =($Config{osname}eq"MSWin32") ?"127.0.0.1" :$tempdir_short;
159158
}
160159

161160
# Set up the cluster to allow replication connections, in the same way that
@@ -166,7 +165,7 @@ sub configure_hba_for_replication
166165

167166
open HBA,">>$pgdata/pg_hba.conf";
168167
print HBA"\n# Allow replication (set up by TestLib.pm)\n";
169-
if (!$windows_os)
168+
if ($Config{osname}ne"MSWin32")
170169
{
171170
print HBA"local replication all trust\n";
172171
}
@@ -190,7 +189,7 @@ sub start_test_server
190189
standard_initdb"$tempdir/pgdata";
191190

192191
$ret = system_log('pg_ctl','-D',"$tempdir/pgdata",'-w','-l',
193-
"$log_path/postmaster.log",'-o',"--log-statement=all",
192+
"$log_path/postmaster.log",'-o',"--fsync=off --log-statement=all",
194193
'start');
195194

196195
if ($ret != 0)
@@ -227,7 +226,6 @@ sub psql
227226
print("# Running SQL command:$sql\n");
228227
run ['psql','-X','-A','-t','-q','-d',$dbname,'-f','-' ],'<', \$sql,'>', \$stdout,'2>', \$stderrordie;
229228
chomp$stdout;
230-
$stdout =~s/\r//gif$Config{osname}eq'msys';
231229
return$stdout;
232230
}
233231

‎src/tools/msvc/clean.bat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ if exist src\test\regress\autoinc.dll del /q src\test\regress\autoinc.dll
9292
ifexist src\bin\initdb\tmp_checkrd /s /q src\bin\initdb\tmp_check
9393
ifexist src\bin\pg_basebackup\tmp_checkrd /s /q src\bin\pg_basebackup\tmp_check
9494
ifexist src\bin\pg_config\tmp_checkrd /s /q src\bin\pg_config\tmp_check
95-
ifexist src\bin\pg_controldata\tmp_checkrd /s /q src\bin\pg_controldata\tmp_check
9695
ifexist src\bin\pg_ctl\tmp_checkrd /s /q src\bin\pg_ctl\tmp_check
9796
ifexist src\bin\pg_rewind\tmp_checkrd /s /q src\bin\pg_rewind\tmp_check
98-
ifexist src\bin\pgbench\tmp_checkrd /s /q src\bin\pgbench\tmp_check
9997
ifexist src\bin\scripts\tmp_checkrd /s /q src\bin\scripts\tmp_check
10098

10199
REM Clean up datafiles built with contrib

‎src/tools/msvc/vcregress.pl

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
my$what =shift ||"";
3636
if ($what =~
37-
/^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck|bincheck)$/i
37+
/^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck|tapcheck)$/i
3838
)
3939
{
4040
$what =uc$what;
@@ -61,14 +61,7 @@
6161
$schedule ="parallel"if ($whateq'CHECK' ||$what =~/PARALLEL/);
6262
}
6363

64-
if ($ENV{PERL5LIB})
65-
{
66-
$ENV{PERL5LIB} ="$topdir/src/tools/msvc;$ENV{PERL5LIB}";
67-
}
68-
else
69-
{
70-
$ENV{PERL5LIB} ="$topdir/src/tools/msvc";
71-
}
64+
$ENV{PERL5LIB} ="$topdir/src/tools/msvc;$ENV{PERL5LIB}";
7265

7366
my$maxconn ="";
7467
$maxconn ="--max_connections=$ENV{MAX_CONNECTIONS}"
@@ -88,7 +81,7 @@
8881
CONTRIBCHECK=> \&contribcheck,
8982
MODULESCHECK=> \&modulescheck,
9083
ISOLATIONCHECK=> \&isolationcheck,
91-
BINCHECK=> \&bincheck,
84+
TAPCHECK=> \&tapcheck,
9285
UPGRADECHECK=> \&upgradecheck,);
9386

9487
my$proc =$command{$what};
@@ -175,7 +168,46 @@ sub isolationcheck
175168
exit$statusif$status;
176169
}
177170

178-
subtap_check
171+
subtapcheck
172+
{
173+
InstallTemp();
174+
175+
my@args = ("prove","--verbose","t/*.pl");
176+
177+
$ENV{PATH} ="$tmp_installdir/bin;$ENV{PATH}";
178+
$ENV{PERL5LIB} ="$topdir/src/test/perl;$ENV{PERL5LIB}";
179+
$ENV{PG_REGRESS} ="$topdir/$Config/pg_regress/pg_regress";
180+
181+
# Find out all the existing TAP tests by looking for t/ directories
182+
# in the tree.
183+
my$tap_dirs = [];
184+
my@top_dir = ($topdir);
185+
File::Find::find(
186+
{wanted=>sub {
187+
/^t\z/s
188+
&&push(@$tap_dirs,$File::Find::name);
189+
}
190+
},
191+
@top_dir);
192+
193+
# Process each test
194+
foreachmy$test_path (@$tap_dirs)
195+
{
196+
# Like on Unix "make check-world", don't run the SSL test suite
197+
# automatically.
198+
nextif ($test_path =~/\/src\/test\/ssl\//);
199+
200+
my$dir = dirname($test_path);
201+
chdir$dir;
202+
# Reset those values, they may have been changed by another test.
203+
$ENV{TESTDIR} ="$dir";
204+
system(@args);
205+
my$status =$? >> 8;
206+
exit$statusif$status;
207+
}
208+
}
209+
210+
subplcheck
179211
{
180212
die"Tap tests not enabled in configuration"
181213
unless$config->{tap_tests};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp