pg_ctl: Change default to wait for all actions

The different actions in pg_ctl had different defaults for -w and -W,
mostly for historical reasons.  Most users will want the -w behavior, so
make that the default.

Remove the -w option in most example and test code, so avoid confusion
and reduce verbosity.  pg_upgrade is not touched, so it can continue to
work with older installations.

Reviewed-by: Beena Emerson <memissemerson@gmail.com>
Reviewed-by: Ryan Murphy <ryanfmurphy@gmail.com>
This commit is contained in:
Peter Eisentraut 2017-01-13 12:00:00 -05:00
parent e574f15d62
commit 05cd12ed5b
10 changed files with 49 additions and 61 deletions

View File

@ -28,8 +28,7 @@ PGLOG="$PGDATA/serverlog"
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# What to use to start up the postmaster. (If you want the script to wait
# until the server has started, you could use "pg_ctl start -w" here.
# But without -w, pg_ctl adds no value.)
# until the server has started, you could use "pg_ctl start" here.)
DAEMON="$prefix/bin/postmaster"
# What to use to shut down the postmaster
@ -51,7 +50,7 @@ case $1 in
su -l $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
;;
restart)
su -l $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -w"
su -l $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
su -l $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
;;
status)

View File

@ -60,8 +60,7 @@ PGLOG="$PGDATA/serverlog"
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# What to use to start up the postmaster. (If you want the script to wait
# until the server has started, you could use "pg_ctl start -w" here.
# But without -w, pg_ctl adds no value.)
# until the server has started, you could use "pg_ctl start" here.)
DAEMON="$prefix/bin/postmaster"
# What to use to shut down the postmaster
@ -102,7 +101,7 @@ case $1 in
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -w"
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"

View File

@ -65,8 +65,7 @@ ROTATESEC="604800"
PATH="$prefix/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
# What to use to start up the postmaster. (If you want the script to wait
# until the server has started, you could use "pg_ctl start -w" here.
# But without -w, pg_ctl adds no value.)
# until the server has started, you could use "pg_ctl start" here.)
DAEMON="$prefix/bin/postmaster"
# What to use to shut down the postmaster

View File

@ -31,7 +31,7 @@ PostgreSQL documentation
<cmdsynopsis>
<command>pg_ctl</command>
<arg choice="plain"><option>start</option></arg>
<arg choice="opt"><option>-w</option></arg>
<arg choice="opt"><option>-W</option></arg>
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg>
<arg choice="opt"><option>-s</option></arg>
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg>
@ -60,7 +60,7 @@ PostgreSQL documentation
<cmdsynopsis>
<command>pg_ctl</command>
<arg choice="plain"><option>restart</option></arg>
<arg choice="opt"><option>-w</option></arg>
<arg choice="opt"><option>-W</option></arg>
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg>
<arg choice="opt"><option>-s</option></arg>
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg>
@ -91,7 +91,7 @@ PostgreSQL documentation
<cmdsynopsis>
<command>pg_ctl</command>
<arg choice="plain"><option>promote</option></arg>
<arg choice="opt"><option>-w</option></arg>
<arg choice="opt"><option>-W</option></arg>
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg>
<arg choice="opt"><option>-s</option></arg>
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg>
@ -117,7 +117,7 @@ PostgreSQL documentation
<arg choice="plain"><option>d[emand]</option></arg>
</group>
</arg>
<arg choice="opt"><option>-w</option></arg>
<arg choice="opt"><option>-W</option></arg>
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg>
<arg choice="opt"><option>-s</option></arg>
<arg choice="opt"><option>-o</option> <replaceable>options</replaceable></arg>
@ -391,17 +391,7 @@ PostgreSQL documentation
Wait for an operation to complete. This is supported for the
modes <literal>start</literal>, <literal>stop</literal>,
<literal>restart</literal>, <literal>promote</literal>,
and <literal>register</literal>.
</para>
<para>
Waiting is the default option for shutdowns, but not startups,
restarts, or promotions. This is mainly for historical reasons; the
waiting option is almost always preferable. If waiting is not
selected, the requested action is triggered, but there is no feedback
about its success. In that case, the server log file or an external
monitoring system would have to be used to check the progress and
success of the operation.
and <literal>register</literal>, and is the default for those modes.
</para>
<para>
@ -424,6 +414,18 @@ PostgreSQL documentation
Do not wait for an operation to complete. This is the opposite of the
option <option>-w</option>.
</para>
<para>
If waiting is disabled, the requested action is triggered, but there
is no feedback about its success. In that case, the server log file
or an external monitoring system would have to be used to check the
progress and success of the operation.
</para>
<para>
In prior releases of PostgreSQL, this was the default except for
the <literal>stop</literal> mode.
</para>
</listitem>
</varlistentry>
@ -593,7 +595,7 @@ PostgreSQL documentation
To start the server, waiting until the server is
accepting connections:
<screen>
<prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
<prompt>$</prompt> <userinput>pg_ctl start</userinput>
</screen>
</para>
@ -637,7 +639,7 @@ PostgreSQL documentation
To restart the server,
waiting for it to shut down and restart:
<screen>
<prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
<prompt>$</prompt> <userinput>pg_ctl restart</userinput>
</screen>
</para>

View File

@ -71,8 +71,7 @@ typedef enum
#define DEFAULT_WAIT 60
static bool do_wait = false;
static bool wait_set = false;
static bool do_wait = true;
static int wait_seconds = DEFAULT_WAIT;
static bool wait_seconds_arg = false;
static bool silent_mode = false;
@ -1959,7 +1958,7 @@ do_help(void)
printf(_(" -s, --silent only print errors, no informational messages\n"));
printf(_(" -t, --timeout=SECS seconds to wait when using -w option\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -w, --wait wait until operation completes\n"));
printf(_(" -w, --wait wait until operation completes (default)\n"));
printf(_(" -W, --no-wait do not wait until operation completes\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("(The default is to wait for shutdown, but not for start or restart.)\n\n"));
@ -2323,11 +2322,9 @@ main(int argc, char **argv)
break;
case 'w':
do_wait = true;
wait_set = true;
break;
case 'W':
do_wait = false;
wait_set = true;
break;
case 'c':
allow_core_files = true;
@ -2423,14 +2420,6 @@ main(int argc, char **argv)
exit(1);
}
if (!wait_set)
{
if (ctl_command == STOP_COMMAND)
do_wait = true;
else
do_wait = false;
}
if (ctl_command == RELOAD_COMMAND)
{
sig = SIGHUP;

View File

@ -32,24 +32,24 @@ else
print CONF "listen_addresses = '127.0.0.1'\n";
}
close CONF;
command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ],
'pg_ctl start -w');
command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data" ],
'pg_ctl start');
# sleep here is because Windows builds can't check postmaster.pid exactly,
# so they may mistake a pre-existing postmaster.pid for one created by the
# postmaster they start. Waiting more than the 2 seconds slop time allowed
# by test_postmaster_connection prevents that mistake.
sleep 3 if ($windows_os);
command_fails([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ],
'second pg_ctl start -w fails');
command_ok([ 'pg_ctl', 'stop', '-D', "$tempdir/data", '-w' ],
'pg_ctl stop -w');
command_fails([ 'pg_ctl', 'stop', '-D', "$tempdir/data", '-w' ],
command_fails([ 'pg_ctl', 'start', '-D', "$tempdir/data" ],
'second pg_ctl start fails');
command_ok([ 'pg_ctl', 'stop', '-D', "$tempdir/data" ],
'pg_ctl stop');
command_fails([ 'pg_ctl', 'stop', '-D', "$tempdir/data" ],
'second pg_ctl stop fails');
command_ok([ 'pg_ctl', 'restart', '-D', "$tempdir/data", '-w' ],
command_ok([ 'pg_ctl', 'restart', '-D', "$tempdir/data" ],
'pg_ctl restart with server not running');
command_ok([ 'pg_ctl', 'restart', '-D', "$tempdir/data", '-w' ],
command_ok([ 'pg_ctl', 'restart', '-D', "$tempdir/data" ],
'pg_ctl restart with server running');
system_or_bail 'pg_ctl', 'stop', '-D', "$tempdir/data";

View File

@ -32,13 +32,13 @@ $node_standby->start;
is($node_standby->safe_psql('postgres', 'SELECT pg_is_in_recovery()'),
't', 'standby is in recovery');
command_ok([ 'pg_ctl', '-D', $node_standby->data_dir, 'promote' ],
'pg_ctl promote of standby runs');
command_ok([ 'pg_ctl', '-D', $node_standby->data_dir, '-W', 'promote' ],
'pg_ctl -W promote of standby runs');
ok($node_standby->poll_query_until('postgres', 'SELECT NOT pg_is_in_recovery()'),
'promoted standby is not in recovery');
# same again with wait option
# same again with default wait option
$node_standby = get_new_node('standby2');
$node_standby->init_from_backup($node_primary, 'my_backup', has_streaming => 1);
$node_standby->start;
@ -46,8 +46,8 @@ $node_standby->start;
is($node_standby->safe_psql('postgres', 'SELECT pg_is_in_recovery()'),
't', 'standby is in recovery');
command_ok([ 'pg_ctl', '-D', $node_standby->data_dir, '-w', 'promote' ],
'pg_ctl -w promote of standby runs');
command_ok([ 'pg_ctl', '-D', $node_standby->data_dir, 'promote' ],
'pg_ctl promote of standby runs');
# no wait here

View File

@ -55,7 +55,7 @@ $master->restart;
$master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
$master->restart;
system_or_bail('pg_ctl', '-w', '-D', $standby->data_dir, 'promote');
system_or_bail('pg_ctl', '-D', $standby->data_dir, 'promote');
$standby->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
$standby->safe_psql('postgres', "create table t11()");

View File

@ -632,7 +632,7 @@ port = $port
=item $node->start()
Wrapper for pg_ctl -w start
Wrapper for pg_ctl start
Start the node and wait until it is ready to accept connections.
@ -645,7 +645,7 @@ sub start
my $pgdata = $self->data_dir;
my $name = $self->name;
print("### Starting node \"$name\"\n");
my $ret = TestLib::system_log('pg_ctl', '-w', '-D', $self->data_dir, '-l',
my $ret = TestLib::system_log('pg_ctl', '-D', $self->data_dir, '-l',
$self->logfile, 'start');
if ($ret != 0)
@ -702,7 +702,7 @@ sub reload
=item $node->restart()
Wrapper for pg_ctl -w restart
Wrapper for pg_ctl restart
=cut
@ -714,7 +714,7 @@ sub restart
my $logfile = $self->logfile;
my $name = $self->name;
print "### Restarting node \"$name\"\n";
TestLib::system_log('pg_ctl', '-D', $pgdata, '-w', '-l', $logfile,
TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile,
'restart');
$self->_update_pid;
}
@ -723,7 +723,7 @@ sub restart
=item $node->promote()
Wrapper for pg_ctl promote -w
Wrapper for pg_ctl promote
=cut
@ -735,7 +735,7 @@ sub promote
my $logfile = $self->logfile;
my $name = $self->name;
print "### Promoting node \"$name\"\n";
TestLib::system_log('pg_ctl', '-D', $pgdata, '-w', '-l', $logfile,
TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile,
'promote');
}

View File

@ -448,7 +448,7 @@ sub upgradecheck
print "\nRunning initdb on old cluster\n\n";
standard_initdb() or exit 1;
print "\nStarting old cluster\n\n";
my @args = ('pg_ctl', 'start', '-l', "$logdir/postmaster1.log", '-w');
my @args = ('pg_ctl', 'start', '-l', "$logdir/postmaster1.log");
system(@args) == 0 or exit 1;
print "\nCreating databases with names covering most ASCII bytes\n\n";
@ -475,7 +475,7 @@ sub upgradecheck
$bindir, '-B', $bindir);
system(@args) == 0 or exit 1;
print "\nStarting new cluster\n\n";
@args = ('pg_ctl', '-l', "$logdir/postmaster2.log", '-w', 'start');
@args = ('pg_ctl', '-l', "$logdir/postmaster2.log", 'start');
system(@args) == 0 or exit 1;
print "\nSetting up stats on new cluster\n\n";
system(".\\analyze_new_cluster.bat") == 0 or exit 1;