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 1sLf3J-00FrSE-5f for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2024 08:27:53 +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 1sLf3H-007abN-Ga for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2024 08:27:51 +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 1sLf3H-007abF-3k for pgsql-hackers@lists.postgresql.org; Mon, 24 Jun 2024 08:27:51 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sLf3E-002rA4-1o for pgsql-hackers@postgresql.org; Mon, 24 Jun 2024 08:27:50 +0000 Received: from [192.168.1.110] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4W71L71r6Bz49Ptk; Mon, 24 Jun 2024 11:27:43 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1719217663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EHNRgM1pPdY1yoeIUThdm141rKu74g1XmLrHCmlmTZc=; b=j9ouYRX3AXq+AbEoYWvyWpqvFz71T4eQD5gN1Cnb4tseR8dVQIFfZqLlEADjh/bfLbhvEA EWsnnv2GRp7F7/uWvcbF9/1sG1UpUUSoAa59Q7HpP9rbBmVlfqhFAQBrLA4/Z9WF1w7b3p zYGW9HQTC7YGIV7ym/LtN+OTBWlK5ibK06ua0KrxLVZAhwaYfzf+Os/kLF5GYZdpf9WBiw aKzdoMFJCkn4i7J+LUHgOjsBUbCQUZpEG0Td23B/wRfajt3b5Coe3fRcJS1jGNRKjt1qKG P+7ohW5PUuLIR01elqozmV3q9boMgFBv+NZxFqgSAtVQdqdow/j0pDtTSaeBPg== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1719217663; a=rsa-sha256; cv=none; b=tkp5v355qW9e40gNmYjB9KT7ZtVviob3+bNZ+I+w1fPvFVRQDQ3PdVrx2KGa39tzzQ2fMP p3J3Qf3ccWdpqXgKEHXll4jsxvQwzbbjrwSWaYy9jMCJvgMzZLUy9kyS9fSlqc9c/zP66e FnSMUtF7X9hgzZXF0V8nrU2Fkq6ruioUIv9Pb7rdr1qUwMNW7+CuvdpOhKGHlAlCa0piIZ Kxhzh1CPlmItwLxpw0fUaEjtkF4UJVedX3SzcdzBVWL9VJmyAgRLn+Koa85osd8kmsOz/i tDZzy/THvzznQvC9Dcyku+8SLhqCkzqJQRaU6sfc75swgr84S0nsGw+lxCl/ag== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1719217663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EHNRgM1pPdY1yoeIUThdm141rKu74g1XmLrHCmlmTZc=; b=ht0DySJ3ZZof3wRhKF/OEEe/4MsPZghmstiiNRSAaYTnoegH8oaRHV8ZDBbB075V7ysYwk JKfKSj+Qaf1/iWcBnjpvxPtKq5LAKsiIlULjxxW0pdv/U6Xoow8cFsuK0tPILyK0p9TTmF 5EFSs0LlaSQ5K5qiMyFHIYx2uriA8HmSIJbl/UXTtjkbScCA8xX3fG2mDPJDzdzH4AY/zY op8TibP/xzaOqwKjWtUfTj+7mfDSOG7LGEiS33VJIbJVC5mHAMIJh+Gw9WLWsBeHUqCXOL fyo3uY/jx1NTxBrYgMzeejY01JgFUjYxs+buEFkyYRddlZ0+F7acrGhLjSGnNQ== Message-ID: Date: Mon, 24 Jun 2024 11:27:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Vacuum ERRORs out considering freezing dead tuples from before OldestXmin To: Melanie Plageman Cc: Pg Hackers , Andres Freund , Noah Misch , Peter Geoghegan References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 21/06/2024 03:02, Peter Geoghegan wrote: > On Thu, Jun 20, 2024 at 7:42 PM Melanie Plageman > wrote: >> If vacuum fails to remove a tuple with xmax older than >> VacuumCutoffs->OldestXmin and younger than >> GlobalVisState->maybe_needed, it will ERROR out when determining >> whether or not to freeze the tuple with "cannot freeze committed >> xmax". >> >> In back branches starting with 14, failing to remove tuples older than >> OldestXmin during pruning caused vacuum to infinitely loop in >> lazy_scan_prune(), as investigated on this [1] thread. > > This is a great summary. +1 >> We can fix this by always removing tuples considered dead before >> VacuumCutoffs->OldestXmin. This is okay even if a reconnected standby >> has a transaction that sees that tuple as alive, because it will >> simply wait to replay the removal until it would be correct to do so >> or recovery conflict handling will cancel the transaction that sees >> the tuple as alive and allow replay to continue. > > I think that this is the right general approach. +1 >> The repro forces a round of index vacuuming after the standby >> reconnects and before pruning a dead tuple whose xmax is older than >> OldestXmin. >> >> At the end of the round of index vacuuming, _bt_pendingfsm_finalize() >> calls GetOldestNonRemovableTransactionId(), thereby updating the >> backend's GlobalVisState and moving maybe_needed backwards. > > Right. I saw details exactly consistent with this when I used GDB > against a production instance. > > I'm glad that you were able to come up with a repro that involves > exactly the same basic elements, including index page deletion. Would it be possible to make it robust so that we could always run it with "make check"? This seems like an important corner case to regression test. -- Heikki Linnakangas Neon (https://neon.tech)