From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Sullivan <andrew@libertyrms.info>
Cc: pgsql-admin@postgresql.org
Subject: Re: auto removing stale pid for postmaster NT service
Date: Mon, 16 Sep 2002 17:27:38 -0400
Message-ID: <2208.1032211658@sss.pgh.pa.us> (raw)
In-Reply-To: <20020916164129.W4394@mail.libertyrms.com>
References: <OFB91CFC47.33257F49-ON85256C31.00654C8C@putnaminv.com>
<26090.1032182629@sss.pgh.pa.us>
<20020916165546.9B98.TELLINI@areabusiness.it>
<20020916164129.W4394@mail.libertyrms.com>
Andrew Sullivan <andrew@libertyrms.info> writes:
> This is because there is a process with the same pid as the
> postmaster. This will happen in cases where the machine crashes and
> starts up again -- something else happens to get the (former)
> postgres pid at startup, and so when postgres checks for a process
> with that pid, one exists. And kerplooey.
FYI, sendmail has the same restart failure mode; I imagine a lot of
other Unix daemons do too.
> I seem to recall that someone (maybe Tom Lane?) suggested an
> extension to the current pidfile check, so that it will also check to
> see if the process really is PostgreSQL. But I don't know if it was
> implemented.
It wasn't yet, mainly because it's not obvious how to tell reliably
whether some other process is a postmaster or not.
I think I had suggested distinguishing EPERM from other kill() errors,
which would tell us whether the other process is under the same userid
as us or not; if not, we could perhaps safely assume that it's not a
postmaster (or at least not one likely to be using our data directory).
Unfortunately, that doesn't really improve the odds very much. The
typical scenario for this problem is that the PID we get assigned will
wobble around by one or two counts from one boot cycle to the next,
depending on just how fast other startup processes manage to finish.
(If we get the exact same PID as before, there's no problem; the code
is smart enough to notice that case.) But the PID(s) adjacent to the
postmaster's will likely also belong to the postgres user --- consider
the shell that launched us, for example. The shell, or whatever it
might launch right after the postmaster, would look enough like a
postmaster to fool this simplistic test.
So I'm at a loss how the postmaster can improve the reliability of this
check, without throwing the baby out with the bathwater by making a
check that might fail to recognize a conflicting postmaster. The
consequences of that would be *dire*.
The best solution is probably to forcibly unlink the postmaster.pid
file in some startup script --- but it has to be a script that is *only*
run during boot, never anytime later. The postgres start script is
not the place for this.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, andrew@libertyrms.info
Subject: Re: auto removing stale pid for postmaster NT service
In-Reply-To: <2208.1032211658@sss.pgh.pa.us>
References: <OFB91CFC47.33257F49-ON85256C31.00654C8C@putnaminv.com> <26090.1032182629@sss.pgh.pa.us> <20020916165546.9B98.TELLINI@areabusiness.it> <20020916164129.W4394@mail.libertyrms.com> <2208.1032211658@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox