From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Subject: Re: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup.
Date: Sat, 16 Sep 2017 13:27:05 -0700
Message-ID: <20170916202705.lhszupzi3s4iaxy6@alap3.anarazel.de> (raw)
In-Reply-To: <27204.1505591941@sss.pgh.pa.us>
References: <E1dsbXB-0006pK-EE@gemulon.postgresql.org>
<14134.1505572349@sss.pgh.pa.us>
<20170916182634.blb7upixw7hosdhu@alap3.anarazel.de>
<23456.1505586621@sss.pgh.pa.us>
<20170916183849.kgqlyi3q2oy4qjkx@alap3.anarazel.de>
<27204.1505591941@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 2017-09-16 15:59:01 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2017-09-16 14:30:21 -0400, Tom Lane wrote:
> >> I wonder whether we shouldn't just revert this patch altogether.
>
> > The problem is that the patch that makes the segment size configurable
> > also adds a bunch more ordering constraints due to the fact that the
> > contents of the control file influence how much shared buffers are
> > needed (via wal_buffers = -1, which requires the segment size, which is
> > read from the control file). Reading things in the wrong order leads to
> > bad results too.
>
> Maybe we could redefine wal_buffers to avoid that. Or read the control
> file at the time where we need it.
I'm curious - do you have a good idea how to do so? It's a bit too much
magic right now (assuming the wal_segment_size patch is applied),
depending on both wal_segment_size and shared_buffers.
> This does not seem like a problem that justifies a system-wide change
> that's much more delicate than you thought.
We need one more initialization call during crash-restart - that doesn't
seem particularly hard a fix. And see below, the alternatives aren't
pretty.
> >> I'm now quite worried about whether we aren't introducing
> >> hazards of using stale values from the file; if a system crash isn't
> >> enough to get it to flush its cache, then what is?
>
> > I don't think the problem here is stale values, it's "just" a stale
> > pointer pointing into shared memory that gets reiniitalized?
>
> The code that's crashing is attempting to install some pre-existing
> copy of pg_control into shared memory. Even if there were good reason
> to think the copy were up to date, I'm not sure we should trust it
> in a crash recovery context.
We definitely should re-read it, agreed. Note there's not really a copy
here, we just assume so because the ControlFile variable isn't NULL - in
hindsight a separate bool signalling the existance of the already read
data would've probably been a good idea.
> I'd rather see this hunk of code just playing dumb and reading the
> file (which, I'm pretty sure, is what it did up till this week).
The problem is that every process needs the results of the
ReadControlFile() call. Which adjusts GUCs and other process local
variables. We can either start ferrying a lot more knowledge through
the backend variable stuff, by adding a bunch more special-case code to
the restore patch, or we're going to have to execute ReadControlFile()
in EXEC_BACKEND processes. But we can't do so once shared memory is
set-up because that'd constantly happen while other processes write to
the ControlFile.
Therefore my approach was to do a ReadControlFile() into local memory at
postmaster start (missing the crash-restart case that should also have
done so), and only do other reads in the EXEC_BACKEND case, before it
uses shared memory.
Alternatively or additionally we could split ReadControlFile() into two
parts, one that does various SetConfigOption({data_checksums,
wal_segment_size})s, computes UsableBytesInSegment etc, and one that
actually reads the file. The former would then liberally sprinkled
everywhere, because it has only process-local effects.
Greetings,
Andres Freund
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: andres@anarazel.de, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org
Subject: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup.
In-Reply-To: <20170916202705.lhszupzi3s4iaxy6@alap3.anarazel.de>
References: <E1dsbXB-0006pK-EE@gemulon.postgresql.org> <14134.1505572349@sss.pgh.pa.us> <20170916182634.blb7upixw7hosdhu@alap3.anarazel.de> <23456.1505586621@sss.pgh.pa.us> <20170916183849.kgqlyi3q2oy4qjkx@alap3.anarazel.de> <27204.1505591941@sss.pgh.pa.us> <20170916202705.lhszupzi3s4iaxy6@alap3.anarazel.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox