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 1rMDDS-003OHv-Tc for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Jan 2024 20:24:23 +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 1rMDDR-00BX0I-Fk for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Jan 2024 20:24:21 +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 1rMDDQ-00BX0A-RD for pgsql-bugs@lists.postgresql.org; Sat, 06 Jan 2024 20:24:21 +0000 Received: from mail-yw1-x112d.google.com ([2607:f8b0:4864:20::112d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMDDM-000DQa-Ve for pgsql-bugs@lists.postgresql.org; Sat, 06 Jan 2024 20:24:19 +0000 Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5f15a1052b3so4786917b3.1 for ; Sat, 06 Jan 2024 12:24:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1704572656; x=1705177456; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=llHe/bTDpuIYlXVf4z6mJSH8P1xw5dBKotfIP04mHcc=; b=WQXxNMj1B4T/eh1KZ5+f3c7jBncwueqjrDUiVcApods8uCWGSOY8iPCLSRwsaHosIo NkvPA7I+ZSV0BI7xpoD+6kNyz8Nf2kOVSnixsrEiY4s6IZ3UtHA+bCu5QAzZK+FBjnFM T5B35NP0PPo3JSm06Yb1IB23mbs/X3NTAinOo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704572656; x=1705177456; h=user-agent:in-reply-to:content-transfer-encoding :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=llHe/bTDpuIYlXVf4z6mJSH8P1xw5dBKotfIP04mHcc=; b=YJAzwgdTqfs21ILQC8rl5OUYFA27nN6gglq+rb62Kzj3DXt4QmbUIyGtLnEPYb8oMM 74lkrHWx9h0My+tRCdHWddXggQDhoXXwY/zcEBDGYP9uD7tEl+xVd+yR7dlxg03C/iQr LY/dC83tgyhIePSkt+sa4N2pTUJxnIEv3boYrrm5QlGkq8BvF78A842jp1exL9O/sBtJ a9tgRu41ZMURtRIWO4DbH8tdOHLoL+S33ntIPlVwDJf2vMyMVbryUoczUuhgDi8KD9Wl I9GfWaMmhu7UOXYoLSzOe603g1I9fycJpbvCZjkepI3ZSBmDay820K/ZolJnzgi9DTyZ HkPg== X-Gm-Message-State: AOJu0Yx47DTl9eNS8V9a1Guw5ApQFaj8AQGucjQX6yW/iCW24Cs140Jv iXQwX6fpEGoC+I0DiI31pJjHvlAyjWpq X-Google-Smtp-Source: AGHT+IEWX43PaxUPbvD38sgttLrQILxNp+35Ju+zaOMAohGor7UUkg45A91F75aRYHgwJKKBU4QRLg== X-Received: by 2002:a0d:d645:0:b0:5ed:6263:40c4 with SMTP id y66-20020a0dd645000000b005ed626340c4mr746623ywd.74.1704572656090; Sat, 06 Jan 2024 12:24:16 -0800 (PST) Received: from rfd.leadboat.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id s62-20020a818241000000b005f48f4e0d4bsm1735878ywf.64.2024.01.06.12.24.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Jan 2024 12:24:15 -0800 (PST) Date: Sat, 6 Jan 2024 12:24:13 -0800 From: Noah Misch To: Peter Geoghegan Cc: Matthias van de Meent , robertmhaas@gmail.com, Alexander Lakhin , PostgreSQL mailing lists , Andres Freund Subject: Re: BUG #17257: (auto)vacuum hangs within lazy_scan_prune() Message-ID: <20240106202413.e5@rfd.leadboat.com> References: <17257-1e46de26bec11433@postgresql.org> <20231225024402.77@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 Sun, Dec 31, 2023 at 03:53:34PM -0800, Peter Geoghegan wrote: > On Sun, Dec 24, 2023 at 6:44 PM Noah Misch wrote: > > On Mon, Nov 01, 2021 at 04:15:27PM +0100, Matthias van de Meent wrote: > > > Another alternative would be to replace the use of vacrel->OldestXmin > > > with `vacrel->vistest->maybe_needed` in lazy_scan_prune, but I believe > > > > v17 commit 1ccc1e05ae essentially did that. > > Obviously, 1ccc1e05ae would fix the immediate problem of infinite > retries, since it just rips out the loop. Yep. > > > that is not legal in how vacuum works (we cannot unilaterally decide > > > that we want to retain tuples < OldestXmin). > > > > Do you think commit 1ccc1e05ae creates problems in that respect? It does have > > the effect of retaining tuples for which GlobalVisState rules "retain" but > > HeapTupleSatisfiesVacuum() would have ruled "delete". If that doesn't create > > problems, then back-patching commit 1ccc1e05ae could be a fix for remaining > > infinite-retries scenarios, if any. > > My guess is that there is a decent chance that backpatching 1ccc1e05ae > would be okay, but that isn't much use. I really don't know either way > right now. And I wouldn't like to speculate too much further before > gaining a proper understanding of what's going on here. Fair enough. While I agree there's a decent chance back-patching would be okay, I think there's also a decent chance that 1ccc1e05ae creates the problem Matthias theorized. Something like: we update relfrozenxid based on OldestXmin, even though GlobalVisState caused us to retain a tuple older than OldestXmin. Then relfrozenxid disagrees with table contents. > Seems to be > specific to partitioning with cross-partition updates. > > > Using the https://postgr.es/m/d5d5af5d-ba46-aff3-9f91-776c70246cc3@gmail.com > > procedure, I see these results: > > > > - A commit from the day of that email, 2021-10-29, (5ccceb2946) reproduced the > > "numretries" assertion failure in each of five 10m runs. > > > > - At the 2022-01-13 commit (18b87b201f^) just before the fix for #17255, the > > script instead gets: FailedAssertion("HeapTupleHeaderIsHeapOnly(htup)", > > File: "pruneheap.c", Line: 964. That happened once in two 10m runs, so it > > was harder to reach than the numretries failure. > > > > - At 18b87b201f, a 1440m script run got no failures. > > > > I've seen symptoms that suggest the infinite-numretries bug remains reachable, > > but I don't know how to reproduce them. (Given the upthread notes about xmin > > going backward during end-of-xact, I'd first try some pauses there.) If it > > does remain reachable, likely some other code change between 2021-10 and > > 2022-01 made this particular test script no longer reach it. > > I am aware of a production database that appears to run into the same > problem. Inserts and concurrent cross-partition updates are used > heavily on this instance (the table in question uses partitioning). > Perhaps you happened upon a similar problematic production database, > and found this thread when researching the issue? Maybe we've both > seen the same problem in the wild? I did find this thread while researching the symptoms I was seeing. No partitioning where I saw them. > I have seen VACUUM get stuck like this on multiple versions, all > associated with the same application code/partitioning > scheme/workload. This includes a 15.4 instance, and various 14.* point > release instances. It seems likely that there is a bug here, and that > it affects Postgres 14, 15, and 16. Agreed.