From 05cd12ed5bc74c853a161c5a138a0cb6f9b0cb8a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 13 Jan 2017 12:00:00 -0500 Subject: [PATCH] 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 Reviewed-by: Ryan Murphy --- contrib/start-scripts/freebsd | 5 ++- contrib/start-scripts/linux | 5 ++- contrib/start-scripts/osx/PostgreSQL | 3 +- doc/src/sgml/ref/pg_ctl-ref.sgml | 36 ++++++++++--------- src/bin/pg_ctl/pg_ctl.c | 15 ++------ src/bin/pg_ctl/t/001_start_stop.pl | 18 +++++----- src/bin/pg_ctl/t/003_promote.pl | 10 +++--- src/test/modules/commit_ts/t/003_standby_2.pl | 2 +- src/test/perl/PostgresNode.pm | 12 +++---- src/tools/msvc/vcregress.pl | 4 +-- 10 files changed, 49 insertions(+), 61 deletions(-) diff --git a/contrib/start-scripts/freebsd b/contrib/start-scripts/freebsd index 87d9b9b357..c6ac8cd47a 100644 --- a/contrib/start-scripts/freebsd +++ b/contrib/start-scripts/freebsd @@ -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) diff --git a/contrib/start-scripts/linux b/contrib/start-scripts/linux index d7499c9d1e..44a775b030 100644 --- a/contrib/start-scripts/linux +++ b/contrib/start-scripts/linux @@ -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" diff --git a/contrib/start-scripts/osx/PostgreSQL b/contrib/start-scripts/osx/PostgreSQL index 48c098c8f1..9735c8c57f 100755 --- a/contrib/start-scripts/osx/PostgreSQL +++ b/contrib/start-scripts/osx/PostgreSQL @@ -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 diff --git a/doc/src/sgml/ref/pg_ctl-ref.sgml b/doc/src/sgml/ref/pg_ctl-ref.sgml index 3f168005ec..176dfaf98a 100644 --- a/doc/src/sgml/ref/pg_ctl-ref.sgml +++ b/doc/src/sgml/ref/pg_ctl-ref.sgml @@ -31,7 +31,7 @@ PostgreSQL documentation pg_ctl - + seconds datadir @@ -60,7 +60,7 @@ PostgreSQL documentation pg_ctl - + seconds datadir @@ -91,7 +91,7 @@ PostgreSQL documentation pg_ctl - + seconds datadir @@ -117,7 +117,7 @@ PostgreSQL documentation - + seconds options @@ -391,17 +391,7 @@ PostgreSQL documentation Wait for an operation to complete. This is supported for the modes start, stop, restart, promote, - and register. - - - - 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 register, and is the default for those modes. @@ -424,6 +414,18 @@ PostgreSQL documentation Do not wait for an operation to complete. This is the opposite of the option . + + + 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. + + + + In prior releases of PostgreSQL, this was the default except for + the stop mode. + @@ -593,7 +595,7 @@ PostgreSQL documentation To start the server, waiting until the server is accepting connections: -$ pg_ctl -w start +$ pg_ctl start @@ -637,7 +639,7 @@ PostgreSQL documentation To restart the server, waiting for it to shut down and restart: -$ pg_ctl -w restart +$ pg_ctl restart diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index c161b19935..93e5891950 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -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; diff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.pl index b328f22487..8f16bf9795 100644 --- a/src/bin/pg_ctl/t/001_start_stop.pl +++ b/src/bin/pg_ctl/t/001_start_stop.pl @@ -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"; diff --git a/src/bin/pg_ctl/t/003_promote.pl b/src/bin/pg_ctl/t/003_promote.pl index 0b6090b6eb..7b1df29fa3 100644 --- a/src/bin/pg_ctl/t/003_promote.pl +++ b/src/bin/pg_ctl/t/003_promote.pl @@ -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 diff --git a/src/test/modules/commit_ts/t/003_standby_2.pl b/src/test/modules/commit_ts/t/003_standby_2.pl index d37ff182c4..043ccb14a5 100644 --- a/src/test/modules/commit_ts/t/003_standby_2.pl +++ b/src/test/modules/commit_ts/t/003_standby_2.pl @@ -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()"); diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index 868492b615..d8be1bd3e1 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -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'); } diff --git a/src/tools/msvc/vcregress.pl b/src/tools/msvc/vcregress.pl index f575e40052..f1b9819cd2 100644 --- a/src/tools/msvc/vcregress.pl +++ b/src/tools/msvc/vcregress.pl @@ -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; -- 2.40.0