Re: Fwd: race in pg_ctl start -w

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Pg Bugs <pgsql-bugs(at)postgresql(dot)org>, Dave Vitek <dvitek(at)grammatech(dot)com>
Subject: Re: Fwd: race in pg_ctl start -w
Date: 2012-10-11 19:36:02
Message-ID: 25454.1349984162@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> writes:
> Hmm, starting with 9.3, postmaster can not only create and append to the
> end of file, it can also inject a line in the middle, shifting the
> following lines forwards. In theory, if a new line is injected into the
> middle of the file between fgets() calls, readfile() could read part of
> the same line twice. Not sure what consequences that could have; pg_ctl
> might try to connect to wrong address or socket directory.

Hm. IIRC, the postmaster is careful to write the whole thing in a
single write() call, which in principle is atomic. Perhaps you're
right that we'd better have pg_ctl read it in a single read() to
ensure that it sees a consistent file state. Otherwise we're making
assumptions about what sort of buffering underlies the stdio functions.

> Then again, I don't think read/write on a
> file is guaranteed to be atomic either, so I guess there's always the
> theoretical possibility of a partial read.

I think it is as long as the file is less than a bufferload.

> This makes me a bit uncomfortable with the 9.3 change that
> postmaster.pid file is no longer strictly append-only (commit c9b0cbe9).
> Could we delay appending the socket directory and listen address
> information to the file until we know both, and then append both in one
> call after that?

IIRC, there were compatibility reasons for doing it that way, so I'm
disinclined to change it.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message david.peyrieres 2012-10-12 06:03:55 Re: BUG #7596: Problem with /etc/init.d/postgresql.9.x file
Previous Message Heikki Linnakangas 2012-10-11 18:59:31 Re: Fwd: race in pg_ctl start -w