Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMOYC-0006Xa-02 for pgsql-bugs@postgresql.org; Thu, 11 Oct 2012 19:36:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMOYA-0006IZ-Pd for pgsql-bugs@postgresql.org; Thu, 11 Oct 2012 19:36:07 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q9BJa2oF025455; Thu, 11 Oct 2012 15:36:02 -0400 (EDT) From: Tom Lane To: Heikki Linnakangas cc: Pg Bugs , Dave Vitek Subject: Re: Fwd: race in pg_ctl start -w In-reply-to: <50771713.8000908@vmware.com> References: <5076F626.2090404@grammatech.com> <5076FF23.6020704@iki.fi> <22107.1349976592@sss.pgh.pa.us> <50771713.8000908@vmware.com> Comments: In-reply-to Heikki Linnakangas message dated "Thu, 11 Oct 2012 21:59:31 +0300" Date: Thu, 11 Oct 2012 15:36:02 -0400 Message-ID: <25454.1349984162@sss.pgh.pa.us> X-Pg-Spam-Score: -4.0 (----) X-Archive-Number: 201210/98 X-Sequence-Number: 34398 Heikki Linnakangas 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