Re: BUG #16154: pg_ctl restart with a logfile fails sometimes (on Windows)

From: Alexander Law <exclusion(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16154: pg_ctl restart with a logfile fails sometimes (on Windows)
Date: 2019-12-07 21:00:00
Message-ID: CAJ0YPFGG9J8TDZ9pBcSt7dNjW4Gj=cdg8+-kHrhJQP2q8=0U9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

07.12.2019 22:26 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> Alexander Law <exclusion(at)gmail(dot)com> writes:
>
>
> > The possible solution is to rid of CMD and to call CreateProcess with
> > postgres.exe as an executable, but then we have to handle it's stdout,
> > stderr pipes like this:
> >
> https://docs.microsoft.com/en-us/windows/win32/procthread/creating-a-child-process-with-redirected-input-and-output
> > I'm afraid this would complicate things (and break an alignment with the
> > Unix solution), but if the uglyness of the proposed fix overweights
> > complexity concerns, I can try to develop an alternative patch.
>
> If it takes that much code to handle redirection on Windows, then
> I agree we don't really want to do it :-(.
>
> Your solution is a little bit messy but it seems expedient. I feel
> that it doesn't really fix the problem, if we define the problem as
> "somebody opened the postmaster logfile with non-sharing-friendly
> parameters".

I see two problems here:
1) "pg_ctl restart ... -l logfile" can fail due to timing issues
2) when it (or "pg_ctl start ... -l logfile") fails, it prints the
non-informative message:
The process cannot access the file because it
is being used by another process.
It doesn't tell the user what file is inaccessible. I think that this issue
remains unresolved for so long partly due to this unclearance. The proposed
patch fixes both, unless I miss something.

This patch works around that for the specific case of
> a series of pg_ctl start commands with identical -l arguments, but
> the file's still not really sharable.

Yes, even if someone would manage to lock the logfile by a separate program
or by starting another postgres cluster with the same logfile, he will get
a more meaningful message (after a timeout).

> Still, maybe that's good
> enough. For our own purposes in buildfarm testing, the main residual
> problem is that we can't safely inspect the postmaster logfile
> immediately after pg_ctl stop; but there's a separate proposal to
> fix that by hacking slurp_file.
>
As to slurp_file, maybe it's read-only nature should help to avoid the
issues with the logfile opening. I can test it next week.

>
> It seems like it'd be cleaner to fix both of these things at once
> by opening the logfile ourselves (rather than letting CMD.EXE do it)
> and using sharing-friendly parameters at that point. But maybe it's
> just not worth the trouble compared to the individual hacks.

If we couldn't find more advantages of rewriting create process (with
logfile), I would restrict changes to one hack (or two, if really needed).

Best regards,
Alexander

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jan Przemysław Wójcik 2019-12-08 11:43:18 Unexpected extra row from jsonb_path_query() with a recursive path
Previous Message Tom Lane 2019-12-07 19:26:06 Re: BUG #16154: pg_ctl restart with a logfile fails sometimes (on Windows)