In pg_upgrade, add -o/-O options to pass parameters to the servers, and

document its use for config-only directory installs.
This commit is contained in:
Bruce Momjian 2011-10-10 07:43:28 -04:00
parent c0f03aae04
commit 0dc3f57ba0
4 changed files with 52 additions and 18 deletions

View File

@ -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\

View File

@ -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 */

View File

@ -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);

View File

@ -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