mirror of
https://github.com/postgres/postgres.git
synced 2025-12-16 16:42:29 +03:00
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 is something that some Linux distributions and some HA tools like to rely on. As a result, this can simplify the logic around a rewind by avoiding the copy of such files before running pg_rewind. This option affects pg_rewind when it internally starts the target cluster with some "postgres" commands, adding -c config_file=FILE to the command 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 shutdown state. Author: Gunnar "Nick" Bluth Reviewed-by: Michael Banck, Alexander Kukushkin, Michael Paquier, Alexander Alekseev Discussion: https://postgr.es/m/7c59265d-ac50-b0aa-ca1e-65e8bd27642a@pro-open.de
This commit is contained in:
@@ -61,6 +61,7 @@ char *datadir_target = NULL;
|
||||
char *datadir_source = NULL;
|
||||
char *connstr_source = NULL;
|
||||
char *restore_command = NULL;
|
||||
char *config_file = NULL;
|
||||
|
||||
static bool debug = false;
|
||||
bool showprogress = false;
|
||||
@@ -87,6 +88,8 @@ usage(const char *progname)
|
||||
printf(_("Options:\n"));
|
||||
printf(_(" -c, --restore-target-wal use restore_command in target configuration to\n"
|
||||
" retrieve WAL files from archives\n"));
|
||||
printf(_(" --config-file=FILENAME use specified main server configuration\n"));
|
||||
printf(_(" file when running target cluster\n"));
|
||||
printf(_(" -D, --target-pgdata=DIRECTORY existing data directory to modify\n"));
|
||||
printf(_(" --source-pgdata=DIRECTORY source data directory to synchronize with\n"));
|
||||
printf(_(" --source-server=CONNSTR source server to synchronize with\n"));
|
||||
@@ -115,6 +118,7 @@ main(int argc, char **argv)
|
||||
{"source-pgdata", required_argument, NULL, 1},
|
||||
{"source-server", required_argument, NULL, 2},
|
||||
{"no-ensure-shutdown", no_argument, NULL, 4},
|
||||
{"config-file", required_argument, NULL, 5},
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{"restore-target-wal", no_argument, NULL, 'c'},
|
||||
{"dry-run", no_argument, NULL, 'n'},
|
||||
@@ -205,6 +209,10 @@ main(int argc, char **argv)
|
||||
case 4:
|
||||
no_ensure_shutdown = true;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
config_file = pg_strdup(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1058,6 +1066,13 @@ getRestoreCommand(const char *argv0)
|
||||
appendPQExpBufferStr(postgres_cmd, " -D ");
|
||||
appendShellString(postgres_cmd, datadir_target);
|
||||
|
||||
/* add custom configuration file only if requested */
|
||||
if (config_file != NULL)
|
||||
{
|
||||
appendPQExpBufferStr(postgres_cmd, " -c config_file=");
|
||||
appendShellString(postgres_cmd, config_file);
|
||||
}
|
||||
|
||||
/* add -C switch, for restore_command */
|
||||
appendPQExpBufferStr(postgres_cmd, " -C restore_command");
|
||||
|
||||
@@ -1136,6 +1151,13 @@ ensureCleanShutdown(const char *argv0)
|
||||
appendPQExpBufferStr(postgres_cmd, " --single -F -D ");
|
||||
appendShellString(postgres_cmd, datadir_target);
|
||||
|
||||
/* add custom configuration file only if requested */
|
||||
if (config_file != NULL)
|
||||
{
|
||||
appendPQExpBufferStr(postgres_cmd, " -c config_file=");
|
||||
appendShellString(postgres_cmd, config_file);
|
||||
}
|
||||
|
||||
/* finish with the database name, and a properly quoted redirection */
|
||||
appendPQExpBufferStr(postgres_cmd, " template1 < ");
|
||||
appendShellString(postgres_cmd, DEVNULL);
|
||||
|
||||
Reference in New Issue
Block a user