{NULL, 0, NULL, 0}
}; int option; /* Command line option */ int optindex = 0; /* used by getopt_long */ int os_user_effective_id;
DataDirSyncMethod unused;
/* Process libpq env. variables; load values here for usage() output */
old_cluster.port = getenv("PGPORTOLD") ? atoi(getenv("PGPORTOLD")) : DEF_PGUPORT;
new_cluster.port = getenv("PGPORTNEW") ? atoi(getenv("PGPORTNEW")) : DEF_PGUPORT;
os_user_effective_id = get_user_info(&os_info.user); /* we override just the database user name; we got the OS id above */ if (getenv("PGUSER"))
{
pg_free(os_info.user); /* must save value, getenv()'s pointer is not stable */
os_info.user = pg_strdup(getenv("PGUSER"));
}
/* Allow help and version to be run as root, so do the test here. */ if (os_user_effective_id == 0)
pg_fatal("%s: cannot be run as root", os_info.progname);
if (!getcwd(cwd, MAXPGPATH))
pg_fatal("could not determine current directory");
canonicalize_path(cwd); if (path_is_prefix_of_path(new_cluster_pgdata, cwd))
pg_fatal("cannot run pg_upgrade from inside the new cluster data directory on Windows");
} #endif
}
staticvoid
usage(void)
{
printf(_("pg_upgrade upgrades a PostgreSQL cluster to a different major version.\n\n"));
printf(_("Usage:\n"));
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 (default\n" " same directory as pg_upgrade)\n"));
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"));
printf(_(" -j, --jobs=NUM number of simultaneous processes or threads to use\n"));
printf(_(" -k, --link link instead of copying files to new cluster\n"));
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
printf(_(" -o, --old-options=OPTIONS old cluster options to pass to the server\n"));
printf(_(" -O, --new-options=OPTIONS new cluster options to pass to the server\n"));
printf(_(" -p, --old-port=PORT old cluster port number (default %d)\n"), old_cluster.port);
printf(_(" -P, --new-port=PORT new cluster port number (default %d)\n"), new_cluster.port);
printf(_(" -r, --retain retain SQL and log files after success\n"));
printf(_(" -s, --socketdir=DIR socket directory to use (default current dir.)\n"));
printf(_(" -U, --username=NAME cluster superuser (default \"%s\")\n"), os_info.user);
printf(_(" -v, --verbose enable verbose internal logging\n"));
printf(_(" -V, --version display version information, then exit\n"));
printf(_(" --clone clone instead of copying files to new cluster\n"));
printf(_(" --copy copy files to new cluster (default)\n"));
printf(_(" --copy-file-range copy files to new cluster with copy_file_range\n"));
printf(_(" --no-statistics do not import statistics from old cluster\n"));
printf(_(" --set-char-signedness=OPTION set new cluster char signedness to \"signed\" or\n" " \"unsigned\"\n"));
printf(_(" --swap move data directories to new cluster\n"));
printf(_(" --sync-method=METHOD set method for syncing files to disk\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\n" "Before running pg_upgrade you must:\n" " create a new database cluster (using the new version of initdb)\n" " shutdown the postmaster servicing the old cluster\n" " shutdown the postmaster servicing the new cluster\n"));
printf(_("\n" "When you run pg_upgrade, you must provide the following information:\n" " the data directory for the old cluster (-d DATADIR)\n" " the data directory for the new cluster (-D DATADIR)\n" " the \"bin\" directory for the old version (-b BINDIR)\n" " the \"bin\" directory for the new version (-B BINDIR)\n"));
printf(_("\n" "For example:\n" " pg_upgrade -d oldCluster/data -D newCluster/data -b oldCluster/bin -B newCluster/bin\n" "or\n")); #ifndef WIN32
printf(_(" $ export PGDATAOLD=oldCluster/data\n" " $ export PGDATANEW=newCluster/data\n" " $ export PGBINOLD=oldCluster/bin\n" " $ export PGBINNEW=newCluster/bin\n" " $ pg_upgrade\n")); #else
printf(_(" C:\\> set PGDATAOLD=oldCluster/data\n" " C:\\> set PGDATANEW=newCluster/data\n" " C:\\> set PGBINOLD=oldCluster/bin\n" " C:\\> set PGBINNEW=newCluster/bin\n" " C:\\> pg_upgrade\n")); #endif
printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
}
if (!getcwd(cwd, MAXPGPATH))
pg_fatal("could not determine current directory");
*dirpath = pg_strdup(cwd);
} elseif (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.",
description, cmdLineOption, envVarName);
}
/* Initially assume config dir and data dir are the same */
cluster->pgconfig = pg_strdup(cluster->pgdata);
/* If there is no postgresql.conf, it can't be a config-only dir */
snprintf(filename, sizeof(filename), "%s/postgresql.conf", cluster->pgconfig); if ((fp = fopen(filename, "r")) == NULL) return;
fclose(fp);
/* If PG_VERSION exists, it can't be a config-only dir */
snprintf(filename, sizeof(filename), "%s/PG_VERSION", cluster->pgconfig); if ((fp = fopen(filename, "r")) != NULL)
{
fclose(fp); return;
}
/* Must be a configuration directory, so find the real data directory. */
if (cluster == &old_cluster)
prep_status("Finding the real data directory for the source cluster"); else
prep_status("Finding the real data directory for the target cluster");
if ((output = popen(cmd, "r")) == NULL ||
fgets(cmd_output, sizeof(cmd_output), output) == NULL)
pg_fatal("could not get data directory using %s: %m", cmd);
rc = pclose(output); if (rc != 0)
pg_fatal("could not get data directory using %s: %s",
cmd, wait_result_to_str(rc));
/* strip trailing newline and carriage return */
(void) pg_strip_crlf(cmd_output);
snprintf(filename, sizeof(filename), "%s/postmaster.pid",
cluster->pgdata); if ((fp = fopen(filename, "r")) == NULL)
pg_fatal("could not open file \"%s\": %m", filename);
for (lineno = 1;
lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
lineno++)
{ if (fgets(line, sizeof(line), fp) == NULL)
pg_fatal("could not read line %d from file \"%s\": %m",
lineno, filename);
/* potentially overwrite user-supplied value */ if (lineno == LOCK_FILE_LINE_PORT)
sscanf(line, "%hu", &old_cluster.port); if (lineno == LOCK_FILE_LINE_SOCKET_DIR)
{ /* strip trailing newline and carriage return */
cluster->sockdir = pg_strdup(line);
(void) pg_strip_crlf(cluster->sockdir);
}
}
fclose(fp);
/* warn of port number correction */ if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port)
pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu",
orig_port, cluster->port);
} #else/* WIN32 */
cluster->sockdir = NULL; #endif
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.45 Sekunden
(vorverarbeitet am 2026-08-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.