Re: pg_ctl promote wait

From: Andres Freund <andres(at)anarazel(dot)de>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_ctl promote wait
Date: 2016-02-19 19:15:34
Message-ID: 20160219191534.yunti6ppenvqpqms@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2016-02-19 13:48:52 -0500, Peter Eisentraut wrote:
> Is it safe to read pg_control externally without a lock? pg_controldata
> will just report a CRC error and proceed, and if you're not sure you can
> just run it again. But if a promotion fails every so often because of
> concurrent pg_control writes, that would make this feature annoying.

Yes, the OS should give sufficient guarantees here:

If write() is interrupted by a signal before it writes any data, it shall return −1 with errno set to [EINTR].

If write() is interrupted by a signal after it successfully writes some data, it shall return the number of bytes written.

If the value of nbyte is greater than {SSIZE_MAX}, the result is implementation-defined.

After a write() to a regular file has successfully returned:

* Any successful read() from each byte position in the file that was modified by that write shall return the data specified
by the write() for that position until such byte positions are again modified.

We currently assume that all "small" writes succeed in one go (and throw
errors if not). Thus the guarantees by read/write are sufficient.

Regards,

Andres

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2016-02-19 19:16:49 Re: pg_ctl promote wait
Previous Message Peter Eisentraut 2016-02-19 18:58:30 Re: pg_ctl promote wait