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 1oIt1o-0001ff-2X for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2022 14:37:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oIt1m-0008IA-SU for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2022 14:37:46 +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 1oIt1m-0008I1-9x for pgsql-hackers@lists.postgresql.org; Tue, 02 Aug 2022 14:37:46 +0000 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oIt1j-0008DR-BI for pgsql-hackers@postgresql.org; Tue, 02 Aug 2022 14:37:45 +0000 Received: by mail-qk1-x732.google.com with SMTP id e16so10733827qka.5 for ; Tue, 02 Aug 2022 07:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc; bh=5NlLZIRTKMYW+eY+PHfx2MSGst1GgAaZ37kXGZ6Adus=; b=IyNgJDhLcSv7VU1Bo1NrbKRzDCKZlwnkrDUbgMzVzo3adDxqGjWWEU4FOKepl4HGHg zmcDOArevFMIl9ONm+BMvQTCBSlKCI8hpQenN9bDNghKsQ5xOSNYrvPEtrUlSYbygLjZ 8yXAdRv0wXzXpiXsNJqJK7vsJcN4yNO3B2Jvk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=5NlLZIRTKMYW+eY+PHfx2MSGst1GgAaZ37kXGZ6Adus=; b=EAUvRehAYcfUFwT4/5JydhnkpyJvzf7J/jp+xG930qJlQ/YljNHNYKAQvf8x9sJMIE H4za99Rcqxzm9SAFZgHen6YaNrMOaeznVR74cpebhbOhowqRPf3qWM/3GXaTbF2BrW2C BiTkg8y73i+NdGxCbm6wu959KrR0d3tJGelvFzGeJNSL3fqfnSSDNsnT7T4/gfhaOUsx YixIM6SyBbUU3MW4fdUNsbHytrKYJSndltfSSmp8/p9Tpcmarf9ehzPOyn+rJ27CGyoL G0yu3XgcHgEjL65IlYiioaB9Fhhw/1zBk/ELu8V9SLl4/F4AKquMIS15Cd2oijzJpGTl zP5Q== X-Gm-Message-State: AJIora8+mCHH6TIsTIl+OU46zBn0BeFbUdRytWvqAATLSq2y8jLJM92y S/dKy1fW0sfsLTSgy8N9oNWpFOOfiy1l7g== X-Google-Smtp-Source: AGRyM1serluOonyzJBUM3LFe9eL67K444KChlSFY7qStx5WGK6gpJl1ZMMbuV9ox7UwAsO25e7aVsw== X-Received: by 2002:a05:620a:1790:b0:6b6:33b:ad2e with SMTP id ay16-20020a05620a179000b006b6033bad2emr15490309qkb.740.1659451051296; Tue, 02 Aug 2022 07:37:31 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id t14-20020a37ea0e000000b006b58fce19dasm10687608qkj.20.2022.08.02.07.37.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Aug 2022 07:37:30 -0700 (PDT) Date: Tue, 2 Aug 2022 07:37:27 -0700 From: Noah Misch To: David Steele Cc: pgsql-hackers@postgresql.org, Kyotaro Horiguchi , Don Seiler Subject: Re: Race between KeepFileRestoredFromArchive() and restartpoint Message-ID: <20220802143727.GA3796043@rfd.leadboat.com> References: <20210202151416.GB3304930@rfd.leadboat.com> <20210619203918.GA1189385@rfd.leadboat.com> <20220731061747.GA3692882@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Aug 02, 2022 at 10:14:22AM -0400, David Steele wrote: > On 7/31/22 02:17, Noah Misch wrote: > >On Tue, Jul 26, 2022 at 07:21:29AM -0400, David Steele wrote: > >>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? > > > >Perhaps. It's sad to have multiple people deep-diving into something fixed on > >HEAD. On the other hand, I'm not eager to spend risk-of-backpatch points on > >this. One alternative would be adding an errhint like "This is known to > >happen occasionally during archive recovery, where it is harmless." That has > >an unpolished look, but it's low-risk and may avoid deep-dive efforts. > > I think in this case a HINT might be sufficient to at least keep people from > wasting time tracking down a problem that has already been fixed. > > However, there is another issue [1] that might argue for a back patch if > this patch (as I believe) would fix the issue. > [1] https://www.postgresql.org/message-id/CAHJZqBDxWfcd53jm0bFttuqpK3jV2YKWx%3D4W7KxNB4zzt%2B%2BqFg%40mail.gmail.com That makes sense. Each iteration of the restartpoint recycle loop has a 1/N chance of failing. Recovery adds >N files between restartpoints. Hence, the WAL directory grows without bound. Is that roughly the theory in mind?