The attached patch adds a switch --no-instructions to initdb and
pg_upgrade, which prevents them from printing instructions about how to
start the cluster (initdb) or how to analyze and delete clusters
(pg_upgrade).
The use case for this is for example the debian or redhat package wrappers.
When these commands are run under those wrappers the printed instructions
are *wrong*. It's better in that case to exclude them, and let the wrapper
be responsible for printing the correct instructions.
I went with the name --no-instructions to have the same name for both
initdb and pg_upgrade. The downside is that "no-instructions" also causes
the scripts not to be written in pg_upgrade, which arguably is a different
thing. We could go with "--no-instructions" and "--no-scripts", but that
would leave the parameters different. I also considered "--no-next-step",
but that one didn't quite have the right ring to me. I'm happy for other
suggestions on the parameter names.
--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/>
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>
diff --git a/doc/src/sgml/ref/initdb.sgml b/doc/src/sgml/ref/initdb.sgml
index 385ac25150..995d78408e 100644
--- a/doc/src/sgml/ref/initdb.sgml
+++ b/doc/src/sgml/ref/initdb.sgml
@@ -275,6 +275,19 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--no-instructions</option></term>
+ <listitem>
+ <para>
+ By default, <command>initdb</command> will write instructions for how
+ to start the cluster at the end of its output. This option causes
+ those instructions to be left out. This is primarily intended for use
+ by tools that wrap <command>initdb</command> in platform specific
+ behavior, where those instructions are likely to be incorrect.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>--pwfile=<replaceable>filename</replaceable></option></term>
<listitem>
diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml
index b59c5697a3..b4d0a5e8f1 100644
--- a/doc/src/sgml/ref/pgupgrade.sgml
+++ b/doc/src/sgml/ref/pgupgrade.sgml
@@ -215,6 +215,20 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--no-instructions</option></term>
+ <listitem>
+ <para>
+ By default, <command>pg_upgrade</command> will write instructions and
+ scripts for how to analyze the new and delete the old cluster at the
+ end of its output. This option causes those scripts and instructions
+ to be left out. This is primarily intended for use by tools that wrap
+ <command>pg_upgrade</command> in platform specific behavior, where
+ those instructions are likely to be incorrect.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-?</option></term>
<term><option>--help</option></term>
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index ee3bfa82f4..e6b5200ba5 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -139,6 +139,7 @@ static const char *authmethodhost = NULL;
static const char *authmethodlocal = NULL;
static bool debug = false;
static bool noclean = false;
+static bool noinstructions = false;
static bool do_sync = true;
static bool sync_only = false;
static bool show_setting = false;
@@ -2294,6 +2295,7 @@ usage(const char *progname)
printf(_(" -L DIRECTORY where to find the input files\n"));
printf(_(" -n, --no-clean do not clean up after errors\n"));
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
+ printf(_(" --no-instructions don't print instructions for next steps\n"));
printf(_(" -s, --show show internal settings\n"));
printf(_(" -S, --sync-only only sync data directory\n"));
printf(_("\nOther options:\n"));
@@ -2953,6 +2955,7 @@ main(int argc, char *argv[])
{"no-clean", no_argument, NULL, 'n'},
{"nosync", no_argument, NULL, 'N'}, /* for backwards compatibility */
{"no-sync", no_argument, NULL, 'N'},
+ {"no-instructions", no_argument, NULL, 13},
{"sync-only", no_argument, NULL, 'S'},
{"waldir", required_argument, NULL, 'X'},
{"wal-segsize", required_argument, NULL, 12},
@@ -3093,6 +3096,9 @@ main(int argc, char *argv[])
case 12:
str_wal_segment_size_mb = pg_strdup(optarg);
break;
+ case 13:
+ noinstructions = true;
+ break;
case 'g':
SetDataDirectoryCreatePerm(PG_DIR_MODE_GROUP);
break;
@@ -3243,34 +3249,40 @@ main(int argc, char *argv[])
"--auth-local and --auth-host, the next time you run initdb.\n"));
}
- /*
- * Build up a shell command to tell the user how to start the server
- */
- start_db_cmd = createPQExpBuffer();
+ if (!noinstructions)
+ {
+ /*
+ * Build up a shell command to tell the user how to start the server
+ */
+ start_db_cmd = createPQExpBuffer();
+
+ /* Get directory specification used to start initdb ... */
+ strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
+ canonicalize_path(pg_ctl_path);
+ get_parent_directory(pg_ctl_path);
+ /* ... and tag on pg_ctl instead */
+ join_path_components(pg_ctl_path, pg_ctl_path, "pg_ctl");
- /* Get directory specification used to start initdb ... */
- strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path));
- canonicalize_path(pg_ctl_path);
- get_parent_directory(pg_ctl_path);
- /* ... and tag on pg_ctl instead */
- join_path_components(pg_ctl_path, pg_ctl_path, "pg_ctl");
+ /* path to pg_ctl, properly quoted */
+ appendShellString(start_db_cmd, pg_ctl_path);
- /* path to pg_ctl, properly quoted */
- appendShellString(start_db_cmd, pg_ctl_path);
+ /* add -D switch, with properly quoted data directory */
+ appendPQExpBufferStr(start_db_cmd, " -D ");
+ appendShellString(start_db_cmd, pgdata_native);
- /* add -D switch, with properly quoted data directory */
- appendPQExpBufferStr(start_db_cmd, " -D ");
- appendShellString(start_db_cmd, pgdata_native);
+ /* add suggested -l switch and "start" command */
+ /* translator: This is a placeholder in a shell command. */
+ appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
- /* add suggested -l switch and "start" command */
- /* translator: This is a placeholder in a shell command. */
- appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
+ printf(_("\nSuccess. You can now start the database server using:\n\n"
+ " %s\n\n"),
+ start_db_cmd->data);
- printf(_("\nSuccess. You can now start the database server using:\n\n"
- " %s\n\n"),
- start_db_cmd->data);
+ destroyPQExpBuffer(start_db_cmd);
+ }
+ else
+ printf(_("\nSuccess.\n"));
- destroyPQExpBuffer(start_db_cmd);
success = true;
return 0;
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index aca1ee8b48..21e8e0283f 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -56,6 +56,7 @@ parseCommandLine(int argc, char *argv[])
{"socketdir", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{"clone", no_argument, NULL, 1},
+ {"no-instructions", no_argument, NULL, 2},
{NULL, 0, NULL, 0}
};
@@ -67,6 +68,7 @@ parseCommandLine(int argc, char *argv[])
time_t run_time = time(NULL);
user_opts.transfer_mode = TRANSFER_MODE_COPY;
+ user_opts.noinstructions = false;
os_info.progname = get_progname(argv[0]);
@@ -203,6 +205,10 @@ parseCommandLine(int argc, char *argv[])
user_opts.transfer_mode = TRANSFER_MODE_CLONE;
break;
+ case 2:
+ user_opts.noinstructions = true;
+ break;
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
os_info.progname);
@@ -307,6 +313,7 @@ usage(void)
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(_(" --no-instructions don't print instructions for next steps\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\n"
"Before running pg_upgrade you must:\n"
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index 70194eb096..e5be7e4b75 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -176,8 +176,11 @@ main(int argc, char **argv)
new_cluster.pgdata);
check_ok();
- create_script_for_cluster_analyze(&analyze_script_file_name);
- create_script_for_old_cluster_deletion(&deletion_script_file_name);
+ if (!user_opts.noinstructions)
+ {
+ create_script_for_cluster_analyze(&analyze_script_file_name);
+ create_script_for_old_cluster_deletion(&deletion_script_file_name);
+ }
issue_warnings_and_set_wal_level();
@@ -186,8 +189,11 @@ main(int argc, char **argv)
"Upgrade Complete\n"
"----------------\n");
- output_completion_banner(analyze_script_file_name,
- deletion_script_file_name);
+ if (!user_opts.noinstructions)
+ {
+ output_completion_banner(analyze_script_file_name,
+ deletion_script_file_name);
+ }
pg_free(analyze_script_file_name);
pg_free(deletion_script_file_name);
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 8b90cefbe0..cedc500dd2 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -292,6 +292,7 @@ typedef struct
transferMode transfer_mode; /* copy files or link them? */
int jobs; /* number of processes/threads to use */
char *socketdir; /* directory to use for Unix sockets */
+ bool noinstructions; /* don't print instructions about next steps */
} UserOpts;
typedef struct