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 1rnknb-00EwDG-Ps for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 19:43:32 +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 1rnkna-0075Nh-9f for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 19:43:30 +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 1rnknZ-0075NW-Qz for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 19:43:30 +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 1rnknW-005uJW-8j for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 19:43:28 +0000 Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-60a0599f631so23067767b3.2 for ; Fri, 22 Mar 2024 12:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1711136606; x=1711741406; 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=EnCxR5uLc+C6PUcEpmM4Bh1VEYHstdczr5L2OU/boEk=; b=VcK3G7oRvpJqiZEzhAGmrf+gwm9TEva3Mqwh1X1xUngH+24dxndW0x3UGvqwePKoJ5 5YDJfe18J89pwqCoRD//GO8UlxtDnHygdffdaYv7Y9VEWA719Go8wnh/G9nGxZfigIQm 9T8HuOUy6LguZD9667AdLQFrvZL1vPIDbif24= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711136606; x=1711741406; 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=EnCxR5uLc+C6PUcEpmM4Bh1VEYHstdczr5L2OU/boEk=; b=Z0wSbxPtm1APkfKH0qvSmU7MThxv3r9r66DNDPfccuuycL/aj0sMdu8ZRIUeCR6ETI 6tnL+Y/elsEXngEeMkH7u9dXpJ4LL0o3wBwbB4fy9HYNGkIBSg6medalvJuZEZJX2wOC fUee7q27dEqPVzpVUQJWixFd7EZWEJSLnNktKDeJ+GqzRvKM4AB0W2WDawzpZo9eZDU/ DNtl0iocaq/gzGCGJ6AVPMyJjOAby0dwMGADho0xLMKQHYP293UYHSCTk9Fh9aT12Sb7 85jIjw2nPV4efteJYXy9/oZOv7tdglkzMry3xSU7JPEF4/zHajTB2lIVdsNVNCKFzHff /02Q== X-Forwarded-Encrypted: i=1; AJvYcCUjNLJcmJzyfaLfKeWqeOePRVDRImfcF8yKjomFVkR3pwAfW1zAgfKUag8u7kumrzMTj5kzRegCAxk6HYzv12GpGi6eW+nNVNDlg4bd0cPk X-Gm-Message-State: AOJu0YwKYruRhCVrgnMdJcGXYyLVpq+2Ha0EK5OSexkctcXAGMXJpQdj RG9IHWWXg9ZXIFe4q5qOaEHFvjUFWKwWetE9L49+IdcLzKX6TrUk4IcmoYfUaQ== X-Google-Smtp-Source: AGHT+IETlE1PHMAsMiAO0ESZYNHkhU1C7ikb9i4mtwOINOfmrmoROESO7Lr2H4uCdvqegxwI+GDE+Q== X-Received: by 2002:a0d:c145:0:b0:60a:3f16:e299 with SMTP id c66-20020a0dc145000000b0060a3f16e299mr665055ywd.25.1711136606495; Fri, 22 Mar 2024 12:43:26 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id x137-20020a81a08f000000b0060a0a571e47sm34287ywg.104.2024.03.22.12.43.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2024 12:43:26 -0700 (PDT) Date: Fri, 22 Mar 2024 12:43:23 -0700 From: Noah Misch To: Melanie Plageman Cc: Robert Haas , Matthias van de Meent , Peter Geoghegan , Alexander Lakhin , PostgreSQL mailing lists , Andres Freund Subject: Re: relfrozenxid may disagree with row XIDs after 1ccc1e05ae Message-ID: <20240322194323.8a.nmisch@google.com> References: <20240106202413.e5@rfd.leadboat.com> <20240106224448.c7@rfd.leadboat.com> <20240304000717.1e@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 Fri, Mar 22, 2024 at 02:41:25PM -0400, Melanie Plageman wrote: > On Fri, Mar 22, 2024 at 8:22 AM Robert Haas wrote: > > On Thu, Mar 21, 2024 at 1:22 PM Matthias van de Meent > > wrote: > > > > So it seems like Matthias, Peter, and Andres all agree that > > > > GlobalVisState->maybe_needed going backward is bad and causes this > > > > problem. Unfortunately, I don't understand the mechanism. > > > > > > There are 2 mechanisms I know of which allow this value to go backwards: > > > > I actually wasn't asking about the mechanism by which > > GlobalVisState->maybe_needed could go backwards. I was asking about > > the mechanism by which that could cause bad things to happen. > > > > > 1. Replication slots that connect may set their backend's xmin to an > > > xmin < GlobalXmin. > > > This is known and has been documented, and was considered OK when this > > > was discussed on the list previously. > > > > Right, OK. > > > > > 2. The commit abort path has a short window in which the backend's > > > xmin is unset and does not mirror the xmin of registered snapshots. > > > This is what I described in [0], and may be the worst (?) offender. > > > > > > [0] https://www.postgresql.org/message-id/CAEze2Wj%2BV0kTx86xB_YbyaqTr5hnE_igdWAwuhSyjXBYscf5-Q%40mail.gmail.com > > > > So, what I would say is that this sounds inadvertent and so perhaps we > > should do something about it, but also, it seems wrong to me that it > > causes any serious problem. As far as I know, we've always treated the > > result of an xmin calculation going backward as a rare but expected > > case with which everything that depends on xmin calculations must > > cope. > > I'm still catching up here, so forgive me if this is a dumb question: > Does using GlobalVisState instead of VacuumCutoffs->OldestXmin when > freezing and determining relfrozenxid not solve the problem? One could fix it along those lines. If GlobalVisState moves forward during VACUUM, that's fine, but relfrozenxid needs to reflect the overall outcome, not just the final GlobalVisState. Suppose we remove XIDs <100 at page 1, <99 at page 2, and <101 at page 3. relfrozenxid needs the value it would get if we had removed <99 at every page. I think GlobalVisState doesn't track that today, but it could. The 2024-03-14 commit e85662d added GetStrictOldestNonRemovableTransactionId(), which targets a similar problem. I've not reviewed it, but I suggest checking it for relevance to $SUBJECT.