22 static void usage(
void);
24 const char *envVarName,
bool useCwd,
25 const char *cmdLineOption,
const char *description,
27 #define FIX_DEFAULT_READ_ONLY "-c default_transaction_read_only=false" 41 static struct option long_options[] = {
59 {
"index-collation-versions-unknown",
no_argument, NULL, 2},
65 int os_user_effective_id;
68 time_t run_time = time(NULL);
89 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
94 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
96 puts(
"pg_upgrade (PostgreSQL) " PG_VERSION);
102 if (os_user_effective_id == 0)
105 while ((option =
getopt_long(argc, argv,
"d:D:b:B:cj:ko:O:p:P:rs:U:v",
106 long_options, &optindex)) != -1)
119 user_opts.
check =
true;
171 pg_fatal(
"invalid old port number\n");
176 pg_fatal(
"invalid new port number\n");
212 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"),
219 pg_fatal(
"too many command-line arguments (first is \"%s\")\n", argv[
optind]);
228 for (filename =
output_files; *filename != NULL; filename++)
230 if ((fp =
fopen_priv(*filename,
"a")) == NULL)
231 pg_fatal(
"could not write to log file \"%s\": %m\n", *filename);
235 "-----------------------------------------------------------------\n" 236 " pg_upgrade run on %s" 237 "-----------------------------------------------------------------\n\n",
243 if (getenv(
"PGOPTIONS"))
246 getenv(
"PGOPTIONS"));
248 setenv(
"PGOPTIONS", pgoptions, 1);
256 "-b",
_(
"old cluster binaries reside"),
false);
258 "-B",
_(
"new cluster binaries reside"),
true);
260 "-d",
_(
"old cluster data resides"),
false);
262 "-D",
_(
"new cluster data resides"),
false);
264 "-s",
_(
"sockets will be created"),
false);
281 pg_fatal(
"could not determine current directory\n");
284 pg_fatal(
"cannot run pg_upgrade from inside the new cluster data directory on Windows\n");
293 printf(
_(
"pg_upgrade upgrades a PostgreSQL cluster to a different major version.\n\n"));
295 printf(
_(
" pg_upgrade [OPTION]...\n\n"));
297 printf(
_(
" -b, --old-bindir=BINDIR old cluster executable directory\n"));
298 printf(
_(
" -B, --new-bindir=BINDIR new cluster executable directory (default\n" 299 " same directory as pg_upgrade)\n"));
300 printf(
_(
" -c, --check check clusters only, don't change any data\n"));
301 printf(
_(
" -d, --old-datadir=DATADIR old cluster data directory\n"));
302 printf(
_(
" -D, --new-datadir=DATADIR new cluster data directory\n"));
303 printf(
_(
" -j, --jobs=NUM number of simultaneous processes or threads to use\n"));
304 printf(
_(
" -k, --link link instead of copying files to new cluster\n"));
305 printf(
_(
" -o, --old-options=OPTIONS old cluster options to pass to the server\n"));
306 printf(
_(
" -O, --new-options=OPTIONS new cluster options to pass to the server\n"));
309 printf(
_(
" -r, --retain retain SQL and log files after success\n"));
310 printf(
_(
" -s, --socketdir=DIR socket directory to use (default current dir.)\n"));
312 printf(
_(
" -v, --verbose enable verbose internal logging\n"));
313 printf(
_(
" -V, --version display version information, then exit\n"));
314 printf(
_(
" --clone clone instead of copying files to new cluster\n"));
315 printf(
_(
" --index-collation-versions-unknown\n" 316 " mark text indexes as needing to be rebuilt\n"));
317 printf(
_(
" -?, --help show this help, then exit\n"));
319 "Before running pg_upgrade you must:\n" 320 " create a new database cluster (using the new version of initdb)\n" 321 " shutdown the postmaster servicing the old cluster\n" 322 " shutdown the postmaster servicing the new cluster\n"));
324 "When you run pg_upgrade, you must provide the following information:\n" 325 " the data directory for the old cluster (-d DATADIR)\n" 326 " the data directory for the new cluster (-D DATADIR)\n" 327 " the \"bin\" directory for the old version (-b BINDIR)\n" 328 " the \"bin\" directory for the new version (-B BINDIR)\n"));
331 " pg_upgrade -d oldCluster/data -D newCluster/data -b oldCluster/bin -B newCluster/bin\n" 334 printf(
_(
" $ export PGDATAOLD=oldCluster/data\n" 335 " $ export PGDATANEW=newCluster/data\n" 336 " $ export PGBINOLD=oldCluster/bin\n" 337 " $ export PGBINNEW=newCluster/bin\n" 340 printf(
_(
" C:\\> set PGDATAOLD=oldCluster/data\n" 341 " C:\\> set PGDATANEW=newCluster/data\n" 342 " C:\\> set PGBINOLD=oldCluster/bin\n" 343 " C:\\> set PGBINNEW=newCluster/bin\n" 344 " C:\\> pg_upgrade\n"));
346 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
347 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
367 const char *cmdLineOption,
const char *description,
370 if (*dirpath == NULL || strlen(*dirpath) == 0)
374 if ((envVar = getenv(envVarName)) && strlen(envVar))
381 pg_fatal(
"could not determine current directory\n");
387 pg_fatal(
"You must identify the directory where the %s.\n" 388 "Please use the %s command-line option or the %s environment variable.\n",
389 description, cmdLineOption, envVarName);
423 snprintf(filename,
sizeof(filename),
"%s/postgresql.conf", cluster->
pgconfig);
424 if ((fp = fopen(filename,
"r")) == NULL)
430 if ((fp = fopen(filename,
"r")) != NULL)
439 prep_status(
"Finding the real data directory for the source cluster");
441 prep_status(
"Finding the real data directory for the target cluster");
448 snprintf(cmd,
sizeof(cmd),
"\"%s/postgres\" -D \"%s\" -C data_directory",
451 if ((output = popen(cmd,
"r")) == NULL ||
452 fgets(cmd_output,
sizeof(cmd_output), output) == NULL)
453 pg_fatal(
"could not get data directory using %s: %s\n",
478 #if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32) 495 unsigned short orig_port = cluster->
port;
501 snprintf(filename,
sizeof(filename),
"%s/postmaster.pid",
503 if ((fp = fopen(filename,
"r")) == NULL)
504 pg_fatal(
"could not open file \"%s\": %s\n",
511 if (fgets(line,
sizeof(line), fp) == NULL)
512 pg_fatal(
"could not read line %d from file \"%s\": %s\n",
530 orig_port, cluster->
port);
void parseCommandLine(int argc, char *argv[])
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
int pg_strip_crlf(char *str)
void get_sock_dir(ClusterInfo *cluster, bool live_check)
const char * get_progname(const char *argv0)
static void output(uint64 loop_count)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
bool path_is_prefix_of_path(const char *path1, const char *path2)
char * psprintf(const char *fmt,...)
int get_user_info(char **user_name_p)
#define FIX_DEFAULT_READ_ONLY
#define GET_MAJOR_VERSION(v)
void canonicalize_path(char *path)
static void check_required_directory(char **dirpath, const char *envVarName, bool useCwd, const char *cmdLineOption, const char *description, bool missingOk)
#define required_argument
void pfree(void *pointer)
#define LOCK_FILE_LINE_SOCKET_DIR
void prep_status(const char *fmt,...) pg_attribute_printf(1
char * pg_strdup(const char *in)
void adjust_data_dir(ClusterInfo *cluster)
static void check_ok(void)
transferMode transfer_mode
#define INTERNAL_LOG_FILE
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
size_t strlcpy(char *dst, const char *src, size_t siz)
#define LOCK_FILE_LINE_PORT
#define fopen_priv(path, mode)