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

Commit0d5c387

Browse files
committed
Add option --config-file to pg_rewind
This option is useful to do a rewind with the server configuration file(aka postgresql.conf) located outside the data directory, which issomething that some Linux distributions and some HA tools like to relyon. As a result, this can simplify the logic around a rewind byavoiding the copy of such files before running pg_rewind.This option affects pg_rewind when it internally starts the targetcluster with some "postgres" commands, adding -c config_file=FILE to thecommand strings generated, when:- retrieving a restore_command using a "postgres -C" command for-c/--restore-target-wal.- forcing crash recovery once to get the cluster into a clean shutdownstate.Author: Gunnar "Nick" BluthReviewed-by: Michael Banck, Alexander Kukushkin, Michael Paquier,Alexander AlekseevDiscussion:https://postgr.es/m/7c59265d-ac50-b0aa-ca1e-65e8bd27642a@pro-open.de
1 parenta82a5ee commit0d5c387

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,21 @@ PostgreSQL documentation
241241
</listitem>
242242
</varlistentry>
243243

244+
<varlistentry>
245+
<term><option>--config-file=<replaceable class="parameter">filename</replaceable></option></term>
246+
<listitem>
247+
<para>
248+
Use the specified main server configuration file for the target
249+
cluster. This affects <application>pg_rewind</application> when
250+
it uses internally the <application>postgres</application> command
251+
for the rewind operation on this cluster (when retrieving
252+
<varname>restore_command</varname> with the option
253+
<option>-c/--restore-target-wal</option> and when forcing a
254+
completion of crash recovery).
255+
</para>
256+
</listitem>
257+
</varlistentry>
258+
244259
<varlistentry>
245260
<term><option>--debug</option></term>
246261
<listitem>

‎src/bin/pg_rewind/pg_rewind.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ char *datadir_target = NULL;
6161
char*datadir_source=NULL;
6262
char*connstr_source=NULL;
6363
char*restore_command=NULL;
64+
char*config_file=NULL;
6465

6566
staticbooldebug= false;
6667
boolshowprogress= false;
@@ -87,6 +88,8 @@ usage(const char *progname)
8788
printf(_("Options:\n"));
8889
printf(_(" -c, --restore-target-wal use restore_command in target configuration to\n"
8990
" retrieve WAL files from archives\n"));
91+
printf(_(" --config-file=FILENAME use specified main server configuration\n"));
92+
printf(_(" file when running target cluster\n"));
9093
printf(_(" -D, --target-pgdata=DIRECTORY existing data directory to modify\n"));
9194
printf(_(" --source-pgdata=DIRECTORY source data directory to synchronize with\n"));
9295
printf(_(" --source-server=CONNSTR source server to synchronize with\n"));
@@ -115,6 +118,7 @@ main(int argc, char **argv)
115118
{"source-pgdata",required_argument,NULL,1},
116119
{"source-server",required_argument,NULL,2},
117120
{"no-ensure-shutdown",no_argument,NULL,4},
121+
{"config-file",required_argument,NULL,5},
118122
{"version",no_argument,NULL,'V'},
119123
{"restore-target-wal",no_argument,NULL,'c'},
120124
{"dry-run",no_argument,NULL,'n'},
@@ -205,6 +209,10 @@ main(int argc, char **argv)
205209
case4:
206210
no_ensure_shutdown= true;
207211
break;
212+
213+
case5:
214+
config_file=pg_strdup(optarg);
215+
break;
208216
}
209217
}
210218

@@ -1058,6 +1066,13 @@ getRestoreCommand(const char *argv0)
10581066
appendPQExpBufferStr(postgres_cmd," -D ");
10591067
appendShellString(postgres_cmd,datadir_target);
10601068

1069+
/* add custom configuration file only if requested */
1070+
if (config_file!=NULL)
1071+
{
1072+
appendPQExpBufferStr(postgres_cmd," -c config_file=");
1073+
appendShellString(postgres_cmd,config_file);
1074+
}
1075+
10611076
/* add -C switch, for restore_command */
10621077
appendPQExpBufferStr(postgres_cmd," -C restore_command");
10631078

@@ -1136,6 +1151,13 @@ ensureCleanShutdown(const char *argv0)
11361151
appendPQExpBufferStr(postgres_cmd," --single -F -D ");
11371152
appendShellString(postgres_cmd,datadir_target);
11381153

1154+
/* add custom configuration file only if requested */
1155+
if (config_file!=NULL)
1156+
{
1157+
appendPQExpBufferStr(postgres_cmd," -c config_file=");
1158+
appendShellString(postgres_cmd,config_file);
1159+
}
1160+
11391161
/* finish with the database name, and a properly quoted redirection */
11401162
appendPQExpBufferStr(postgres_cmd," template1 < ");
11411163
appendShellString(postgres_cmd,DEVNULL);

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ sub run_pg_rewind
263263
"--debug",
264264
"--source-pgdata=$standby_pgdata",
265265
"--target-pgdata=$primary_pgdata",
266-
"--no-sync"
266+
"--no-sync",
267+
"--config-file",
268+
"$tmp_folder/primary-postgresql.conf.tmp"
267269
],
268270
'pg_rewind local');
269271
}
@@ -276,7 +278,8 @@ sub run_pg_rewind
276278
'pg_rewind',"--debug",
277279
"--source-server",$standby_connstr,
278280
"--target-pgdata=$primary_pgdata","--no-sync",
279-
"--write-recovery-conf"
281+
"--write-recovery-conf","--config-file",
282+
"$tmp_folder/primary-postgresql.conf.tmp"
280283
],
281284
'pg_rewind remote');
282285

@@ -323,7 +326,8 @@ sub run_pg_rewind
323326

324327
# Note the use of --no-ensure-shutdown here. WAL files are
325328
# gone in this mode and the primary has been stopped
326-
# gracefully already.
329+
# gracefully already. --config-file reuses the original
330+
# postgresql.conf as restore_command has been enabled above.
327331
command_ok(
328332
[
329333
'pg_rewind',
@@ -332,7 +336,9 @@ sub run_pg_rewind
332336
"--target-pgdata=$primary_pgdata",
333337
"--no-sync",
334338
"--no-ensure-shutdown",
335-
"--restore-target-wal"
339+
"--restore-target-wal",
340+
"--config-file",
341+
"$primary_pgdata/postgresql.conf"
336342
],
337343
'pg_rewind archive');
338344
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp