22static 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[] = {
71 int os_user_effective_id;
96 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
101 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
103 puts(
"pg_upgrade (PostgreSQL) " PG_VERSION);
109 if (os_user_effective_id == 0)
113 long_options, &optindex)) != -1)
177 pg_fatal(
"invalid old port number");
182 pg_fatal(
"invalid new port number");
230 pg_fatal(
"invalid argument for option %s",
"--set-char-signedness");
238 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"),
245 pg_fatal(
"too many command-line arguments (first is \"%s\")", argv[
optind]);
256 if (getenv(
"PGOPTIONS"))
259 getenv(
"PGOPTIONS"));
261 setenv(
"PGOPTIONS", pgoptions, 1);
269 "-b",
_(
"old cluster binaries reside"),
false);
271 "-B",
_(
"new cluster binaries reside"),
true);
273 "-d",
_(
"old cluster data resides"),
false);
275 "-D",
_(
"new cluster data resides"),
false);
277 "-s",
_(
"sockets will be created"),
false);
294 pg_fatal(
"could not determine current directory");
297 pg_fatal(
"cannot run pg_upgrade from inside the new cluster data directory on Windows");
306 printf(
_(
"pg_upgrade upgrades a PostgreSQL cluster to a different major version.\n\n"));
308 printf(
_(
" pg_upgrade [OPTION]...\n\n"));
310 printf(
_(
" -b, --old-bindir=BINDIR old cluster executable directory\n"));
311 printf(
_(
" -B, --new-bindir=BINDIR new cluster executable directory (default\n"
312 " same directory as pg_upgrade)\n"));
313 printf(
_(
" -c, --check check clusters only, don't change any data\n"));
314 printf(
_(
" -d, --old-datadir=DATADIR old cluster data directory\n"));
315 printf(
_(
" -D, --new-datadir=DATADIR new cluster data directory\n"));
316 printf(
_(
" -j, --jobs=NUM number of simultaneous processes or threads to use\n"));
317 printf(
_(
" -k, --link link instead of copying files to new cluster\n"));
318 printf(
_(
" -N, --no-sync do not wait for changes to be written safely to disk\n"));
319 printf(
_(
" -o, --old-options=OPTIONS old cluster options to pass to the server\n"));
320 printf(
_(
" -O, --new-options=OPTIONS new cluster options to pass to the server\n"));
323 printf(
_(
" -r, --retain retain SQL and log files after success\n"));
324 printf(
_(
" -s, --socketdir=DIR socket directory to use (default current dir.)\n"));
326 printf(
_(
" -v, --verbose enable verbose internal logging\n"));
327 printf(
_(
" -V, --version display version information, then exit\n"));
328 printf(
_(
" --clone clone instead of copying files to new cluster\n"));
329 printf(
_(
" --copy copy files to new cluster (default)\n"));
330 printf(
_(
" --copy-file-range copy files to new cluster with copy_file_range\n"));
331 printf(
_(
" --no-statistics do not import statistics from old cluster\n"));
332 printf(
_(
" --set-char-signedness=OPTION set new cluster char signedness to \"signed\" or\n"
334 printf(
_(
" --swap move data directories to new cluster\n"));
335 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
336 printf(
_(
" -?, --help show this help, then exit\n"));
338 "Before running pg_upgrade you must:\n"
339 " create a new database cluster (using the new version of initdb)\n"
340 " shutdown the postmaster servicing the old cluster\n"
341 " shutdown the postmaster servicing the new cluster\n"));
343 "When you run pg_upgrade, you must provide the following information:\n"
344 " the data directory for the old cluster (-d DATADIR)\n"
345 " the data directory for the new cluster (-D DATADIR)\n"
346 " the \"bin\" directory for the old version (-b BINDIR)\n"
347 " the \"bin\" directory for the new version (-B BINDIR)\n"));
350 " pg_upgrade -d oldCluster/data -D newCluster/data -b oldCluster/bin -B newCluster/bin\n"
353 printf(
_(
" $ export PGDATAOLD=oldCluster/data\n"
354 " $ export PGDATANEW=newCluster/data\n"
355 " $ export PGBINOLD=oldCluster/bin\n"
356 " $ export PGBINNEW=newCluster/bin\n"
359 printf(
_(
" C:\\> set PGDATAOLD=oldCluster/data\n"
360 " C:\\> set PGDATANEW=newCluster/data\n"
361 " C:\\> set PGBINOLD=oldCluster/bin\n"
362 " C:\\> set PGBINNEW=newCluster/bin\n"
363 " C:\\> pg_upgrade\n"));
365 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
366 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
386 const char *cmdLineOption,
const char *
description,
389 if (*dirpath == NULL || strlen(*dirpath) == 0)
393 if ((envVar = getenv(envVarName)) && strlen(envVar))
400 pg_fatal(
"could not determine current directory");
406 pg_fatal(
"You must identify the directory where the %s.\n"
407 "Please use the %s command-line option or the %s environment variable.",
444 if ((fp = fopen(
filename,
"r")) == NULL)
450 if ((fp = fopen(
filename,
"r")) != NULL)
459 prep_status(
"Finding the real data directory for the source cluster");
461 prep_status(
"Finding the real data directory for the target cluster");
468 snprintf(cmd,
sizeof(cmd),
"\"%s/postgres\" -D \"%s\" -C data_directory",
472 if ((
output = popen(cmd,
"r")) == NULL ||
473 fgets(cmd_output,
sizeof(cmd_output),
output) == NULL)
474 pg_fatal(
"could not get data directory using %s: %m", cmd);
478 pg_fatal(
"could not get data directory using %s: %s",
510 unsigned short orig_port =
cluster->port;
518 if ((fp = fopen(
filename,
"r")) == NULL)
525 if (fgets(line,
sizeof(line), fp) == NULL)
526 pg_fatal(
"could not read line %d from file \"%s\": %m",
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
#define fprintf(file, fmt, msg)
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)
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)
int pg_strcasecmp(const char *s1, const char *s2)
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)