static void usage(void);
static void check_required_directory(char **dirpath,
const char *envVarName, bool useCwd,
- const char *cmdLineOption, const char *description);
+ const char *cmdLineOption, const char *description,
+ bool missingOk);
#define FIX_DEFAULT_READ_ONLY "-c default_transaction_read_only=false"
/* Get values from env if not already set */
check_required_directory(&old_cluster.bindir, "PGBINOLD", false,
- "-b", _("old cluster binaries reside"));
+ "-b", _("old cluster binaries reside"), false);
check_required_directory(&new_cluster.bindir, "PGBINNEW", false,
- "-B", _("new cluster binaries reside"));
+ "-B", _("new cluster binaries reside"), true);
check_required_directory(&old_cluster.pgdata, "PGDATAOLD", false,
- "-d", _("old cluster data resides"));
+ "-d", _("old cluster data resides"), false);
check_required_directory(&new_cluster.pgdata, "PGDATANEW", false,
- "-D", _("new cluster data resides"));
+ "-D", _("new cluster data resides"), false);
check_required_directory(&user_opts.socketdir, "PGSOCKETDIR", true,
- "-s", _("sockets will be created"));
+ "-s", _("sockets will be created"), false);
#ifdef WIN32
printf(_(" pg_upgrade [OPTION]...\n\n"));
printf(_("Options:\n"));
printf(_(" -b, --old-bindir=BINDIR old cluster executable directory\n"));
- printf(_(" -B, --new-bindir=BINDIR new cluster executable directory\n"));
+ printf(_(" -B, --new-bindir=BINDIR new cluster executable directory (default\n"
+ " same directory as pg_upgrade)"));
printf(_(" -c, --check check clusters only, don't change any data\n"));
printf(_(" -d, --old-datadir=DATADIR old cluster data directory\n"));
printf(_(" -D, --new-datadir=DATADIR new cluster data directory\n"));
* useCwd - true if OK to default to CWD
* cmdLineOption - the command line option for this directory
* description - a description of this directory option
+ * missingOk - true if OK that both dirpath and envVarName are not existing
*
* We use the last two arguments to construct a meaningful error message if the
* user hasn't provided the required directory name.
*/
static void
check_required_directory(char **dirpath, const char *envVarName, bool useCwd,
- const char *cmdLineOption, const char *description)
+ const char *cmdLineOption, const char *description,
+ bool missingOk)
{
if (*dirpath == NULL || strlen(*dirpath) == 0)
{
pg_fatal("could not determine current directory\n");
*dirpath = pg_strdup(cwd);
}
+ else if (missingOk)
+ return;
else
pg_fatal("You must identify the directory where the %s.\n"
"Please use the %s command-line option or the %s environment variable.\n",
static void
setup(char *argv0, bool *live_check)
{
- char exec_path[MAXPGPATH]; /* full path to my executable */
-
/*
* make sure the user has a clean environment, otherwise, we may confuse
* libpq when we connect to one (or both) of the servers.
*/
check_pghost_envvar();
+ /*
+ * In case the user hasn't specified the directory for the new binaries
+ * with -B, default to using the path of the currently executed pg_upgrade
+ * binary.
+ */
+ if (!new_cluster.bindir)
+ {
+ char exec_path[MAXPGPATH];
+
+ if (find_my_exec(argv0, exec_path) < 0)
+ pg_fatal("%s: could not find own program executable\n", argv0);
+ /* Trim off program name and keep just path */
+ *last_dir_separator(exec_path) = '\0';
+ canonicalize_path(exec_path);
+ new_cluster.bindir = pg_strdup(exec_path);
+ }
+
verify_directories();
/* no postmasters should be running, except for a live check */
pg_fatal("There seems to be a postmaster servicing the new cluster.\n"
"Please shutdown that postmaster and try again.\n");
}
-
- /* get path to pg_upgrade executable */
- if (find_my_exec(argv0, exec_path) < 0)
- pg_fatal("%s: could not find own program executable\n", argv0);
-
- /* Trim off program name and keep just path */
- *last_dir_separator(exec_path) = '\0';
- canonicalize_path(exec_path);
- os_info.exec_path = pg_strdup(exec_path);
}