Created
January 8, 2013 17:18
-
-
Save mrmichalis/4485756 to your computer and use it in GitHub Desktop.
OSX Shell script to start and stop PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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