On 11.10.2012 20:29, Tom Lane wrote:
Heikki Linnakangas<hlinn...@iki.fi>  writes:
A straightforward fix would be to just allocate one large-enough buffer
to begin with, e.g 8k, and read the whole file in one go. I'll write up
a patch for that.

This makes the readfile function very usage-specific though.  The fix
I was thinking about was to modify the second loop to force it to fall
out once the predetermined number of lines had been read.

Or maybe we should use just one loop with realloc, instead of reading
the file twice.

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.

Although in practice, fgets() is buffered, and the buffer is probably large enough to hold the whole file, so it probably gets slurped into memory as one unit anyway. 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.

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?

Gah, how can a trivial thing like this be so complicated..

- Heikki


--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to