Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dtJhp-0007wE-C2 for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Sep 2017 20:28:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dtJho-0001Y8-Lx for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Sep 2017 20:28:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dtJgG-0007EX-Il for pgsql-hackers@postgresql.org; Sat, 16 Sep 2017 20:27:12 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dtJgC-0005FK-TV for pgsql-hackers@postgresql.org; Sat, 16 Sep 2017 20:27:12 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2D4F922A5C; Sat, 16 Sep 2017 16:27:07 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Sat, 16 Sep 2017 16:27:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=gEEETcXME+OdTGc7WD P8Rx19cd6T0jWYMoLeHy+0QEQ=; b=sQaoqBOa7rPsjavarVoJ1knTO3Pm8VOmuZ 64IXaLKDxFFo7K+rFMf+Rsq+Opfcv3nLES7NFQ3Krj7YEgP8gdczLZa3+g6z3G88 q6glWzmEaBabLK7QtFjEusY8ClY8biyIA2gtCG0qqN1YG5GQa8XrBqvApHmp9S02 LnZC6EX6e0C7GNIIrMbJhzIWYxIjuoXEptpqcQBq9lsSuHmcbTi/z5dZLJYJcdTI /07oiRDx7/6rPtBGiJNgmNSl3hgIKl5VZixoEyYIUVHelZBGUqVnD45bRR+QKxXl tN68MNiVpemMQ3yhQ1awflGv/oO95islpt3INqyWvx/eueJpyt1w== X-ME-Sender: X-Sasl-enc: WpQIDXTZyQFFvDVzY4ev1z+bCgq5BTtEYWnaw9Sa/VJS 1505593626 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id D76167F96A; Sat, 16 Sep 2017 16:27:06 -0400 (EDT) Date: Sat, 16 Sep 2017 13:27:05 -0700 From: Andres Freund To: Tom Lane Cc: pgsql-hackers@postgresql.org Subject: Re: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup. Message-ID: <20170916202705.lhszupzi3s4iaxy6@alap3.anarazel.de> References: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <27204.1505591941@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2017-09-16 15:59:01 -0400, Tom Lane wrote: > Andres Freund 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