Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oGIdB-0003vC-27 for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Jul 2022 11:21:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oGId8-00029N-82 for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Jul 2022 11:21:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oGId7-00027u-Uc for pgsql-hackers@lists.postgresql.org; Tue, 26 Jul 2022 11:21:37 +0000 Received: from mail.thelabyrinth.net ([45.56.70.56]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oGId3-0005vo-KM for pgsql-hackers@postgresql.org; Tue, 26 Jul 2022 11:21:37 +0000 Received: from [172.20.20.20] (c-24-126-12-6.hsd1.wv.comcast.net [24.126.12.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dsteele) by mail.thelabyrinth.net (Postfix) with ESMTPSA id 2684B54682; Tue, 26 Jul 2022 11:21:31 +0000 (UTC) Message-ID: Date: Tue, 26 Jul 2022 07:21:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: Race between KeepFileRestoredFromArchive() and restartpoint Content-Language: en-US To: Noah Misch , pgsql-hackers@postgresql.org, Kyotaro Horiguchi References: <20210202151416.GB3304930@rfd.leadboat.com> <20210619203918.GA1189385@rfd.leadboat.com> From: David Steele In-Reply-To: <20210619203918.GA1189385@rfd.leadboat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Noah, On 6/19/21 16:39, Noah Misch wrote: > On Tue, Feb 02, 2021 at 07:14:16AM -0800, Noah Misch wrote: >> Recycling and preallocation are wasteful during archive recovery, because >> KeepFileRestoredFromArchive() unlinks every entry in its path. I propose to >> fix the race by adding an XLogCtl flag indicating which regime currently owns >> the right to add long-term pg_wal directory entries. In the archive recovery >> regime, the checkpointer will not preallocate and will unlink old segments >> instead of recycling them (like wal_recycle=off). XLogFileInit() will fail. > > Here's the implementation. Patches 1-4 suffice to stop the user-visible > ERROR. Patch 5 avoids a spurious LOG-level message and wasted filesystem > writes, and it provides some future-proofing. > > I was tempted to (but did not) just remove preallocation. Creating one file > per checkpoint seems tiny relative to the max_wal_size=1GB default, so I > expect it's hard to isolate any benefit. Under the old checkpoint_segments=3 > default, a preallocated segment covered a respectable third of the next > checkpoint. Before commit 63653f7 (2002), preallocation created more files. This also seems like it would fix the link issues we are seeing in [1]. I wonder if that would make it worth a back patch? [1] https://www.postgresql.org/message-id/flat/CAKw-smBhLOGtRJTC5c%3DqKTPz8gz5%2BWPoVAXrHB6mY-1U4_N7-w%40mail.gmail.com