Hello !

Server rebooted occasionally after power failure.
And I have stale postmaster.pid file, so postmaster didn't start with error
   bill postgres[600]: [1-1] FATAL:  file "postmaster.pid" already exists

I think startup script and/or pg_ctl have to be written to check if that process really exists
and it is postmaster, so DBMS server starts after any hard reboot.

I changed the startup script block

   postgresql_command()
   {
su -l ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
   }

to

postgresql_cmd()
{
su -l ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
}
postgresql_command()
{
       if [ ".$1" = ".start" ]; then
               pidfile="${postgresql_data}/postmaster.pid"
               if [ -e ${pidfile} ]; then
                       #check if postmaster process really exists
                       pid_fromfile=`head -1 ${pidfile}`
real_pid=`ps ax | grep -v grep | grep postmaster | grep ${postgresql_data} | awk '{print $1}'`
                       if [ "x${pid_fromfile}" = "x${real_pid}" ]; then
echo "Postmater for datadir ${postgresql_data} already run with pid $real_pid"
                       else
                               #we have stale pidfile, remove it
                               unlink $pidfile
                               #and run postmater safely
                               postgresql_cmd
                       fi
               else
                       #.pid file not exists, clean startup
                       postgresql_cmd
               fi
       else
               postgresql_cmd
       fi
}

That I hope satisfy all cases with stale .pid file...

--
Ruslan A Dautkhanov

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to