Re: BUG #19610: Database won't start if an unrelated process is exist

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Cc: Daniel Gustafsson <daniel(at)yesql(dot)se>, scherbakov_lo_radarmms(at)mail(dot)ru, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19610: Database won't start if an unrelated process is exist
Date: 2026-08-12 12:51:41
Message-ID: 2622434.1786539101@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre(at)kurilemu(dot)de> writes:
> Well, I'm not sure this is really intended. I'd say it's rather
> emergent behavior from what we can do, which is to inquiry whether a
> process with that PID exist or not; and if it does, we assume it's the
> postmaster and give up. But maybe there are ways to verify whether it's
> really a postmaster that indeed corresponds to that .pid file; so that
> if we can determine it's not, then the .pid file is stale and we can
> remove it and move on.

We already check that the PID belongs to our own UID, and is not our
parent or grandparent. I doubt there is more that we can do portably.
We've already expended a bunch of sweat in this direction,
eg commit 8f5500e6b.

To my mind, this false-positive is only likely to happen if you have
a bunch of unrelated stuff getting run under the same UID, which is
already a security problem of the first magnitude. Don't do that:
create a dedicated UID for each Postgres instance you plan to run.

> If we get it wrong, the user ends up with corrupt data which definitely
> is not nice.

Yeah. Erring in the direction of thinking it's safe when it isn't
is far worse than erring in this direction.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-08-12 15:14:16 Re: pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found
Previous Message Álvaro Herrera 2026-08-12 11:26:14 Re: BUG #19610: Database won't start if an unrelated process is exist