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 1rMFPU-003a7w-Hg for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Jan 2024 22:44:57 +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 1rMFPT-00CAFd-KN for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Jan 2024 22:44:55 +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 1rMFPT-00CAFV-3M for pgsql-bugs@lists.postgresql.org; Sat, 06 Jan 2024 22:44:55 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMFPQ-000EMP-Aj for pgsql-bugs@lists.postgresql.org; Sat, 06 Jan 2024 22:44:53 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5f75aee31d2so2199687b3.2 for ; Sat, 06 Jan 2024 14:44:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1704581091; x=1705185891; 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=FpVAx3Y1sh7Uyy1gQfvpaC3hFRcH71hzVxNcIeCuQUw=; b=C9GolKlrZHIV3OHkxZ/6gpvseW4J4NbQ/NQDRTQTnUjoWa6fT3yW9/BNbPgWMPgIMS wTgEsHTNGC1spb8PmQt58S2LREw0urBt4GaNreEW06gMZMaVNnpxas5fzIWILRVdTLVC YkzOQK/+MyBdoAOGokKRs1yUl8STQRMDs1dp4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704581091; x=1705185891; 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=FpVAx3Y1sh7Uyy1gQfvpaC3hFRcH71hzVxNcIeCuQUw=; b=UDzxbgy5SnmQVTrlpomv5h63wfqh/6pZVZ503RIDCbNzC8a1d7zTBbVfCunNLLrx0E PwNI7n8h3RQSVEa4FBTWttW6nJ27E6pPAkrZI6EhXmbVNUmLxALRKQ+ZEsMw4UtJH0u1 E0lJfgISmhcHyj/Un8K6XoGTwFNxMIvCJqWghNjMT0QyiafWPVJcF/X1c6EmB77WyGyF bRPooqcwbpr135vorMGB+X0HD/E0TVi3sniy8qm5UB9J24LhOgFHVq98oj3fvzC+yU2z 9lZKKWBN/dnTklBDuXdHIkvxUju3ZXuumE/fJz+CiX3+4q500nQvagqJoxTDaCgzSdzT SqkQ== X-Gm-Message-State: AOJu0YxQ/MoyRyzfPr8OuY+cIUGactZGJCnGv885/dlH0sbpGYQSyRl3 4zv9zGmcVwmEnqRO/bXmGVKOtAdUMlwB X-Google-Smtp-Source: AGHT+IHISZKLSyRZdiChxk5UwJYdJ5m6wO0zxb1l36rnEQVfyuBcQDPaouEM8bCfNFoHPTyrAkHcNA== X-Received: by 2002:a0d:d884:0:b0:5e8:5666:f2df with SMTP id a126-20020a0dd884000000b005e85666f2dfmr897305ywe.55.1704581091201; Sat, 06 Jan 2024 14:44:51 -0800 (PST) Received: from rfd.leadboat.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id h17-20020a81b411000000b005e7fb8e1fdasm1823448ywi.14.2024.01.06.14.44.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Jan 2024 14:44:50 -0800 (PST) Date: Sat, 6 Jan 2024 14:44:48 -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: <20240106224448.c7@rfd.leadboat.com> References: <17257-1e46de26bec11433@postgresql.org> <20231225024402.77@rfd.leadboat.com> <20240106202413.e5@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 Sat, Jan 06, 2024 at 01:30:40PM -0800, Peter Geoghegan wrote: > On Sat, Jan 6, 2024 at 12:24 PM Noah Misch wrote: > > On Sun, Dec 31, 2023 at 03:53:34PM -0800, Peter Geoghegan wrote: > > > 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. > > Either every relevant code path has the same OldestXmin to work off > of, or the whole NewRelfrozenXid/relfrozenxid-tracking thing can't be > expected to work as designed. I find it a bit odd that > pruneheap.c/GlobalVisState has no direct understanding of this > dependency (none that I can discern, at least). Wouldn't it at least > be more natural if pruneheap.c could access OldestXmin when run inside > VACUUM? (Could just be used by defensive hardening code.) Tied to that decision is the choice of semantics when the xmin horizon moves backward during one VACUUM, e.g. when a new walsender xmin does so. Options: 1. Continue to remove tuples based on the OldestXmin from VACUUM's start. We could have already removed some of those tuples, so the walsender xmin won't achieve a guarantee anyway. (VACUUM would want ratchet-like behavior in GlobalVisState, possibly by sharing OldestXmin with pruneheap like you say.) 2. Move OldestXmin backward, to reflect the latest xmin horizon. (Perhaps VACUUM would just pass GlobalVisState to a function that returns the compatible OldestXmin.) Which way is better? > We're also relying on vacuumlazy.c's call to vacuum_get_cutoffs() > (which itself calls GetOldestNonRemovableTransactionId) taking place > before vacuumlazy.c goes on to call GlobalVisTestFor() a few lines > further down (I think). It seems like even the code in procarray.c > might have something to say about the vacuumlazy.c dependency, too. > But offhand it doesn't look like it does, either. Why shouldn't we > expect random implementation details in code like ComputeXidHorizons() > to break the assumption/dependency within vacuumlazy.c? Makes sense. On Sat, Jan 06, 2024 at 01:41:23PM -0800, Peter Geoghegan wrote: > What do you think of the idea of adding a defensive "can't happen" > error to lazy_scan_prune() that will catch DEAD or RECENTLY_DEAD > tuples with storage that still contain an xmax < OldestXmin? This > probably won't catch every possible problem, but I suspect it'll work > well enough. So before the "goto retry", ERROR if the tuple header suggests this mismatch is happening? That, or limiting the retry count, could help.