Thread: Postmaster failing to start on reboot

Postmaster failing to start on reboot

From
"surabhi.ahuja"
Date:
Hello everyone,
 
I reboot my machine while postmaster is up.
 
after the m/c gets rebooted ,
I grep for the process "postmaster", and it does not find it.
 
So,  I try starting postmaster. and it displays the following error message:
HINT:  If you're sure there are no old server processes still running, remove the shared memory block with the command "ipcr
m", or just delete the file "/export/home1/sdc_image_pool/dbx/postmaster.pid".
 
does it means that i will have to delete the postmaster.pid file ..in such a scenarion always?
 
thanks,
regards
Surabhi Ahuja
 
 

Re: Postmaster failing to start on reboot

From
Richard Huxton
Date:
surabhi.ahuja wrote:
> Hello everyone,
>
> I reboot my machine while postmaster is up.
>
> after the m/c gets rebooted , I grep for the process "postmaster",
> and it does not find it.
>
> So,  I try starting postmaster. and it displays the following error
> message: HINT:  If you're sure there are no old server processes
> still running, remove the shared memory block with the command "ipcr
> m", or just delete the file
> "/export/home1/sdc_image_pool/dbx/postmaster.pid".
>
> does it means that i will have to delete the postmaster.pid file ..in
> such a scenarion always?

No, only when it doesn't close down properly. Check your system logs to
see what happened.

--
   Richard Huxton
   Archonet Ltd

Re: Postmaster failing to start on reboot

From
Tom Lane
Date:
Richard Huxton <dev@archonet.com> writes:
> surabhi.ahuja wrote:
>> So,  I try starting postmaster. and it displays the following error
>> message: HINT:  If you're sure there are no old server processes
>> still running, remove the shared memory block with the command "ipcr
>> m", or just delete the file
>> "/export/home1/sdc_image_pool/dbx/postmaster.pid".
>>
>> does it means that i will have to delete the postmaster.pid file ..in
>> such a scenarion always?

> No, only when it doesn't close down properly. Check your system logs to
> see what happened.

Also, what PG version is this exactly?  More recent versions have better
defenses against being fooled by stale postmaster.pid files.  It matters
what postmaster startup script you're using, too.

            regards, tom lane

Re: Postmaster failing to start on reboot

From
"surabhi.ahuja"
Date:
i am using PostgreSQL 8.0.0
and the statrtup script i am using is as follows:
 
 
*****
#! /bin/sh
# dbxd    Script for starting up the PostgreSQL
#               server in the daemon mode
#
#

# postgreSQL version is:
PGVERSION=8.0
# Name of the script
NAME=dbxd
# Command issued start/stop/restart
action="$1"
# Get SDC configiration
#   . $SDCHOME/.SdCrc
# Set defaults for port and database directory
POSTGRES_LOG="$SDCHOME/nuevo/logfiles/postgreslog"
if [ "`uname`" = "Linux" ]; then
   #DEVMACHINE=`file /export/dbsroot | grep -c directory`
   POSTMASTER=/usr/bin/postmaster
   PGCTL="/usr/bin/pg_ctl -w "
   INITDB=/usr/bin/initdb
   PGDATA=$SdC_IMAGE_POOL/dbx
   PGPORT=5432
else
   echo "Cannot launch POSTGRES , unknown OS"
   echo " [ FAILED ]"
   exit 1
fi
if [ "`uname`" = "Linux" ]; then
   INITD=/etc/rc.d/init.d
   . $INITD/functions
   # Get config.
   . /etc/sysconfig/network
fi
# Check that networking is up.
# Pretty much need it for postmaster.
if [ "`uname`" = "Linux" ]; then
   [ "${NETWORKING}" = "no" ] && exit 0
fi
start(){
        # Check for the PGDATA structure
        if [ -f $PGDATA/PG_VERSION ] && [ -d $PGDATA/base ]
        then
        # Check version of existing PGDATA
                INSTPG_VERSION=`cat $PGDATA/PG_VERSION`
                if [ $INSTPG_VERSION != '8.0' -a $INSTPG_VERSION != '8.1' ]
                then
                        echo "An old version of the database format was found.\n"
                        exit 1
                fi
        else
        # No existing PGDATA - call initdb
                echo "Initializing database: "
                #chmod 755 /var/lib/pgsql
                if [ ! -d $PGDATA ]
                then
                        mkdir -p $PGDATA
                fi
                chown $SDCUSER:$SDCUSER $PGDATA
                chmod go-rwx $PGDATA
                # Make sure the locale from the initdb is preserved for later startups...
                [ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n $PGDATA/../initdb.i18n
                # Just in case no locale was set, use en_US on Linux
                if [ "`uname`" = "Linux" ]; then
                        [ ! -f /etc/sysconfig/i18n ] && echo "LANG=en_US" > $PGDATA/../initdb.i18n
                fi
                # Initialize the database
                if [ "`uname`" = "Linux" ]; then
                        /bin/sh -c "$INITDB --pgdata=$PGDATA > /dev/null 2>&1" < /dev/null
                fi
                # Modify original postgres settings so that local connection are trusted
                mv $PGDATA/pg_hba.conf $PGDATA/pg_hba.conf.orig
                cat $PGDATA/pg_hba.conf.orig | sed "s/^local.*/local   all    all    trust/" > $PGDATA/pg_hba.conf
                chown $SDCUSER:$SDCUSER $PGDATA/pg_hba.conf
                chmod 600 $PGDATA/pg_hba.conf
                rm $PGDATA/pg_hba.conf.orig
                #Copy the configuration file to the database - TBD
                #cp /export/home/sdc/database_scripts/config/postgresql.conf $PGDATA/
                #chown postgres:postgres $PGDATA/postgresql.conf
                #chmod 600 $PGDATA/postgresql.conf
        fi
        # Check for postmaster already running...
        # note that pg_ctl only looks at the data structures in PGDATA
        # you really do need the pidof()
        if [ "`uname`" = "Linux" ]; then
           pid=`pidof -s postmaster`
        else
           pid=`ps -eaf | grep postmaster | grep -v grep | tail -1 | awk '{print $2}'`
        fi
        if [ $pid ] && $PGCTL status -D $PGDATA > /dev/null 2>&1
        then
                echo "Postmaster already running."
        else
                if [ "`uname`" = "Linux" ]; then
                   #su -l postgres -s /bin/sh -c "$PGCTL -l $POSTGRES_LOG -D $PGDATA -p $POSTMASTER -o '-p ${PGPORT}' start
 > /dev/null 2>&1" < /dev/null
                   rm -f /tmp/.s.PGSQL.${PGPORT} > /dev/null
                   rm -f /tmp/.s.PGSQL.${PGPORT}.lock > /dev/null
                   /bin/sh -c "$PGCTL -l $POSTGRES_LOG -D $PGDATA -p $POSTMASTER -o '-p ${PGPORT}' start  > /dev/null 2>&1"
< /dev/null
               
fi
                sleep 1
                if [ "`uname`" = "Linux" ]; then
                   pid=`pidof -s postmaster`
                else
                   pid=`ps -eaf | grep postmaster | grep -v grep | tail -1 | awk '{print $2}'`
                fi
                if [ $pid ]
                then
                        #echo "success $PSQL_START"
                        echo_success
                else
                        #echo "failure $PSQL_START"
                        echo_failure
                fi
        fi
}
stop(){
        echo "Stopping ${NAME} service: "
        if [ "`uname`" = "Linux" ]; then
           #su -l postgres -s /bin/sh -c "$PGCTL stop -D $PGDATA -s -m fast" > /dev/null 2>&1
           /bin/sh -c "$PGCTL stop -D $PGDATA -s -m fast" > /dev/null 2>&1
        fi
       ret=$?
        if [ $ret -eq 0 ]
        then
                #echo "success"
                echo_success
        else
                echo_failure
                if [ "`uname`" = "Linux" ]; then
                   #su -l postgres -s /bin/sh -c "$PGCTL stop -D $PGDATA -s -m immediate" > /dev/null 2>&1
                   /bin/sh -c "$PGCTL stop -D $PGDATA -s -m immediate" > /dev/null 2>&1
                fi
        fi
        echo
}
case $action in
  start)
        start
        ;;
  stop)
        stop
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
        exit 1
esac
exit 0
*****
 
for starting postmaster i run dbxd start
and for shutting it down i run dbxd stop.
 
Can you please study it once and suggest if I have missed something.
 
Please see the highlighted section (in red) . do i also need to remove the pid file also . i mean with the other rm commands do i need to give rm -f $PGDATA /postmaster.pid also?
 
Thank You,
Regards
Surabhi


From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Wed 11/9/2005 9:23 PM
To: Richard Huxton
Cc: surabhi.ahuja; pgsql-general@postgresql.org
Subject: Re: [GENERAL] Postmaster failing to start on reboot

***********************
Your mail has been scanned by InterScan VirusWall.
***********-***********


Richard Huxton <dev@archonet.com> writes:
> surabhi.ahuja wrote:
>> So,  I try starting postmaster. and it displays the following error
>> message: HINT:  If you're sure there are no old server processes
>> still running, remove the shared memory block with the command "ipcr
>> m", or just delete the file
>> "/export/home1/sdc_image_pool/dbx/postmaster.pid".
>>
>> does it means that i will have to delete the postmaster.pid file ..in
>> such a scenarion always?

> No, only when it doesn't close down properly. Check your system logs to
> see what happened.

Also, what PG version is this exactly?  More recent versions have better
defenses against being fooled by stale postmaster.pid files.  It matters
what postmaster startup script you're using, too.

                        regards, tom lane


Re: Postmaster failing to start on reboot

From
"surabhi.ahuja"
Date:
The error
 
 "If you're sure there are no old server processes
> still running, remove the shared memory block with the command "ipcr
> m", or just delete the file
> "/export/home1/sdc_image_pool/dbx/postmaster.pid".
 
was looged in the Postgres Log file that i give at the time of starting postmaster.
how do i check my system logs to get further info?
I am sorry i am still in the learning phase .
 
thanks
Regards
Surabhi
 


From: Richard Huxton [mailto:dev@archonet.com]
Sent: Wed 11/9/2005 8:23 PM
To: surabhi.ahuja
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Postmaster failing to start on reboot

***********************
Your mail has been scanned by InterScan VirusWall.
***********-***********


surabhi.ahuja wrote:
> Hello everyone,
>
> I reboot my machine while postmaster is up.
>
> after the m/c gets rebooted , I grep for the process "postmaster",
> and it does not find it.
>
> So,  I try starting postmaster. and it displays the following error
> message: HINT:  If you're sure there are no old server processes
> still running, remove the shared memory block with the command "ipcr
> m", or just delete the file
> "/export/home1/sdc_image_pool/dbx/postmaster.pid".
>
> does it means that i will have to delete the postmaster.pid file ..in
> such a scenarion always?

No, only when it doesn't close down properly. Check your system logs to
see what happened.

--
   Richard Huxton
   Archonet Ltd


Re: Postmaster failing to start on reboot

From
"surabhi.ahuja"
Date:
Another thing that has been noted is ...sometimes if i run the command
 
dbxd stop.
it fails to bring down postmaster. What should be done in such a situation?
 
right now we do a kill -9 postmaster
 
Thanks
regards
Surabhi ahuja 


From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Wed 11/9/2005 9:23 PM
To: Richard Huxton
Cc: surabhi.ahuja; pgsql-general@postgresql.org
Subject: Re: [GENERAL] Postmaster failing to start on reboot

***********************
Your mail has been scanned by InterScan VirusWall.
***********-***********


Richard Huxton <dev@archonet.com> writes:
> surabhi.ahuja wrote:
>> So,  I try starting postmaster. and it displays the following error
>> message: HINT:  If you're sure there are no old server processes
>> still running, remove the shared memory block with the command "ipcr
>> m", or just delete the file
>> "/export/home1/sdc_image_pool/dbx/postmaster.pid".
>>
>> does it means that i will have to delete the postmaster.pid file ..in
>> such a scenarion always?

> No, only when it doesn't close down properly. Check your system logs to
> see what happened.

Also, what PG version is this exactly?  More recent versions have better
defenses against being fooled by stale postmaster.pid files.  It matters
what postmaster startup script you're using, too.

                        regards, tom lane


Re: Postmaster failing to start on reboot

From
Richard Huxton
Date:
surabhi.ahuja wrote:
> i am using PostgreSQL 8.0.0

You should upgrade to 8.0.4 as soon as is convenient - there are 4 sets
of bugfixes available.

> and the statrtup script i am using is as follows:
>
>
> *****
> #! /bin/sh
> # dbxd    Script for starting up the PostgreSQL
> #               server in the daemon mode
> #
> #
>
> # postgreSQL version is:
> PGVERSION=8.0
> # Name of the script
> NAME=dbxd
> # Command issued start/stop/restart
> action="$1"
> # Get SDC configiration
> #   . $SDCHOME/.SdCrc

I don't recognise this script. Can I ask two questions:

Q1. What distribution of Linux are you running?
Q2. How did you install PostgreSQL?
Q3. Have you made any changes to this script?

In another email you mention that this script sometimes doesn't stop PG.
This is the relevant block of code, and you can see that the line
starting "su -l postgres" has been commented out and replaced.

That's strange, because my copy of pg_ctl refuses to run as root.

> stop(){
>         echo "Stopping ${NAME} service: "
>         if [ "`uname`" = "Linux" ]; then
>            #su -l postgres -s /bin/sh -c "$PGCTL stop -D $PGDATA -s -m fast" > /dev/null 2>&1
>            /bin/sh -c "$PGCTL stop -D $PGDATA -s -m fast" > /dev/null 2>&1
>         fi
>        ret=$?
>         if [ $ret -eq 0 ]
>         then
>                 #echo "success"
>                 echo_success
>         else
>                 echo_failure
>                 if [ "`uname`" = "Linux" ]; then
>                    #su -l postgres -s /bin/sh -c "$PGCTL stop -D $PGDATA -s -m immediate" > /dev/null 2>&1
>                    /bin/sh -c "$PGCTL stop -D $PGDATA -s -m immediate" > /dev/null 2>&1
>                 fi
>         fi
>         echo
> }


> Please see the highlighted section (in red) .

Most people will be viewing this in text-mode (including me). They won't
see the red. It appears to be deleting the unix socket and lock *AFTER*
starting up PG. I don't understand how that makes sense.

Q4. Where did you get this script?

 > do i also need to remove the pid file also .

What, after starting PG? How could that make sense?

 > i mean with the other rm commands do i need to give
 > rm -f $PGDATA /postmaster.pid also?

The standard script should start and stop PostgreSQL quite successfully.
If it isn't working the first place to look is your logs.
--
   Richard Huxton
   Archonet Ltd

Re: Postmaster failing to start on reboot

From
Tom Lane
Date:
Richard Huxton <dev@archonet.com> writes:
> In another email you mention that this script sometimes doesn't stop PG.
> This is the relevant block of code, and you can see that the line
> starting "su -l postgres" has been commented out and replaced.
> That's strange, because my copy of pg_ctl refuses to run as root.

We added the no-root check to pg_ctl in 8.0beta4, so AFAICS this script
should *never* work to stop the postmaster if you are indeed dealing
with an 8.0.0 release.  The script change must have been made by someone
who was dealing with a pre-8.0 version (and even then, not one of the
later subreleases, because every branch since Oct 2004 has had this
check).

At least, it'd never work if executed by root.  It might work if
executed by postgres --- dunno whether any of the other stuff is
root-only.

In any case, the short answer is to get rid of this script and get
one that works properly ...

            regards, tom lane

Re: Postmaster failing to start on reboot

From
"surabhi.ahuja"
Date:
 hi,
 
in the script ithe statement to start and stop postmsater as the root is commented. thats how i saw the script( has been written by some one else)
 
will using 8.0.4 ensure proper starting and stopping of postmsater.
 
what abt the case in which the system is simply rebooted ...with postmsater already running)?
 
(attaching the script) again
 
thanks
regards
Surabhi
Attachment