diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c index 3ab1b5cc704ca8da3b1bb77003c9f7f6d485deb3..9892b9764df24d7406313b514863692fa4ddfc44 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 0fb16ed7646f16335d7cc3faad88487e166d615a..b7e4ea5127ffe98813b56bfd5f9f194d1a736004 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 d512ef3d4fe977e8950dc5a3779ec3d4bea33d2b..9c4f2d6fc3fd6858bca5fcd805c676cafde94e68 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 0d084243a86d22c9ab9319537b59bfa435885c78..460d06b6e031f748c2396cf0be3cb3723e0c5dfc 100644 --- a/doc/src/sgml/pgupgrade.sgml +++ b/doc/src/sgml/pgupgrade.sgml @@ -114,6 +114,20 @@ <listitem><para>log session activity to file</para></listitem> </varlistentry> + <varlistentry> + <term><option>-o</option> <replaceable class="parameter">options</replaceable></term> + <term><option>--old-options</option> <replaceable class="parameter">options</replaceable></term> + <listitem><para>options to be passed directly to the + old <command>postgres</command> command</para></listitem> + </varlistentry> + + <varlistentry> + <term><option>-O</option> <replaceable class="parameter">options</replaceable></term> + <term><option>--new-options</option> <replaceable class="parameter">options</replaceable></term> + <listitem><para>options to be passed directly to the + new <command>postgres</command> command</para></listitem> + </varlistentry> + <varlistentry> <term><option>-p</option> <replaceable>old_port_number</></term> <term><option>--old-port=</option><replaceable>old_portnum</></term> @@ -559,6 +573,14 @@ psql --username postgres --file script.sql postgres insert dummy data, and upgrade that. </para> + <para> + If you are upgrading a pre-<productname>PostgreSQL</> 9.2 cluster + that uses a configuration-file-only directory, you must pass the + real data directory location to <application>pg_upgrade</>, and + pass the configuration directory location to the server, e.g. + <literal>-d /real-data-directory -o '-D /configuration-directory'</>. + </para> + <para> 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