Skip to content

Instantly share code, notes, and snippets.

@mrmichalis
Created January 8, 2013 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrmichalis/4485756 to your computer and use it in GitHub Desktop.
Save mrmichalis/4485756 to your computer and use it in GitHub Desktop.
OSX Shell script to start and stop PostgreSQL
#!/usr/bin/env bash
# usage
# sudo -u postgres bin/pg_ctl $1 -D $DATADIR
PG_DIR=$(dirname $(locate pg_ctl | head -n 1))
DATADIR=/Library/PostgreSQL/9.2/data
STATUS=$(sudo -u postgres $PG_DIR/pg_ctl status -D $DATADIR)
if [ $# -lt 1 ]; then
echo "Usage : $0 [start|stop|status]"
echo $STATUS
exit
fi
if [ "$1" == "start" ]; then
if [ "$STATUS" == "pg_ctl: no server running" ]; then
sudo -u postgres bin/pg_ctl $1 -D $DATADIR
else
echo "Server is already running."
echo $STATUS
echo "$0 stop - to stop the PostgresSQL server"
fi
else
sudo -u postgres bin/pg_ctl $1 -D $DATADIR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment