| From: | Adis Nezirovic <adis(at)linux(dot)org(dot)ba> | 
|---|---|
| To: | Andreas Joseph Krogh <andreak(at)officenet(dot)no> | 
| Cc: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: file-locking and postmaster.pid | 
| Date: | 2006-05-23 16:35:11 | 
| Message-ID: | 20060523163511.GA12309@hiigarah.team.ba | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On Tue, May 23, 2006 at 05:23:16PM +0200, Andreas Joseph Krogh wrote:
> Hi all.
> 
> I've experienced several times that PG has died somehow and the postmaster.pid 
> file still exists 'cause PG hasn't had the ability to delete it upon proper 
> shutdown. Upon start-up, after such an incidence, PG tells me another PG is 
> running and that I either have to shut down the other instance, or delete the 
> postmaster.pid file if there really isn't an instance running. This seems 
> totally unnecessary to me. Why doesn't PG use file-locking to tell if another 
> PG is running or not? If PG holds an exclusive-lock on the pid-file and the 
> process crashes, or shuts down, then the lock(which is process-based and 
> controlled by the kernel) will be removed and another PG which tries to start 
> up can detect that. Using the existence of the pid-file as the only evidence 
> gives too many false positives IMO.
Well, maybe you could tweak postgres startup script, add check for post
master (either 'pgrep postmaster' or 'ps -axu | grep [p]ostmaster'), and
delete pid file on negative results.
i.e.
#!/bin/bash
PID=`pgrep -f /usr/bin/postmaster`;
if [[ $PID ]]; then
    echo "'$PID'";
    # postgres is already running
else
    echo "Postmaster is not running";
    # delete stale PID file
fi
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Simon Riggs | 2006-05-23 16:45:11 | Re: error-free disabling of individual child partition | 
| Previous Message | Tom Lane | 2006-05-23 16:25:48 | Re: file-locking and postmaster.pid |