Thread: starting PGSQL automatically on Redhat 6.2

starting PGSQL automatically on Redhat 6.2

From
"Ryan Mahoney"
Date:
Hey all, I copied the pg_ctl script and placed it in my /etc/rc.d/init.d/
directory and renamed it 'postgres'.  I then made all the necessary symbolic
links.  When my machine boots up however, pgsql does not start up because it
cannot be started by root.  I have created the 'postgres' user and data
directories.  I can start PG manually just fine.  Can someone post or mail a
working startup script/recommend any changes to pg_ctl?  Thanks!

Ryan Mahoney
ryan@paymentalliance.net



Re: starting PGSQL automatically on Redhat 6.2

From
T F
Date:
Ryan Mahoney wrote:

> Hey all, I copied the pg_ctl script and placed it in my /etc/rc.d/init.d/
> directory and renamed it 'postgres'.  I then made all the necessary symbolic
> links.  When my machine boots up however, pgsql does not start up because it
> cannot be started by root.  I have created the 'postgres' user and data
> directories.  I can start PG manually just fine.  Can someone post or mail a
> working startup script/recommend any changes to pg_ctl?  Thanks!
>
> Ryan Mahoney
> ryan@paymentalliance.net

You might try this, it was taken from the postgresql-6.5.3-6 rpm:


#! /bin/sh
# postgresql    This is the init script for starting up the PostgreSQL
#        server

# Version 6.5.3-2 Lamar Owen
# Added code to determine if PGDATA exists, whether it is current version
#     or not, and initdb if no PGDATA (initdb will not overwrite a database).

# chkconfig: 345 85 15
# description: Starts and stops the PostgreSQL backend daemon that handles \
#           all database requests.
# processname: postmaster
# pidfile: /var/run/postmaster.pid
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
# Pretty much need it for postmaster.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/bin/postmaster ] || exit 0

# This script is slightly unusual in that the name of the daemon (postmaster)
# is not the same as the name of the subsystem (postgresql)

# See how we were called.
case "$1" in
  start)
    echo -n "Checking postgresql installation: "
    # Check for the PGDATA structure
    if [ -f /var/lib/pgsql/PG_VERSION ] && [ -d /var/lib/pgsql/base/template1 ]
    then
    # Check version of existing PGDATA

        if [ `cat /var/lib/pgsql/PG_VERSION` != '6.5' ]
        then
            echo "old version. Need to Upgrade."
            echo "See /usr/doc/postgresql-6.5.3/README.rpm for more information."
            exit 1
        else
            echo "looks good!"
        fi

    # No existing PGDATA! Initdb it.

    else
        echo "no database files found."
                if [ ! -d /var/lib/pgsql ]
        then
            mkdir -p /var/lib/pgsql
            chown postgres.postgres /var/lib/pgsql
        fi
        su -l postgres -c '/usr/bin/initdb --pglib=/usr/lib/pgsql --pgdata=/var/lib/pgsql'
    fi

    # Check for postmaster already running...
    pid=`pidof postmaster`
    if [ $pid ]
    then
        echo "Postmaster already running."
    else
        #all systems go -- remove any stale lock files
        rm -f /tmp/.s.PGSQL.* > /dev/null
        echo -n "Starting postgresql service: "
        su -l postgres -c '/usr/bin/postmaster -i -S -D/var/lib/pgsql'
        sleep 1
        pid=`pidof postmaster`
        if [ $pid ]
        then
            echo -n "postmaster [$pid]"
            touch /var/lock/subsys/postgresql
            echo $pid > /var/run/postmaster.pid
            echo
        else
            echo "failed."
        fi
    fi
    ;;
  stop)
    echo -n "Stopping postgresql service: "
    killproc postmaster
    sleep 2
    rm -f /var/run/postmaster.pid
    rm -f /var/lock/subsys/postgresql
    echo
    ;;
  status)
    status postmaster
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: postgresql {start|stop|status|restart}"
    exit 1
esac

exit 0

Re: starting PGSQL automatically on Redhat 6.2

From
"Brett W. McCoy"
Date:
On Tue, 9 Jan 2001, Ryan Mahoney wrote:

> Hey all, I copied the pg_ctl script and placed it in my /etc/rc.d/init.d/
> directory and renamed it 'postgres'.  I then made all the necessary symbolic
> links.  When my machine boots up however, pgsql does not start up because it
> cannot be started by root.  I have created the 'postgres' user and data
> directories.  I can start PG manually just fine.  Can someone post or mail a
> working startup script/recommend any changes to pg_ctl?  Thanks!

You need to su to the postgres user in your script to start the
postmaster:

su postgres -c "postmaster -i ... "

There's a complete example in the installation docs.

-- Brett
                                     http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
History is the version of past events that people have decided to agree on.
        -- Napoleon Bonaparte, "Maxims"


Re: Re: starting PGSQL automatically on Redhat 6.2

From
Tatsuo Ishii
Date:
From: T F <torford@hotmail.nospam.com>
Subject: [GENERAL] Re: starting PGSQL automatically on Redhat 6.2
Date: Tue, 09 Jan 2001 12:12:52 -0700
Message-ID: <3A5B62B4.C73124BE@hotmail.nospam.com>

> Ryan Mahoney wrote:
>
> > Hey all, I copied the pg_ctl script and placed it in my /etc/rc.d/init.d/
> > directory and renamed it 'postgres'.  I then made all the necessary symbolic
> > links.  When my machine boots up however, pgsql does not start up because it
> > cannot be started by root.  I have created the 'postgres' user and data
> > directories.  I can start PG manually just fine.  Can someone post or mail a
> > working startup script/recommend any changes to pg_ctl?  Thanks!
> >
> > Ryan Mahoney
> > ryan@paymentalliance.net
>
> You might try this, it was taken from the postgresql-6.5.3-6 rpm:
>
>

That script seems dangerous. It calls

    killproc postmaster

to terminate postmaster. In this case killproc firstly sends SIGTERM
to postmaster (this is ok). But if postmaster won't die with the
signal, then killproc sends SIGKILL to postmaster (this is not
good). SIGINT or SIGQUIT should be sent in this case.

BTW, pg_ctl only works with version 7.0 or higher.
--
Tatsuo Ishii

Re: Re: starting PGSQL automatically on Redhat 6.2

From
"Ryan Mahoney"
Date:
I'm actaully trying to get 7.1b to start automatically, still no success,
but I'm making progres.

Trying to modify the pg_ctl that comes with 7.1 to add the su - postgres -c
....

-Ryan

Tatsuo Ishii wrote in message <20010110111111X.t-ishii@sra.co.jp>...
>From: T F <torford@hotmail.nospam.com>
>Subject: [GENERAL] Re: starting PGSQL automatically on Redhat 6.2
>Date: Tue, 09 Jan 2001 12:12:52 -0700
>Message-ID: <3A5B62B4.C73124BE@hotmail.nospam.com>
>
>> Ryan Mahoney wrote:
>>
>> > Hey all, I copied the pg_ctl script and placed it in my
/etc/rc.d/init.d/
>> > directory and renamed it 'postgres'.  I then made all the necessary
symbolic
>> > links.  When my machine boots up however, pgsql does not start up
because it
>> > cannot be started by root.  I have created the 'postgres' user and data
>> > directories.  I can start PG manually just fine.  Can someone post or
mail a
>> > working startup script/recommend any changes to pg_ctl?  Thanks!
>> >
>> > Ryan Mahoney
>> > ryan@paymentalliance.net
>>
>> You might try this, it was taken from the postgresql-6.5.3-6 rpm:
>>
>>
>
>That script seems dangerous. It calls
>
> killproc postmaster
>
>to terminate postmaster. In this case killproc firstly sends SIGTERM
>to postmaster (this is ok). But if postmaster won't die with the
>signal, then killproc sends SIGKILL to postmaster (this is not
>good). SIGINT or SIGQUIT should be sent in this case.
>
>BTW, pg_ctl only works with version 7.0 or higher.
>--
>Tatsuo Ishii



Re: Re: starting PGSQL automatically on Redhat 6.2

From
Mike Castle
Date:
On Wed, Jan 10, 2001 at 12:17:23PM -0000, Ryan Mahoney wrote:
> I'm actaully trying to get 7.1b to start automatically, still no success,
> but I'm making progres.
>
> Trying to modify the pg_ctl that comes with 7.1 to add the su - postgres -c

I added the following to the postgres account's .profile:

export PGDATA=${HOME}/data


I then had to use the following in my startup script:

                su - postgres -- --login -c "pg_ctl -o -S start"

                su - postgres -- --login -c "pg_ctl stop"

The reason for the --login is that the bash/gnu-su combination is broken (IMO)
wrt to sourcing .profile when ran from su.

mrc
--
       Mike Castle       Life is like a clock:  You can work constantly
  dalgoda@ix.netcom.com  and be right all the time, or not work at all
www.netcom.com/~dalgoda/ and be right at least twice a day.  -- mrc
    We are all of us living in the shadow of Manhattan.  -- Watchmen