PostgreSQL auto start script

#! /bin/bash
#
# chkconfig: 2345 80 05
# description: start and stop PostgreSQL Database Enterprise Edition
#

#
# Note: Change the value of POSTGRES to the login name of the PostgreSQL owner
POSTGRES=postgres

export PGDATA=/home/postgres/DATA
export PGPORT=5432
export PGSOFTWARE=/home/postgres/9.6_SOFTWARE #location where we installed the software


PATH=${PATH}:$PGSOFTWARE/bin
export PATH

case $1 in
‘start’)
        echo $”Starting PostgreSQL: “
        if [[ `whoami` == ‘postgres’ ]]
        then
        $PGSOFTWARE/bin/pg_ctl start
        else
        su $POSTGRES -c “$PGSOFTWARE/bin/pg_ctl start”
        fi
        ;;
‘stop’)
        echo $”Shutting down PostgreSQL: “
        if [[ `whoami` == ‘postgres’ ]]
        then
        $PGSOFTWARE/bin/pg_ctl start
        else
        su $POSTGRES -c “$PGSOFTWARE/bin/pg_ctl stop”
        fi
        ;;
‘status’)
        echo $”Status of PostgreSQL: “
        if [[ `whoami` == ‘postgres’ ]]
        then
        $PGSOFTWARE/bin/pg_ctl status
        else
        su $POSTGRES -c “$PGSOFTWARE/bin/pg_ctl status”
        fi
        ;;
‘restart’)
        echo $”Restarting PostgreSQL: “
        if [[ `whoami` == ‘postgres’ ]]
        then
        $PGSOFTWARE/bin/pg_ctl restart
        else
        su $POSTGRES -c “$PGSOFTWARE/bin/pg_ctl restart”
        fi
        ;;
*)
        echo “usage: $0 {start|stop|restart|status}”
        exit
        ;;
esac
exit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s