3 # postgresql This is the init script for starting up the PostgreSQL
8 # description: Starts and stops the PostgreSQL backend daemon that handles \
9 # all database requests.
11 # processname: postmaster
12 # pidfile: /var/run/postmaster.pid
14 # Source function library
15 . /etc/rc.d/init.d/functions
18 . /etc/sysconfig/network
21 if [ -f /etc/sysconfig/postgresql ] ; then
22 . /etc/sysconfig/postgresql
24 ALLOW_TCP_CONNECTIONS=no
25 POSTGRES_DATA_DIR=/var/lib/psql
28 # Check that networking is up.
29 if is_no "${NETWORKING}"; then
30 msg_Network_Down Postgresql
34 # See how we were called.
37 # Check if the service is already running?
38 if [ ! -f /var/lock/subsys/postgresql ]; then
41 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
42 STARTTEXT="Starting postgresql"
44 # Check for the PGDATA structure
45 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -d $POSTGRES_DATA_DIR/base/template1 ]; then
46 # Check version of existing PGDATA
47 if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '6.5' ]; then
48 STARTTEXT="$STARTTEXT [Old version. Need to Upgrade]"
49 show "$STARTTEXT"; fail
53 # Create sample database
54 if [ ! -d $POSTGRES_DATA_DIR ]; then
55 mkdir -p $POSTGRES_DATA_DIR
56 chown postgres.postgres $POSTGRES_DATA_DIR
58 show "Creating postgresql init database"
60 su postgres -c "LD_LIBRARY_PATH=/usr/lib \
61 initdb --pgdata=$POSTGRES_DATA_DIR \
62 --pglib=/usr/lib/pgsql &>/tmp/initdb.pgsql"
68 su postgres -c "/usr/bin/postmaster \
69 $([ "$ALLOW_TCP_CONNECTIONS" = yes ] && echo "-i") \
70 $([ -n "$MAX_NUM_BACKENDS" ] && echo "-N $MAX_NUM_BACKENDS") \
71 $([ -n "POSTGRES_$DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
73 $([ "$POSTGRES_QUIET" = yes ] && echo "-Q") \
74 $([ "$POSTGRES_DIABLE_FSYNC" = yes ] && echo "-F") 2> /dev/null &"
76 if ps ax | grep -v grep | grep -q postmaster; then
82 msg_Already_Running Postgresql
84 touch /var/lock/subsys/postgresql
87 msg_stopping postgresql
90 rm -f /var/run/postmaster.pid
91 rm -f /var/lock/subsys/postgresql
101 msg_Usage "$0 {start|stop|status|restart|reload}"