From: Peter Eisentraut Date: Sat, 25 Nov 2000 17:17:30 +0000 (+0000) Subject: Update pg_ctl ref page, help output, messages. Some repair to work better X-Git-Tag: REL7_1_BETA~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c25b4dbf03a9b9e5bf79f2f7e2bcdcd9dc6263b9;p=postgresql Update pg_ctl ref page, help output, messages. Some repair to work better with current postmaster. --- diff --git a/doc/src/sgml/ref/pg_ctl-ref.sgml b/doc/src/sgml/ref/pg_ctl-ref.sgml index 4fc37312ea..8d7e3eac13 100644 --- a/doc/src/sgml/ref/pg_ctl-ref.sgml +++ b/doc/src/sgml/ref/pg_ctl-ref.sgml @@ -1,42 +1,76 @@ + + 2000-11-25 + + - - pg_ctl - + pg_ctl + 1 Application - - pg_ctl - - - Starts, stops, and restarts postmaster - + pg_ctl + Starts, stops, or restarts postmaster - - 2000-04-05 - - - -pg_ctl [-w] [-D datadir][-p path] [-o "options"] start -pg_ctl [-w] [-D datadir] [-m [s[mart]|f[ast]|i[mmediate]]] stop -pg_ctl [-w] [-D datadir] [-m [s[mart]|f[ast]|i[mmediate]] - [-o "options"] restart -pg_ctl [-D datadir] status - - - - - Inputs - + + pg_ctl + start + -w + -D datadir + -p path + -o options + + pg_ctl + stop + -w + -D datadir + -m + + s[mart] + f[ast] + i[mmediate] + + + + pg_ctl + restart + -w + -D datadir + -m + + s[mart] + f[ast] + i[mmediate] + + + -o options + + pg_ctl + status + -D datadir + + + + + + Description + + pg_ctl is a utility for starting, + stopping, or restarting the , or displaying the status of a + running postmaster. + + + + Options @@ -44,8 +78,9 @@ pg_ctl [-D datadir] status -w - Wait for the database server to come up, by - watching for creation of the pid file (PGDATA/postmaster.pid). + Wait for the database server to come up, by watching for + creation of the pid file + (PGDATA/postmaster.pid). Times out after 60 seconds. @@ -55,7 +90,9 @@ pg_ctl [-D datadir] status -D datadir - Specifies the database location for this database installation. + Specifies the file system location of the database files. If + this is omitted, the environment variable + PGDATA is used. @@ -64,13 +101,18 @@ pg_ctl [-D datadir] status -p path - Specifies the path to the postmaster image. + Specifies the location of the postmaster + executable. By default the postmaster is taken from the same + directory as pg_ctl, or failing that, the hard-wired + installation directory. It is not necessary to use this + option unless you are doing something unusual and get errors + that the postmaster was not found. - -o "options" + -o options Specifies options to be passed directly to @@ -95,8 +137,8 @@ pg_ctl [-D datadir] status s - smart mode waits for all - the clients to logout. This is the default. + Smart mode waits for all the clients to disconnect. This + is the default. @@ -106,8 +148,8 @@ pg_ctl [-D datadir] status f - Fast mode sends SIGTERM to the backends; that means - active transactions get rolled back. + Fast mode does not wait for clients to disconnect. All + active transactions will be rolled back. @@ -117,9 +159,8 @@ pg_ctl [-D datadir] status i - Immediate mode sends SIGUSR1 - to the backends and lets them abort. In this case, database recovery - will be necessary on the next start-up. + Immediate mode will abort without complete shutdown. This + will lead to a recovery run on restart. @@ -150,8 +191,8 @@ pg_ctl [-D datadir] status restart - Restart the postmaster, performing - a stop/start sequence. + Stop the postmaster, if one is running, + and then start it again. @@ -168,229 +209,107 @@ pg_ctl [-D datadir] status - - - 1999-11-07 - - - Outputs - - - - - pg_ctl: postmaster is state (pid: #) - - - Postmaster status. - - - - + + Files - If there is an error condition, the backend error message will be displayed. + + If the file postmaster.opts.default exists in + the data directory, the contents of the file will be passed as + options to the postmaster, unless + overridden by the option. - - - - Description - - - pg_ctl is a utility for starting, - stopping or restarting postmaster. - + - - Usage - + Usage - - Starting postmaster - + Starting the postmaster To start up postmaster: - - -$ pg_ctl start - + +$ pg_ctl start + - If -w is supplied, pg_ctl waits for the database server to come up, by - watching for creation of the pid file (PGDATA/postmaster.pid), for up - to 60 seconds. - - - - Parameters to invoke postmaster are - taken from the following sources: - - - - - Path to postmaster: found in the command search path. - - - - - - Database directory: PGDATA environment variable. - - - - - - Other parameters: - PGDATA/postmaster.opts.default. - - - - - - - postmaster.opts.default contains parameters - for postmaster. - - - - Note that postmaster.opts.default is - installed by initdb from - lib/postmaster.opts.default.sample - under the Postgres installation - directory (lib/postmaster.opts.default.sample - is copied from - src/bin/pg_ctl/postmaster.opts.default.sample - while installing Postgres). - - - - To override the default parameters you can use , - and options. - - - - An example of starting the - postmaster, blocking until - postmaster comes up is: - -$ pg_ctl -w start - - - - - To specify the postmaster binary path, - try: - - -$ pg_ctl -p /usr/local/pgsql/bin/postmaster start - + An example of starting the postmaster, + blocking until postmaster comes up is: + +$ pg_ctl -w start + For a postmaster using port 5433, and running without fsync, use: - - -$ pg_ctl -o "-o -F -p 5433" start - + +$ pg_ctl -o "-F -p 5433" start + - - Stopping postmaster - + Stopping the postmaster - - -$ pg_ctl stop - - + +$ pg_ctl stop + stops postmaster. Using the switch allows one to control how the backend shuts down. - - waits for postmaster to shut down. - specifies the shut down mode. + waits for postmaster to shut down. - - Restarting postmaster - + Restarting the postmaster This is almost equivalent to stopping the - postmaster then starting it - again except that the parameters used before stopping - it would be used too. This is done by saving them in - $PGDATA/postmaster.opts file. - , , , - , and - - can also be used in the restarting mode and they have the same meanings as - described above. - - - - To restart postmaster in the simplest - form: - - -$ pg_ctl restart - + postmaster then starting it again + except that pg_ctl saves and reuses the command line options that + were passed to the previously running instance. To restart + postmaster in the simplest form: + +$ pg_ctl restart + To restart postmaster, waiting for it to shut down and to come up: - - -$ pg_ctl -w restart - + +$ pg_ctl -w restart + To restart using port 5433 and disabling fsync after restarting: - - -$ pg_ctl -o "-o -F -p 5433" restart - + +$ pg_ctl -o "-F -p 5433" restart + - - postmaster status - + Showing postmaster status - To get status information from postmaster: - - -$ pg_ctl status - - - - - Here is a sample output from pg_ctl: - - + Here is a sample status output from + pg_ctl: + +$ pg_ctl status + pg_ctl: postmaster is running (pid: 13718) -options are: -/usr/local/src/pgsql/current/bin/postmaster --p 5433 --D /usr/local/src/pgsql/current/data --B 64 --b /usr/local/src/pgsql/current/bin/postgres --N 32 --o '-F' - +Command line was: +/usr/local/pgsql/bin/postmaster '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128' + + + This is the command line that would be invoked in restart mode. diff --git a/src/bin/pg_ctl/Makefile b/src/bin/pg_ctl/Makefile index 716d93cea2..fb4234dcc8 100644 --- a/src/bin/pg_ctl/Makefile +++ b/src/bin/pg_ctl/Makefile @@ -4,7 +4,7 @@ # # Copyright (c) 1999, PostgreSQL Global Development Group # -# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.9 2000/09/17 13:02:35 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.10 2000/11/25 17:17:30 petere Exp $ # #------------------------------------------------------------------------- @@ -15,7 +15,9 @@ include $(top_builddir)/src/Makefile.global all: pg_ctl pg_ctl: pg_ctl.sh - cp $< $@ + sed -e 's/@VERSION@/$(VERSION)/g' \ + -e 's,@bindir@,$(bindir),g' \ + $< >$@ chmod a+x $@ install: all installdirs diff --git a/src/bin/pg_ctl/pg_ctl.sh b/src/bin/pg_ctl/pg_ctl.sh index 2c98f41ecd..aea4a98690 100755 --- a/src/bin/pg_ctl/pg_ctl.sh +++ b/src/bin/pg_ctl/pg_ctl.sh @@ -8,14 +8,50 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.13 2000/10/24 19:11:15 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.14 2000/11/25 17:17:30 petere Exp $ # #------------------------------------------------------------------------- + CMDNAME=`basename $0` +help="\ +$CMDNAME is a utility to start, stop, restart, and report the status +of a PostgreSQL server. + +Usage: + $CMDNAME start [-w] [-D DATADIR] [-p PATH-TO-POSTMASTER] [-o \"OPTIONS\"] + $CMDNAME stop [-w] [-D DATADIR] [-m SHUTDOWN-MODE] + $CMDNAME restart [-w] [-D DATADIR] [-m SHUTDOWN-MODE] [-o \"OPTIONS\"] + $CMDNAME status [-D DATADIR] + +Options: + -D DATADIR Location of the database storage area + -m SHUTDOWN-MODE May be 'smart', 'fast', or 'immediate' + -o OPTIONS Command line options to pass to the postmaster + (PostgreSQL server executable) + -p PATH-TO-POSTMASTER Normally not necessary + -w Wait until operation completes + +If the -D option is omitted, the environment variable PGDATA is used. + +Shutdown modes are: + smart Quit after all clients have disconnected + fast Quit directly, with proper shutdown + immediate Quit without complete shutdown; will lead + to recovery run on restart + +Report bugs to ." + +advice="\ +Try '$CMDNAME --help' for more information." + + +# Placed here during build +bindir='@bindir@' +VERSION='@VERSION@' + # Check for echo -n vs echo \c -ECHO=echo if echo '\c' | grep -s c >/dev/null 2>&1 then ECHO_N="echo -n" @@ -28,38 +64,35 @@ fi # # Find out where we're located # -if $ECHO "$0" | grep '/' > /dev/null 2>&1 +if echo "$0" | grep '/' > /dev/null 2>&1 then # explicit dir name given - PGPATH=`$ECHO $0 | sed 's,/[^/]*$,,'` # (dirname command is not portable) + self_path=`echo $0 | sed 's,/[^/]*$,,'` # (dirname command is not portable) else # look for it in PATH ('which' command is not portable) - for dir in `$ECHO "$PATH" | sed 's/:/ /g'` + for dir in `echo "$PATH" | sed 's/:/ /g'` do # empty entry in path means current dir [ -z "$dir" ] && dir='.' if [ -f "$dir/$CMDNAME" ] then - PGPATH="$dir" + self_path="$dir" break fi done fi # Check if needed programs actually exist in path -for prog in postmaster psql -do - if [ ! -x "$PGPATH/$prog" ] - then - $ECHO "The program $prog needed by $CMDNAME could not be found. It was" - $ECHO "expected at:" - $ECHO " $PGPATH/$prog" - $ECHO "If this is not the correct directory, please start $CMDNAME" - $ECHO "with a full search path. Otherwise make sure that the program" - $ECHO "was installed successfully." - exit 1 - fi -done +if [ -x "$self_path/postmaster" ] && [ -x "$self_path/psql" ]; then + PGPATH=$self_path +elif [ -x "$bindir/postmaster" ] && [ -x "$bindir/psql" ]; then + PGPATH=$bindir +else + echo "The programs 'postmaster' and 'psql' are needed by $CMDNAME but" 1>&2 + echo "were not found in the directory '$bindir'." 1>&2 + echo "Check your installation." 1>&2 + exit 1 +fi po_path=$PGPATH/postmaster @@ -69,14 +102,17 @@ sig="-TERM" while [ "$#" -gt 0 ] do case $1 in - -h|--help) - usage=1 - break - ;; + -h|--help|-\?) + echo "$help" + exit 0 + ;; + -V|--version) + echo "pg_ctl (PostgreSQL) $VERSION" + exit 0 + ;; -D) shift PGDATA="$1" - export PGDATA ;; -p) shift @@ -94,8 +130,9 @@ do sig="-QUIT" ;; *) - $ECHO "$CMDNAME: Wrong shutdown mode $sigopt" - usage=1 + echo "$CMDNAME: wrong shutdown mode: $1" 1>&2 + echo "$advice" 1>&2 + exit 1 ;; esac ;; @@ -106,6 +143,11 @@ do shift POSTOPTS="$1" ;; + -*) + echo "$CMDNAME: invalid option: $1" 1>&2 + echo "$advice" 1>&2 + exit 1 + ;; start) op="start" ;; @@ -119,23 +161,23 @@ do op="status" ;; *) - usage=1 - break + echo "$CMDNAME: invalid operation mode: $1" 1>&2 + echo "$advice" 1>&2 + exit 1 ;; esac shift done -if [ "$usage" = 1 -o "$op" = "" ];then - $ECHO "Usage: $CMDNAME [-w][-D database_dir][-p path_to_postmaster][-o \"postmaster_opts\"] start" - $ECHO " $CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]] stop" - $ECHO " $CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]][-o \"postmaster_opts\"] restart" - $ECHO " $CMDNAME [-D database_dir] status" +if [ x"$op" = x"" ];then + echo "$CMDNAME: no operation mode specified" 1>&2 + echo "$advice" 1>&2 exit 1 fi if [ -z "$PGDATA" ];then - $ECHO "$CMDNAME: No database directory or environment variable \$PGDATA is specified" + echo "$CMDNAME: no database directory or environment variable \$PGDATA is specified" 1>&2 + echo "$advice" 1>&2 exit 1 fi @@ -148,15 +190,15 @@ if [ $op = "status" ];then PID=`cat $PIDFILE` if [ $PID -lt 0 ];then PID=`expr 0 - $PID` - $ECHO "$CMDNAME: postgres is running (pid: $PID)" + echo "$CMDNAME: postgres is running (pid: $PID)" else - $ECHO "$CMDNAME: postmaster is running (pid: $PID)" - $ECHO "options are:" - $ECHO "`cat $POSTOPTSFILE`" + echo "$CMDNAME: postmaster is running (pid: $PID)" + echo "Command line was:" + echo "`cat $POSTOPTSFILE`" fi exit 0 else - $ECHO "$CMDNAME: postmaster or postgres is not running" + echo "$CMDNAME: postmaster or postgres is not running" exit 1 fi fi @@ -166,8 +208,8 @@ if [ $op = "stop" -o $op = "restart" ];then PID=`cat $PIDFILE` if [ $PID -lt 0 ];then PID=`expr 0 - $PID` - $ECHO "$CMDNAME: Cannot restart postmaster. postgres is running (pid: $PID)" - $ECHO "Please terminate postgres and try again" + echo "$CMDNAME: Cannot restart postmaster. postgres is running (pid: $PID)" + echo "Please terminate postgres and try again" exit 1 fi @@ -176,7 +218,7 @@ if [ $op = "stop" -o $op = "restart" ];then # wait for postmaster shutting down if [ "$wait" = 1 -o $op = "restart" ];then cnt=0 - $ECHO_N "Waiting for postmaster shutting down.."$ECHO_C + $ECHO_N "Waiting for postmaster to shut down.."$ECHO_C while : do @@ -184,7 +226,7 @@ if [ $op = "stop" -o $op = "restart" ];then $ECHO_N "."$ECHO_C cnt=`expr $cnt + 1` if [ $cnt -gt 60 ];then - $ECHO "$CMDNAME: postmaster does not shut down" + echo "$CMDNAME: postmaster does not shut down" exit 1 fi else @@ -192,16 +234,16 @@ if [ $op = "stop" -o $op = "restart" ];then fi sleep 1 done - $ECHO "done." + echo "done" fi - $ECHO "postmaster successfully shut down." + echo "postmaster successfully shut down" else - $ECHO "$CMDNAME: Can't find $PIDFILE." - $ECHO "Is postmaster running?" + echo "$CMDNAME: cannot find $PIDFILE" + echo "Is postmaster running?" if [ $op = "restart" ];then - $ECHO "Anyway, I'm going to start up postmaster..." + echo "starting postmaster anyway..." else exit 1 fi @@ -210,7 +252,7 @@ fi if [ $op = "start" -o $op = "restart" ];then if [ -f $PIDFILE ];then - $ECHO "$CMDNAME: It seems another postmaster is running. Try to start postmaster anyway." + echo "$CMDNAME: It seems another postmaster is running. Trying to start postmaster anyway." pid=`cat $PIDFILE` fi @@ -219,21 +261,22 @@ if [ $op = "start" -o $op = "restart" ];then if [ $op = "start" ];then # if we are in start mode, then look for postmaster.opts.default if [ -f $DEFPOSTOPTS ];then - eval "$po_path `cat $DEFPOSTOPTS`" & + $po_path -D $PGDATA `cat $DEFPOSTOPTS` & else - $po_path & + $po_path -D $PGDATA & fi else # if we are in restart mode, then look postmaster.opts - eval `cat $POSTOPTSFILE` & + `cat $POSTOPTSFILE` & fi else - eval "$po_path $POSTOPTS " & + # -o given + $po_path -D $PGDATA $POSTOPTS & fi if [ -f $PIDFILE ];then if [ "`cat $PIDFILE`" = "$pid" ];then - $ECHO "$CMDNAME: Cannot start postmaster. Is another postmaster is running?" + echo "$CMDNAME: Cannot start postmaster. Is another postmaster is running?" exit 1 fi fi @@ -241,7 +284,7 @@ if [ $op = "start" -o $op = "restart" ];then # wait for postmaster starting up if [ "$wait" = 1 ];then cnt=0 - $ECHO_N "Waiting for postmaster starting up.."$ECHO_C + $ECHO_N "Waiting for postmaster to start up.."$ECHO_C while : do if psql -l >/dev/null 2>&1 @@ -251,16 +294,16 @@ if [ $op = "start" -o $op = "restart" ];then $ECHO_N "."$ECHO_C cnt=`expr $cnt + 1` if [ $cnt -gt 60 ];then - $ECHO "$CMDNAME: postmaster does not start up" + echo "$CMDNAME: postmaster does not start up" exit 1 fi sleep 1 fi done - $ECHO "done." + echo "done" fi - $ECHO "postmaster successfully started up." + echo "postmaster successfully started up" fi exit 0