pgsql: Try again to work around Windows' ERROR_SHARING_VIOLATION in pg_

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Try again to work around Windows' ERROR_SHARING_VIOLATION in pg_
Date: 2020-02-16 17:20:29
Message-ID: E1j3Nan-0003AI-4d@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Try again to work around Windows' ERROR_SHARING_VIOLATION in pg_ctl.

Commit 0da33c762 introduced an unfortunate regression in pg_ctl on
Windows: if the log file specified with -l doesn't exist yet, and
pg_ctl is running with Administrator privileges, then the log file
might get created with permissions that prevent the postmaster from
writing on it. (It seems that whether this happens depends on whether
the log file is inside the user's home directory or not, and perhaps
on other phase-of-the-moon conditions, which may explain why we failed
to notice it sooner.)

To fix, just don't create the log file if it doesn't exist yet. The
case where we need to wait obviously only occurs with a pre-existing
log file.

In passing, switch from using fopen() to plain open(), saving a few
cycles.

Per bug #16259 from Jonathan Katz and Heath Lord. Back-patch to v12,
as the faulty commit was.

Alexander Lakhin

Discussion: https://postgr.es/m/16259-c5ebed32a262a8b1@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e02ea141ee66e5b2372e1eb2d2000b7ed3a8e13a

Modified Files
--------------
src/bin/pg_ctl/pg_ctl.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2020-02-17 07:05:19 pgsql: Add description about LogicalRewriteTruncate wait event into doc
Previous Message Tom Lane 2020-02-16 15:51:46 Re: pgsql: Logical Tape Set: lazily allocate read buffer.