#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Chennai, India
    Posts
    69
    Rep Power
    13

    automate startup of PostgreSQL 7.2.1


    Could anyone please point me to the links for information about automating the startup of PostgreSQL 7.2.1 on linux ?

    Thanks for your valuable input.

    Best Regards.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    France
    Posts
    55
    Rep Power
    13
    hi!

    Under redhat i use 'serviceconf' and check the postgresql service
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Chennai, India
    Posts
    69
    Rep Power
    13
    Thanks.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Chennai, India
    Posts
    69
    Rep Power
    13
    I've done what the link says, but afraid that its not working !
    ---------
    However, I did the following modification in /etc/rc5.d directory, as there was already a file called S91smb, I included a soft link for /etc/init.d/postgresql as /etc/rc5.d/S92postgresql. All the other instructions in the link, I followed verbatim...

    ln -s /etc/rc.d/init.d/postgresql /etc/rc.d/rc3.d/S91postgresql
    ln -s /etc/rc.d/init.d/postgresql /etc/rc.d/rc6.d/K22postgresql
    -----------

    I've checked /var/log/messages for any error messages also, but nothing connected to PostgreSQL startup !!

    Can you please point out what I'm missing out ? Or should I check some other file ? I've checked /var/spool/mail/root also.

    Thanks for your valuable input.

    Best Regards.
    Last edited by ggnanaraj; November 7th, 2002 at 02:29 AM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13
    Hey ggnanaraj,

    You are able to start postgres manually, right? When you watch the boot screen, does it give you any error messages, or does it just say, "Starting Postgres [FAILED]"

    I found this script on one of our Red Hat machines, it is started with:

    /etc/rc.d/init.d/postgresql start

    The "postgresql" script isn't softlinked to anything else, it's just in that init.d directory.


    PHP Code:

    #! /bin/sh
    # postgresql    This is the init script for starting up the PostgreSQL
    #        server
    #
    # chkconfig: - 85 15
    # description: Starts and stops the PostgreSQL backend daemon that handles \
    #           all database requests.
    # processname: postmaster
    # pidfile: /var/run/postmaster.pid

    # 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).

    # Version 7.0 Lamar Owen
    # Added logging code
    # Changed PGDATA.
    #

    # Version 7.0.2 Trond Eivind Glomsrød <teg@redhat.com>
    # use functions, add conditional restart
              
    # Version 7.0.3 Lamar Owen <lamar@postgresql.org>
    # Check for the existence of functions before blindly using them 
    # in particular -- check for success () and failure () before using.
    # More Cross-distribution support -- PGVERSION variable, and docdir checks.

    # Version 7.1 Release Candidate Lamar Owen <lamar@postgresql.org>
    # initdb parameters have changed.

    # Version 7.1.2 Trond Eivind Glomsrød <teg@redhat.com>
    # Specify shell for su
    # Handle stop better - kill unwanted output, make it wait until the database is ready
    # Handle locales slightly differently - always using "C" isn't a valid option 
    # Kill output from database initialization 
    # Mark messages for translation

    # Version 7.1.2-2.PGDG Lamar Owen <lamar.owen@wgcr.org>
    # sync up.
    # Karl's fixes for some quoting issues.

    # Version 7.2b2 Lamar Owen <lamar.owen@wgcr.org>
    # version change.

    # Version 7.2 final.  Lamar Owen <lamar.owen@wgcr.org>
    # reload from Peter E.
    # Eliminate the pidof postmaster test in stop -- we're using pg_ctl so we don't need pidof.
    # Tested the $? return for the stop script -- it does in fact propagate.
    # TODO: multiple postmasters.

    # PGVERSION is:  (note that PGVERSION is the major: 7.2.1 -> PGVERSION 7.2)
    PGVERSION=7.2

    # Source function library.
    INITD=/etc/rc.d/init.d
    $INITD/functions

    # Get function listing for cross-distribution logic.
    TYPESET=`typeset -f|grep "declare"`

    # Get config.
    . /etc/sysconfig/network

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

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


    start
    (){
        
    PSQL_START=$"Starting postgresql service: "
        
        
    # Check for older PGDATA location.
        
    if [ -/var/lib/pgsql/PG_VERSION ] && [ -/var/lib/pgsql/base/template1 ]
        
    then
            export PGDATA
    =/var/lib/pgsql
        
    else
            
    export PGDATA=/var/lib/pgsql/data
        fi

        
    # Check for the PGDATA structure
        
    if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
        
    then
        
    # Check version of existing PGDATA

            
    if [ `cat $PGDATA/PG_VERSION` != '7.2' ]
            
    then
                SYSDOCDIR
    ="(Your System's documentation directory)"
                
    if [ -/usr/doc/postgresql-$PGVERSION ]
                
    then
                    SYSDOCDIR
    =/usr/doc
                fi
                
    if [ -/usr/share/doc/postgresql-$PGVERSION ]
                
    then
                    SYSDOCDIR
    =/usr/share/doc
                fi
                
    if [ -/usr/doc/packages/postgresql-$PGVERSION ]
                
    then
                    SYSDOCDIR
    =/usr/doc/packages
                fi
                
    if [ -/usr/share/doc/packages/postgresql-$PGVERSION ]
                
    then
                    SYSDOCDIR
    =/usr/share/doc/packages
                fi
                
    echo
                echo $
    "An old version of the database format was found.\nYou need to upgrade the data format before using PostgreSQL.\nSee $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information."
                
    exit 1
    #                       This doesn't seem to do anything useful...
    #        else
    #            if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
    #            then
    #                success "$PSQL_CHECK"
    #            else
    #                echo "  [ OK ]"
    #            fi
    #            echo
            
    fi

        
    # No existing PGDATA! Initdb it.

        
    else
                echo -
    $"Initializing database: "
                    
    if [ ! -d $PGDATA ]
            
    then
                mkdir 
    -p $PGDATA
                chown postgres
    .postgres $PGDATA
            fi
            
    # Make sure the locale from the initdb is preserved for later startups...
            
    [ -/etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n
            
    # Just in case no locale was set, use en_US
            
    [ ! -/etc/sysconfig/i18n ] && echo "LANG=en_US" $PGDATA/../initdb.i18n 
            
    # Is expanded this early to be used in the command su runs
            
    echo "export LANG LC_ALL LC_CTYPE LC_COLLATE LC_NUMERIC LC_CTYPE LC_TIME" >> $PGDATA/../initdb.i18n
            
    # Initialize the database
            
    su -l postgres -/bin/sh -"/usr/bin/initdb --pgdata=/var/lib/pgsql/data > /dev/null 2>&1" < /dev/null
            
    [ -f $PGDATA/PG_VERSION ] && echo_success
            
    [ ! -f $PGDATA/PG_VERSION ] && echo_failure
            
    echo
         
    fi

        
    # Check for postmaster already running...
        
    pid=`pidof -s postmaster`
        if [ 
    $pid ]
        
    then
            
    echo $"Postmaster already running."
        
    else
            
    #all systems go -- remove any stale lock files
            
    rm -/tmp/.s.PGSQL.* > /dev/null
            
    echo -"$PSQL_START"
            
    su -l postgres -/bin/sh -"/usr/bin/pg_ctl  -D $PGDATA -p /usr/bin/postmaster start  > /dev/null 2>&1" < /dev/null
             sleep 1
             pid
    =`pidof -s postmaster`
             if [ 
    $pid ]
            
    then
                
    if echo "$TYPESET"|grep "declare -f success ()" >/dev/null
                then
                    success 
    "$PSQL_START"
                
    else
                    echo 
    "  [ OK ]"
                
    fi
                touch 
    /var/lock/subsys/postgresql
                
    echo $pid > /var/run/postmaster.pid
                
    echo
            else
                if echo 
    "$TYPESET"|grep "declare -f failure ()" >/dev/null
                then
                    failure 
    "$PSQL_START"
                
    else
                    echo 
    " [ FAILED ]"
                
    fi
                
    echo
            
    fi
        fi
    }

    stop(){
        echo -
    $"Stopping postgresql service: "
        
    # Check for older PGDATA location.
        
    if [ -/var/lib/pgsql/PG_VERSION ] && [ -/var/lib/pgsql/base/template1 ]
        
    then
            export PGDATA
    =/var/lib/pgsql
        
    else
            
    export PGDATA=/var/lib/pgsql/data
        fi
        su 
    -l postgres -/bin/sh -"/usr/bin/pg_ctl stop -D $PGDATA -s -m fast" > /dev/null 2>&1
            ret
    =$? 
            if [ 
    $ret -eq 0 ]; then
            echo_success
            
    else
                
    echo_failure
            fi
        
    echo
        
    rm -/var/run/postmaster.pid
        rm 
    -/var/lock/subsys/postgresql
    }

    restart(){
        
    stop
        start
    }

    condrestart(){
        [ -
    /var/lock/subsys/postgresql ] && restart || :
    }

    reload(){
        
    su -l postgres -/bin/sh -"/usr/bin/pg_ctl reload -D $PGDATA -s" > /dev/null 2>&1
    }

    # 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
    )
        
    start
        
    ;;
      
    stop)
        
    stop
        
    ;;
      
    status)
        
    status postmaster
        
    ;;
      
    restart)
        
    restart
        
    ;;
      
    condrestart)
        
    condrestart
        
    ;;
      
    reload|force-reload)
        
    reload
        
    ;;
      *)
        echo $
    "Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
        
    exit 1
    esac

    exit 
    Last edited by Ted Striker; November 7th, 2002 at 11:28 AM.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Chennai, India
    Posts
    69
    Rep Power
    13
    Originally posted by Ted Striker
    You are able to start postgres manually, right? When you watch the boot screen, does it give you any error messages, or does it just say, "Starting Postgres [FAILED]"

    Hi Ted

    I start and shutdown postgres with the following code:
    Code:
    startup:
    postmaster -i -D /var/lib/pgsql/data > logfile 2>&1 &
    
    shutdown:
    kill -INT `head -1 /var/lib/pgsql/data/postmaster.pid`
    BTW, when I grep on dmesg, I don't get any messages related to postgres startup ! The same with /var/log/messages.
    The listing of /etc/init.d for the postgres script is as follows:


    [root@sun051 init.d]# ls -la post*
    -rwxr-xr-x 1 root root 6002 Nov 5 10:12 postgresql
    [root@sun051 init.d]#
    I've have copied your script for postgresql startup into /etc/init.d and rebooted, but no effect !

    I hope I'll be able to automate the startup of PostgreSQL.

    Thanks you for your valuable input.

    Best Regards.
    Last edited by ggnanaraj; November 7th, 2002 at 10:58 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13
    Run this script manually:

    . /etc/rc.d/init.d/postgresql start

    And see if it works, and if it does not, what output
    it returns.

    It's also not a good idea to shutdown postgres using KILL, instead check in that script, there is a pretty good command there for shutting it down, like this one:

    PHP Code:

    su 
    -l postgres -/bin/sh -"/usr/bin/pg_ctl stop -D $PGDATA -s -m fast" > /dev/null 2>&
    Also, in your scripts, check to make sure that you have the $PGDATA variable defined to where your database data is.

    Finally, in your start command, it helps to specify a Postgres specific log file, this can be extremely helpful as it might say why the postmaster isn't starting.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Chennai, India
    Posts
    69
    Rep Power
    13
    Originally posted by Ted Striker
    Run this script manually:
    . /etc/rc.d/init.d/postgresql start
    And see if it works, and if it does not, what output it returns.
    [root@sun051 root]# pwd
    /root
    [root@sun051 root]# ./etc/rc.d/init.d/postgresql start
    bash: ./etc/rc.d/init.d/postgresql: No such file or directory
    [root@sun051 root]#

    Also, in your scripts, check to make sure that you have the $PGDATA variable defined to where your database data is.
    The script seems to check it on its own ..??
    # Check for older PGDATA location.
    if [ -f /var/lib/pgsql/PG_VERSION ] && [ -d /var/lib/pgsql/base/template1 ]
    then
    export PGDATA=/var/lib/pgsql
    else
    export PGDATA=/var/lib/pgsql/data
    fi
    PGDATA=/var/lib/pgsql/data is right.

    Finally, in your start command, it helps to specify a Postgres specific log file, this can be extremely helpful as it might say why the postmaster isn't starting.
    [root@sun051 root]# ./etc/rc.d/init.d/postgresql start > logfile 2>&1
    [root@sun051 root]# cat logfile
    bash: ./etc/rc.d/init.d/postgresql: No such file or directory

    Thank you for your valuable input.
    Last edited by ggnanaraj; November 8th, 2002 at 12:10 AM.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13

    Red face


    Oops, my mistake take the . off the command:

    ./etc/rc.d/init.d/postgresql

    and rerun like this:

    /etc/rc.d/init.d/postgresql start

    If you still get the "not found" message, then

    # cd /etc/rc.d/init.d
    # postgresql start

    or

    # cd /etc/rc.d/init.d
    # ./postgresql start
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Chennai, India
    Posts
    69
    Rep Power
    13
    Nope!


    [root@sun051 init.d]# ./postgresql start > logfile 2>&1
    [root@sun051 init.d]# cat logfile
    [root@sun051 init.d]# psql
    psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13
    Try it just like this:

    # ./postgresql start

    So if there is output it goes directly to the screen.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13
    The other thing you can do is put your command that you use to start it up manually into your own script and have that script run manually at boot time.

IMN logo majestic logo threadwatch logo seochat tools logo