22 static void usage(
void);
24 const char *envVarName,
bool useCwd,
27 #define FIX_DEFAULT_READ_ONLY "-c default_transaction_read_only=false"
41 static struct option long_options[] = {
68 int os_user_effective_id;
91 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
96 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
98 puts(
"pg_upgrade (PostgreSQL) " PG_VERSION);
104 if (os_user_effective_id == 0)
108 long_options, &optindex)) != -1)
172 pg_fatal(
"invalid old port number");
177 pg_fatal(
"invalid new port number");
216 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"),
223 pg_fatal(
"too many command-line arguments (first is \"%s\")", argv[
optind]);
234 if (getenv(
"PGOPTIONS"))
237 getenv(
"PGOPTIONS"));
239 setenv(
"PGOPTIONS", pgoptions, 1);
247 "-b",
_(
"old cluster binaries reside"),
false);
249 "-B",
_(
"new cluster binaries reside"),
true);
251 "-d",
_(
"old cluster data resides"),
false);
253 "-D",
_(
"new cluster data resides"),
false);
255 "-s",
_(
"sockets will be created"),
false);
272 pg_fatal(
"could not determine current directory");
275 pg_fatal(
"cannot run pg_upgrade from inside the new cluster data directory on Windows");
284 printf(
_(
"pg_upgrade upgrades a PostgreSQL cluster to a different major version.\n\n"));
286 printf(
_(
" pg_upgrade [OPTION]...\n\n"));
288 printf(
_(
" -b, --old-bindir=BINDIR old cluster executable directory\n"));
289 printf(
_(
" -B, --new-bindir=BINDIR new cluster executable directory (default\n"
290 " same directory as pg_upgrade)\n"));
291 printf(
_(
" -c, --check check clusters only, don't change any data\n"));
292 printf(
_(
" -d, --old-datadir=DATADIR old cluster data directory\n"));
293 printf(
_(
" -D, --new-datadir=DATADIR new cluster data directory\n"));
294 printf(
_(
" -j, --jobs=NUM number of simultaneous processes or threads to use\n"));
295 printf(
_(
" -k, --link link instead of copying files to new cluster\n"));
296 printf(
_(
" -N, --no-sync do not wait for changes to be written safely to disk\n"));
297 printf(
_(
" -o, --old-options=OPTIONS old cluster options to pass to the server\n"));
298 printf(
_(
" -O, --new-options=OPTIONS new cluster options to pass to the server\n"));
301 printf(
_(
" -r, --retain retain SQL and log files after success\n"));
302 printf(
_(
" -s, --socketdir=DIR socket directory to use (default current dir.)\n"));
304 printf(
_(
" -v, --verbose enable verbose internal logging\n"));
305 printf(
_(
" -V, --version display version information, then exit\n"));
306 printf(
_(
" --clone clone instead of copying files to new cluster\n"));
307 printf(
_(
" --copy copy files to new cluster (default)\n"));
308 printf(
_(
" --copy-file-range copy files to new cluster with copy_file_range\n"));
309 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
310 printf(
_(
" -?, --help show this help, then exit\n"));
312 "Before running pg_upgrade you must:\n"
313 " create a new database cluster (using the new version of initdb)\n"
314 " shutdown the postmaster servicing the old cluster\n"
315 " shutdown the postmaster servicing the new cluster\n"));
317 "When you run pg_upgrade, you must provide the following information:\n"
318 " the data directory for the old cluster (-d DATADIR)\n"
319 " the data directory for the new cluster (-D DATADIR)\n"
320 " the \"bin\" directory for the old version (-b BINDIR)\n"
321 " the \"bin\" directory for the new version (-B BINDIR)\n"));
324 " pg_upgrade -d oldCluster/data -D newCluster/data -b oldCluster/bin -B newCluster/bin\n"
327 printf(
_(
" $ export PGDATAOLD=oldCluster/data\n"
328 " $ export PGDATANEW=newCluster/data\n"
329 " $ export PGBINOLD=oldCluster/bin\n"
330 " $ export PGBINNEW=newCluster/bin\n"
333 printf(
_(
" C:\\> set PGDATAOLD=oldCluster/data\n"
334 " C:\\> set PGDATANEW=newCluster/data\n"
335 " C:\\> set PGBINOLD=oldCluster/bin\n"
336 " C:\\> set PGBINNEW=newCluster/bin\n"
337 " C:\\> pg_upgrade\n"));
339 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
340 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
360 const char *cmdLineOption,
const char *
description,
363 if (*dirpath == NULL || strlen(*dirpath) == 0)
367 if ((envVar = getenv(envVarName)) && strlen(envVar))
374 pg_fatal(
"could not determine current directory");
380 pg_fatal(
"You must identify the directory where the %s.\n"
381 "Please use the %s command-line option or the %s environment variable.",
418 if ((fp = fopen(
filename,
"r")) == NULL)
424 if ((fp = fopen(
filename,
"r")) != NULL)
433 prep_status(
"Finding the real data directory for the source cluster");
435 prep_status(
"Finding the real data directory for the target cluster");
442 snprintf(cmd,
sizeof(cmd),
"\"%s/postgres\" -D \"%s\" -C data_directory",
446 if ((
output = popen(cmd,
"r")) == NULL ||
447 fgets(cmd_output,
sizeof(cmd_output),
output) == NULL)
448 pg_fatal(
"could not get data directory using %s: %m", cmd);
452 pg_fatal(
"could not get data directory using %s: %s",
484 unsigned short orig_port =
cluster->port;
492 if ((fp = fopen(
filename,
"r")) == NULL)
499 if (fgets(line,
sizeof(line), fp) == NULL)
500 pg_fatal(
"could not read line %d from file \"%s\": %m",
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
char * pg_strdup(const char *in)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
static void check_ok(void)
static void const char fflush(stdout)
void pfree(void *pointer)
bool parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
PGDLLIMPORT char * optarg
int get_user_info(char **user_name_p)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
@ TRANSFER_MODE_COPY_FILE_RANGE
void prep_status(const char *fmt,...) pg_attribute_printf(1
#define LOCK_FILE_LINE_PORT
#define LOCK_FILE_LINE_SOCKET_DIR
bool path_is_prefix_of_path(const char *path1, const char *path2)
void canonicalize_path(char *path)
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
char * psprintf(const char *fmt,...)
#define FIX_DEFAULT_READ_ONLY
void adjust_data_dir(ClusterInfo *cluster)
void parseCommandLine(int argc, char *argv[])
void get_sock_dir(ClusterInfo *cluster)
static void check_required_directory(char **dirpath, const char *envVarName, bool useCwd, const char *cmdLineOption, const char *description, bool missingOk)
int pg_strip_crlf(char *str)
transferMode transfer_mode
char * wait_result_to_str(int exitstatus)