diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c index 3ab1b5cc70..9892b9764d 100644 --- a/contrib/pg_upgrade/option.c +++ b/contrib/pg_upgrade/option.c @@ -39,6 +39,8 @@ parseCommandLine(int argc, char *argv[]) {"new-datadir", required_argument, NULL, 'D'}, {"old-bindir", required_argument, NULL, 'b'}, {"new-bindir", required_argument, NULL, 'B'}, + {"old-options", required_argument, NULL, 'o'}, + {"new-options", required_argument, NULL, 'O'}, {"old-port", required_argument, NULL, 'p'}, {"new-port", required_argument, NULL, 'P'}, @@ -93,7 +95,7 @@ parseCommandLine(int argc, char *argv[]) getcwd(os_info.cwd, MAXPGPATH); - while ((option = getopt_long(argc, argv, "d:D:b:B:cgG:kl:p:P:u:v", + while ((option = getopt_long(argc, argv, "d:D:b:B:cgG:kl:o:O:p:P:u:v", long_options, &optindex)) != -1) { switch (option) @@ -141,6 +143,19 @@ parseCommandLine(int argc, char *argv[]) log_opts.filename = pg_strdup(optarg); break; + case 'o': + old_cluster.pgopts = pg_strdup(optarg); + break; + + case 'O': + new_cluster.pgopts = pg_strdup(optarg); + break; + + /* + * Someday, the port number option could be removed and + * passed using -o/-O, but that requires postmaster -C + * to be supported on all old/new versions. + */ case 'p': if ((old_cluster.port = atoi(optarg)) <= 0) { @@ -242,6 +257,8 @@ Options:\n\ -G, --debugfile=FILENAME output debugging activity to file\n\ -k, --link link instead of copying files to new cluster\n\ -l, --logfile=FILENAME log session activity to file\n\ + -o, --old-options=OPTIONS old cluster options to pass to the server\n\ + -O, --new-options=OPTIONS new cluster options to pass to the server\n\ -p, --old-port=OLDPORT old cluster port number (default %d)\n\ -P, --new-port=NEWPORT new cluster port number (default %d)\n\ -u, --user=NAME clusters superuser (default \"%s\")\n\ diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h index 0fb16ed764..b7e4ea5127 100644 --- a/contrib/pg_upgrade/pg_upgrade.h +++ b/contrib/pg_upgrade/pg_upgrade.h @@ -189,6 +189,7 @@ typedef struct char *pgdata; /* pathname for cluster's $PGDATA directory */ char *pgconfig; /* pathname for cluster's config file directory */ char *bindir; /* pathname for cluster's executable directory */ + char *pgopts; /* options to pass to the server, like pg_ctl -o */ unsigned short port; /* port number where postmaster is waiting */ uint32 major_version; /* PG_VERSION of cluster */ char major_version_str[64]; /* string PG_VERSION of cluster */ diff --git a/contrib/pg_upgrade/server.c b/contrib/pg_upgrade/server.c index d512ef3d4f..9c4f2d6fc3 100644 --- a/contrib/pg_upgrade/server.c +++ b/contrib/pg_upgrade/server.c @@ -168,12 +168,12 @@ start_postmaster(ClusterInfo *cluster) */ snprintf(cmd, sizeof(cmd), SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" " - "-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE, + "-o \"-p %d %s %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE, cluster->bindir, log_opts.filename2, cluster->pgconfig, cluster->port, (cluster->controldata.cat_ver >= BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ? "-b" : "-c autovacuum=off -c autovacuum_freeze_max_age=2000000000", - log_opts.filename2); + cluster->pgopts ? cluster->pgopts : "", log_opts.filename2); /* * Don't throw an error right away, let connecting throw the error because @@ -207,27 +207,21 @@ void stop_postmaster(bool fast) { char cmd[MAXPGPATH]; - const char *bindir; - const char *configdir; + ClusterInfo *cluster; if (os_info.running_cluster == &old_cluster) - { - bindir = old_cluster.bindir; - configdir = old_cluster.pgconfig; - } + cluster = &old_cluster; else if (os_info.running_cluster == &new_cluster) - { - bindir = new_cluster.bindir; - configdir = new_cluster.pgconfig; - } + cluster = &new_cluster; else - return; /* no cluster running */ + return; /* no cluster running */ snprintf(cmd, sizeof(cmd), - SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" %s stop >> " - "\"%s\" 2>&1" SYSTEMQUOTE, - bindir, log_opts.filename2, configdir, fast ? "-m fast" : "", - log_opts.filename2); + SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" -o \"%s\" " + "%s stop >> \"%s\" 2>&1" SYSTEMQUOTE, + cluster->bindir, log_opts.filename2, cluster->pgconfig, + cluster->pgopts ? cluster->pgopts : "", + fast ? "-m fast" : "", log_opts.filename2); exec_prog(fast ? false : true, "%s", cmd); diff --git a/doc/src/sgml/pgupgrade.sgml b/doc/src/sgml/pgupgrade.sgml index 0d084243a8..460d06b6e0 100644 --- a/doc/src/sgml/pgupgrade.sgml +++ b/doc/src/sgml/pgupgrade.sgml @@ -114,6 +114,20 @@ log session activity to file + + options + options + options to be passed directly to the + old postgres command + + + + options + options + options to be passed directly to the + new postgres command + + old_port_number old_portnum @@ -559,6 +573,14 @@ psql --username postgres --file script.sql postgres insert dummy data, and upgrade that. + + If you are upgrading a pre-PostgreSQL 9.2 cluster + that uses a configuration-file-only directory, you must pass the + real data directory location to pg_upgrade, and + pass the configuration directory location to the server, e.g. + -d /real-data-directory -o '-D /configuration-directory'. + + If you want to use link mode and you don't want your old cluster to be modified when the new cluster is started, make a copy of the