Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqGvG-002BC1-42 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Mar 2025 19:30:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tqGvD-005rIc-PO for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Mar 2025 19:30:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqGvD-005rIU-8C for pgsql-hackers@lists.postgresql.org; Thu, 06 Mar 2025 19:30:19 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tqGvB-001MFq-0T for pgsql-hackers@postgresql.org; Thu, 06 Mar 2025 19:30:18 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-22355618fd9so20349075ad.3 for ; Thu, 06 Mar 2025 11:30:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1741289416; x=1741894216; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=itpzFuiqzPfwnw2syeVoYFK1btH74GH7PH1h3kDBbH0=; b=W+ZjoNxNWKH2ZBO4M4DyLw1KTGsb5kCuwSPlO6K9tZy54XWnVxgImwR1keWf+Zu774 5IXDaIir+GdsGgSr/JspqDupPegatlxdyQ4fFvPKrOBV/WGkRYQLHv79nsnexdZoOEwx l3svasbS5NQF3ZmV/SiUx2zg3K7vAlnDtV/d4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741289416; x=1741894216; 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 :subject:date:message-id:reply-to; bh=itpzFuiqzPfwnw2syeVoYFK1btH74GH7PH1h3kDBbH0=; b=JMhS77f3OOzgq7ur/CnMWNeSVrY7Dc0RweLlah0JtxrM0Ndvg5e1w18gLd8/mBK4hi DrGGzGg9O6dj9aF/Nt1XXglGt6aICtpSRHqRj1D8+g62i4J9qwyMY21L/jNJiu5fh0rD C75sUG5Eb/ZExpcsATpIMv1FdTFUO3LGJ/rVxkOsAt+i7hx2TOPJrhH893EG9u6buIP4 bRL7Z0iyX+8Ie26/5slrwUsQ7US7ITWZ9LegvEOnnoS5JnQKkMUlH/iulctaJUHs8D7n pBHzIvDbzlo5BauVtM1X3D+HxVXE1tONyfzbqjZK0VZ3195RdOsrsA0qMir65XD5XtJI GDOA== X-Forwarded-Encrypted: i=1; AJvYcCVxwEJbiU7xD2yaua4XAOdqWUsmX7YkmRymQ71/DgPRRo6i5WEULFDRElAZ4tBLT/N1rd3GS0ZBSMw8NdH5@postgresql.org X-Gm-Message-State: AOJu0Yzy8jDt1QbDo23S3gPtlfVXw9YrXKsqJFdZlmGVztsuG3pRZWSg g8mYOj8ZWQ+LPLO5rTaC5ONXgk/7mTnVrrmOD95mdmkDje3eNBrh90CJ+gyMcg== X-Gm-Gg: ASbGncsIw4eSxsXOQVar34+036CMAnY01HMLWjtXgvdMlsGj8zb0C1gKBeE10asDcoB BDlrmiSJSUFoJt9sdImIcod0J7wg11GZGJu52+bXHm7kXUM6zJIRBnLMqaAQ40ATZnTAIq6Oj1i b3rQs8uVaOmJrL2AMQw+OleaGtIeFDGHcQReYEDIDx4TLYJ6czjUSkUgOaXS7P1EH+xiKB2iNnL eGleP6PmeKFxU9l09+hdKeCBK8r90ikydSIZUFv18m1UA1p+ZEonytte8ao9iGPTkk/3DanzfjB pAC3F9A6Yfvt2VqWJVPwm0lGp8Z0qTW9Chrpyh0= X-Google-Smtp-Source: AGHT+IF1WBaOIKLtnhx6hn5WQ0g/erWWoHAofN+fyoWtnP8N69PIxbPxSDIlR2IikrV4XHWoA6rs1g== X-Received: by 2002:a05:6a00:2e9b:b0:736:5da1:d344 with SMTP id d2e1a72fcca58-736aab160c6mr918863b3a.24.1741289416247; Thu, 06 Mar 2025 11:30:16 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::46]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7369844ce73sm1747272b3a.74.2025.03.06.11.30.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Mar 2025 11:30:15 -0800 (PST) Date: Thu, 6 Mar 2025 11:30:13 -0800 From: Noah Misch To: Michael Paquier Cc: Andres Freund , Nathan Bossart , Robert Pang , Kyotaro Horiguchi , Tom Lane , robertmhaas@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Back-patch of: avoid multiple hard links to same WAL file after a crash Message-ID: <20250306193013.36.nmisch@google.com> References: <20220502173907.GB3351307@nathanxps13> <20220502230613.GA3398932@nathanxps13> <7chjz7zeigbsbt7nim4cj6zryflzcpy2lgenas3yh7cpvwf3gb@m6cwqzlvfd6q> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Dec 19, 2024 at 02:44:53PM +0900, Michael Paquier wrote: > On Wed, Dec 18, 2024 at 08:51:20PM -0500, Andres Freund wrote: > > I don't think the issue is actually quite as unlikely to be hit as reasoned in > > the commit message. The crash has indeed to happen between the link() and > > unlink() - but at the end of a checkpoint we do that operations hundreds of > > times in a row on a busy server. And that's just after potentially doing lots > > of write IO during a checkpoint, filling up drive write caches / eating up > > IOPS/bandwidth disk quots. > > Looks so, yep. Your timing and the report's timing are interesting. > > I've been double-checking the code to refresh myself with the problem, > and I don't see a reason to not apply something like the attached set > down to v13 for all these remaining branches (minus an edit of the > commit message). This became v14 commit 1f95181b44c843729caaa688f74babe9403b5850. I think it is causing timing-dependent failures in archive recovery, at restartpoints. v14 and earlier were relying on the "excl" part of durable_rename_excl() to keep WAL preallocation and recycling from stomping on archive-restored WAL files. If that's right, we need to either back-patch v15's suppression of those features during archive recovery (commit cc2c7d6 and five others), or we need to revert and fix the multiple hard links differently. v15 commit cc2c7d6 "Skip WAL recycling and preallocation during archive recovery" wrote that it fixed "a spurious durable_rename_excl() LOG message". Replacing durable_rename_excl() with durable_rename() increased consequences beyond spurious messages. I regret that I didn't make that connection during post-commit review of commit 1f95181b44c843729caaa688f74babe9403b5850. Trouble emerges during archive recovery, not during streaming or crash recovery. The symptom is "invalid magic number 0000 in log segment X, offset 0" when PreallocXlogFiles() stomps. The symptom is "unexpected pageaddr X in log segment Y, offset 0" [X < Y] when RemoveOldXlogFiles() recycling stomps. wal_recycle=off probably avoids the latter but not the former. Options I see: 1. Make v14 and v13 skip WAL recycling and preallocation during archive recovery, like newer branches do. I think that means back-patching the six commits cc2c7d6~4 cc2c7d6~3 cc2c7d6~2 cc2c7d6~1 cc2c7d6 e36cbef. 2. Revert 1f95181b44c843729caaa688f74babe9403b5850 and its v13 counterpart. Avoid multiple hard links by making durable_rename_excl() first rename oldfile to a temporary name. (I haven't thought this through in detail. It may not suffice.) I'm leaning toward (1) at least enough to see how messy the back-patch would be, since I don't like risks of designing old-branch-specific solutions when v15/v16/v17 have a proven solution. What else should we be thinking about before deciding? Arun Thirupathi collected the symptoms, traced them to commit 1f95181b44c843729caaa688f74babe9403b5850, and reported the diagnosis to me. These symptoms have not emerged in v15+. Thanks, nm