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

Commit927474c

Browse files
committed
pg_rewind: Allow writing recovery configuration
This is provided with a new switch --write-recovery-conf and reuses thepg_basebackup code.Author: Paul Guo, Jimmy Yih, Ashwin AgrawalReviewed-by: Alexey Kondratov, Michaël Paquier, Álvaro HerreraDiscussion:https://postgr.es/m/CAEET0ZEffUkXc48pg2iqARQgGRYDiiVxDu+yYek_bTwJF+q=Uw@mail.gmail.com
1 parenta12c75a commit927474c

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

‎doc/src/sgml/ref/pg_rewind.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ PostgreSQL documentation
180180
</listitem>
181181
</varlistentry>
182182

183+
<varlistentry>
184+
<term><option>-R</option></term>
185+
<term><option>--write-recovery-conf</option></term>
186+
<listitem>
187+
<para>
188+
Create <filename>standby.signal</filename> and append connection
189+
settings to <filename>postgresql.auto.conf</filename> in the output
190+
directory. <literal>--source-server</literal> is mandatory with
191+
this option.
192+
</para>
193+
</listitem>
194+
</varlistentry>
195+
183196
<varlistentry>
184197
<term><option>-n</option></term>
185198
<term><option>--dry-run</option></term>

‎src/bin/pg_rewind/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ top_builddir = ../../..
1616
include$(top_builddir)/src/Makefile.global
1717

1818
overrideCPPFLAGS := -I$(libpq_srcdir) -DFRONTEND$(CPPFLAGS)
19-
LDFLAGS_INTERNAL +=$(libpq_pgport)
19+
LDFLAGS_INTERNAL +=$(libpq_pgport) -L$(top_builddir)/src/fe_utils -lpgfeutils
2020

2121
OBJS= pg_rewind.o parsexlog.o xlogreader.o datapagemap.o timeline.o\
2222
fetch.o file_ops.o copy_fetch.o libpq_fetch.o filemap.o\

‎src/bin/pg_rewind/libpq_fetch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
#include"file_ops.h"
2121
#include"filemap.h"
2222

23-
#include"libpq-fe.h"
2423
#include"catalog/pg_type_d.h"
2524
#include"fe_utils/connect.h"
2625
#include"port/pg_bswap.h"
2726

28-
staticPGconn*conn=NULL;
27+
PGconn*conn=NULL;
2928

3029
/*
3130
* Files are fetched max CHUNKSIZE bytes at a time.

‎src/bin/pg_rewind/pg_rewind.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include"common/file_perm.h"
2828
#include"common/file_utils.h"
2929
#include"common/restricted_token.h"
30+
#include"fe_utils/recovery_gen.h"
3031
#include"getopt_long.h"
3132
#include"storage/bufpage.h"
3233

@@ -41,6 +42,7 @@ static void syncTargetDirectory(void);
4142
staticvoidsanityChecks(void);
4243
staticvoidfindCommonAncestorTimeline(XLogRecPtr*recptr,int*tliIndex);
4344
staticvoidensureCleanShutdown(constchar*argv0);
45+
staticvoiddisconnect_atexit(void);
4446

4547
staticControlFileDataControlFile_target;
4648
staticControlFileDataControlFile_source;
@@ -76,6 +78,8 @@ usage(const char *progname)
7678
printf(_(" -D, --target-pgdata=DIRECTORY existing data directory to modify\n"));
7779
printf(_(" --source-pgdata=DIRECTORY source data directory to synchronize with\n"));
7880
printf(_(" --source-server=CONNSTR source server to synchronize with\n"));
81+
printf(_(" -R, --write-recovery-conf write configuration for replication\n"
82+
" (requires --source-server)\n"));
7983
printf(_(" -n, --dry-run stop before modifying anything\n"));
8084
printf(_(" -N, --no-sync do not wait for changes to be written\n"
8185
" safely to disk\n"));
@@ -94,6 +98,7 @@ main(int argc, char **argv)
9498
staticstructoptionlong_options[]= {
9599
{"help",no_argument,NULL,'?'},
96100
{"target-pgdata",required_argument,NULL,'D'},
101+
{"write-recovery-conf",no_argument,NULL,'R'},
97102
{"source-pgdata",required_argument,NULL,1},
98103
{"source-server",required_argument,NULL,2},
99104
{"no-ensure-shutdown",no_argument,NULL,44},
@@ -118,6 +123,7 @@ main(int argc, char **argv)
118123
XLogRecPtrendrec;
119124
TimeLineIDendtli;
120125
ControlFileDataControlFile_new;
126+
boolwriterecoveryconf= false;
121127

122128
pg_logging_init(argv[0]);
123129
set_pglocale_pgservice(argv[0],PG_TEXTDOMAIN("pg_rewind"));
@@ -138,7 +144,7 @@ main(int argc, char **argv)
138144
}
139145
}
140146

141-
while ((c=getopt_long(argc,argv,"D:nNP",long_options,&option_index))!=-1)
147+
while ((c=getopt_long(argc,argv,"D:nNPR",long_options,&option_index))!=-1)
142148
{
143149
switch (c)
144150
{
@@ -158,6 +164,10 @@ main(int argc, char **argv)
158164
do_sync= false;
159165
break;
160166

167+
case'R':
168+
writerecoveryconf= true;
169+
break;
170+
161171
case3:
162172
debug= true;
163173
pg_logging_set_level(PG_LOG_DEBUG);
@@ -200,6 +210,13 @@ main(int argc, char **argv)
200210
exit(1);
201211
}
202212

213+
if (writerecoveryconf&&connstr_source==NULL)
214+
{
215+
pg_log_error("no source server information (--source--server) specified for --write-recovery-conf");
216+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
217+
exit(1);
218+
}
219+
203220
if (optind<argc)
204221
{
205222
pg_log_error("too many command-line arguments (first is \"%s\")",
@@ -236,6 +253,8 @@ main(int argc, char **argv)
236253

237254
umask(pg_mode_mask);
238255

256+
atexit(disconnect_atexit);
257+
239258
/* Connect to remote server */
240259
if (connstr_source)
241260
libpqConnect(connstr_source);
@@ -322,6 +341,9 @@ main(int argc, char **argv)
322341
if (!rewind_needed)
323342
{
324343
pg_log_info("no rewind required");
344+
if (writerecoveryconf)
345+
WriteRecoveryConfig(conn,datadir_target,
346+
GenerateRecoveryConfig(conn,NULL));
325347
exit(0);
326348
}
327349

@@ -419,6 +441,10 @@ main(int argc, char **argv)
419441
pg_log_info("syncing target data directory");
420442
syncTargetDirectory();
421443

444+
if (writerecoveryconf)
445+
WriteRecoveryConfig(conn,datadir_target,
446+
GenerateRecoveryConfig(conn,NULL));
447+
422448
pg_log_info("Done!");
423449

424450
return0;
@@ -828,3 +854,10 @@ ensureCleanShutdown(const char *argv0)
828854
pg_fatal("Command was: %s",cmd);
829855
}
830856
}
857+
858+
staticvoid
859+
disconnect_atexit(void)
860+
{
861+
if (conn!=NULL)
862+
PQfinish(conn);
863+
}

‎src/bin/pg_rewind/pg_rewind.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
#include"datapagemap.h"
1515

1616
#include"access/timeline.h"
17+
#include"common/logging.h"
18+
#include"libpq-fe.h"
1719
#include"storage/block.h"
1820
#include"storage/relfilenode.h"
1921

20-
#include"common/logging.h"
2122

2223
/* Configuration options */
2324
externchar*datadir_target;
@@ -31,6 +32,9 @@ extern intWalSegSz;
3132
externTimeLineHistoryEntry*targetHistory;
3233
externinttargetNentries;
3334

35+
/* general state */
36+
externPGconn*conn;
37+
3438
/* Progress counters */
3539
externuint64fetch_size;
3640
externuint64fetch_done;
@@ -53,6 +57,7 @@ extern void progress_report(bool force);
5357

5458
/* in timeline.c */
5559
externTimeLineHistoryEntry*rewind_parseTimeLineHistory(char*buffer,
56-
TimeLineIDtargetTLI,int*nentries);
60+
TimeLineIDtargetTLI,
61+
int*nentries);
5762

5863
#endif/* PG_REWIND_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp