# Original author: Ryan Kirkpatrick <pgsql@rkirkpat.net>
-# $Header: /cvsroot/pgsql/contrib/start-scripts/linux,v 1.3 2001/07/30 14:52:42 momjian Exp $
+# contrib/start-scripts/linux
## EDIT FROM HERE
# Data directory
PGDATA="/usr/local/pgsql/data"
-# Who to run pg_ctl as, should be "postgres".
+# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=postgres
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
-## STOP EDITING HERE
+# It's often a good idea to protect the postmaster from being killed by the
+# OOM killer (which will tend to preferentially kill the postmaster because
+# of the way it accounts for shared memory). Setting the OOM_ADJ value to
+# -17 will disable OOM kill altogether. If you enable this, you probably want
+# to compile PostgreSQL with "-DLINUX_OOM_ADJ=0", so that individual backends
+# can still be killed by the OOM killer.
+#OOM_ADJ=-17
-# Check for echo -n vs echo \c
-if echo '\c' | grep -s c >/dev/null 2>&1 ; then
- ECHO_N="echo -n"
- ECHO_C=""
-else
- ECHO_N="echo"
- ECHO_C='\c'
-fi
+## STOP EDITING HERE
# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-# What to use to start up the postmaster
-DAEMON="$prefix/bin/pg_ctl"
+# 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.)
+DAEMON="$prefix/bin/postmaster"
+
+# What to use to shut down the postmaster
+PGCTL="$prefix/bin/pg_ctl"
set -e
-# Only start if we can find pg_ctl.
-test -f $DAEMON || exit 0
+# Only start if we can find the postmaster.
+test -x $DAEMON ||
+{
+ echo "$DAEMON not found"
+ if [ "$1" = "stop" ]
+ then exit 0
+ else exit 5
+ fi
+}
+
# Parse command line parameters.
case $1 in
start)
- $ECHO_N "Starting PostgreSQL: "$ECHO_C
- su - $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG"
+ echo -n "Starting PostgreSQL: "
+ test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
+ su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
- su - $PGUSER -c "$DAEMON stop -D '$PGDATA' -s -m fast"
+ su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
- su - $PGUSER -c "$DAEMON restart -D '$PGDATA' -s -m fast"
+ su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
+ test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
+ su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
+ reload)
+ echo -n "Reload PostgreSQL: "
+ su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
+ echo "ok"
+ ;;
status)
- su - $PGUSER -c "$DAEMON status -D '$PGDATA'"
+ su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
*)
# Print help
- echo "Usage: $0 {start|stop|restart|status}" 1>&2
+ echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac