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 1oI2H4-0003kR-Db for pgsql-hackers@arkaria.postgresql.org; Sun, 31 Jul 2022 06:18:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oI2H2-0006r3-0A for pgsql-hackers@arkaria.postgresql.org; Sun, 31 Jul 2022 06:18:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oI2H1-0006qs-G4 for pgsql-hackers@lists.postgresql.org; Sun, 31 Jul 2022 06:17:59 +0000 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oI2Gu-00011Q-Gu for pgsql-hackers@postgresql.org; Sun, 31 Jul 2022 06:17:58 +0000 Received: by mail-qt1-x82f.google.com with SMTP id r21so5987807qtn.11 for ; Sat, 30 Jul 2022 23:17:52 -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=Iv45trr2/o1PJSc2SF9HRewCupAdJilG3oTAPfYYpvw=; b=RB19Ew5cGnWJKMZOQjyzhu3FutZAv3U/2Qq98dthE/tkvHacRqRqxVS4qkXLrzLboJ lqRlLnqxVFvbYS5JX7uIuP3Mj97RhYmeOVGStL7PpGTrXEW8rkyOW+7hfIHF3uPKk3y9 nIxLgrBu/Fs23W1RTxaAfPai6K8qdezvUO5UE= 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=Iv45trr2/o1PJSc2SF9HRewCupAdJilG3oTAPfYYpvw=; b=yWJeZ3FwLWGSs1ACGHtzcwWro65IAEC9JAA0Az41x8gAJT/bw8U/Jg14fFDMuBZjGg egwXtkJVd8r46U9IYMZG96HTrj9SeMeo9rpomFvD0ylnNzpPsAVs2iH1wjW+Zob3g8sx 2yTNQ4v4H43L0cbQVsZOnW3ifsJlQgi4SKg6z3wmKtARuFqd4QHaCsof6LBGcBIzQhCl tl0mbMDCceOA2G92g6b/jMHadGF9ZQLbsdq9UFh5+mhuuqWZY3ohgzDlS7L8RjOWLa3H q9iGA+IqK1E7Bp69liJtjWBcZlNIxVeuULIAT1mQquc2RUhlc4rOCL0TuzepK8RWEB0F DphQ== X-Gm-Message-State: AJIora+2czOEhtLhcpPI+0zAUecmgfXC2iXxVEMs7TX7YXC4XA3g3wgc 2Z+bJiSg6IEH+OlIOxjQH+QPqw== X-Google-Smtp-Source: AGRyM1sYGueQZ4wERD3480vjpV9YRNb0pskzEdfgEq14ZmI01s7AgD9OTT0CbbmUOg1JgNilBRL9nw== X-Received: by 2002:ac8:5790:0:b0:31e:f69a:1b9e with SMTP id v16-20020ac85790000000b0031ef69a1b9emr9609211qta.103.1659248271401; Sat, 30 Jul 2022 23:17:51 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id z1-20020ac84541000000b0031f338f95c0sm5078971qtn.0.2022.07.30.23.17.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Jul 2022 23:17:50 -0700 (PDT) Date: Sat, 30 Jul 2022 23:17:47 -0700 From: Noah Misch To: David Steele Cc: pgsql-hackers@postgresql.org, Kyotaro Horiguchi Subject: Re: Race between KeepFileRestoredFromArchive() and restartpoint Message-ID: <20220731061747.GA3692882@rfd.leadboat.com> References: <20210202151416.GB3304930@rfd.leadboat.com> <20210619203918.GA1189385@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, 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. > [1] https://www.postgresql.org/message-id/flat/CAKw-smBhLOGtRJTC5c%3DqKTPz8gz5%2BWPoVAXrHB6mY-1U4_N7-w%40mail.gmail.com