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 1rMuFl-007ZJm-Fl for pgsql-bugs@arkaria.postgresql.org; Mon, 08 Jan 2024 18:21:38 +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 1rMuFj-006wlt-Dy for pgsql-bugs@arkaria.postgresql.org; Mon, 08 Jan 2024 18:21:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMuFi-006wll-UL for pgsql-bugs@lists.postgresql.org; Mon, 08 Jan 2024 18:21:35 +0000 Received: from mail-yw1-x1133.google.com ([2607:f8b0:4864:20::1133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMuFe-000W28-5O for pgsql-bugs@lists.postgresql.org; Mon, 08 Jan 2024 18:21:34 +0000 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5f3da7ba2bfso20988797b3.3 for ; Mon, 08 Jan 2024 10:21:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1704738088; x=1705342888; 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=KiTL2lSYKGxc19UCcjSlmj+5rtWSaaS6Zm4L5YD0nfo=; b=Gv7jg+PBmTtGKrp/tD+IfGr/i/nF0eA2QihD/MH7r2F/gK1wCdItqiFHVQnVkur2PP oA98QGOcxQCxsvstul5Ddq53QyqmZtoK1WVs+MfcbdH/T65J/dyaHCx9YhAEitYhjBZT QtFP7MkU2/Ci+kVzh0AGLKIA3Y0Js9y9PeijE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704738088; x=1705342888; 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=KiTL2lSYKGxc19UCcjSlmj+5rtWSaaS6Zm4L5YD0nfo=; b=sgw/1LBn69QSEXkVyrJOqwtBS+1rtiUiZjrp+Usr5Os6nLeVXbEDp1j7dRG1O+4X/S Im0j+Kiwb7FKqk9wV9sIwmcQjy8bZWnOcb/ytKZiSDguZyBr+jHBc3XYIRfwjvc9HJTZ sTZ1I5oHEreZxx4NnZnwiwaLxyEf7LlhLD4PoUnr7IdHUYMR9iC8FnX9nTrcVzfmbM9E xSk1f6rLYgcP9xHPFALlgQ/eiwWIaJ6nLLJiexgwgC3K83aP+bxp3wKZxyAuH5lZW8M8 nnCawklmyvFgNEofsKKH5ioa4wXHu6K+hmU3VFHoQRCCq90G9N1Z/GYIDuDCP++hdcru hspA== X-Gm-Message-State: AOJu0Yw4t2MqyZvEXm8xJwSnLMOmBh7R+cHX9D+bRQMNCCyw2jCpj01z fZ5hnTdNqYgU5tRsCOFwnP+HghnbVw0u X-Google-Smtp-Source: AGHT+IEr+GGfSEPdG76ALABAd4kefgWdHCPrpweJ05qrodWIYZ7bzDOhD0O7ti/UjDNdqlBJ9zWpcw== X-Received: by 2002:a0d:fd45:0:b0:5d7:1940:f3f0 with SMTP id n66-20020a0dfd45000000b005d71940f3f0mr3336018ywf.88.1704738088583; Mon, 08 Jan 2024 10:21:28 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id m184-20020a0dfcc1000000b005f59ba17709sm78798ywf.18.2024.01.08.10.21.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2024 10:21:28 -0800 (PST) Date: Mon, 8 Jan 2024 10:21:25 -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: <20240108182125.f8.nmisch@google.com> References: <17257-1e46de26bec11433@postgresql.org> <20231225024402.77@rfd.leadboat.com> <20240106202413.e5@rfd.leadboat.com> <20240106224448.c7@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 Mon, Jan 08, 2024 at 12:02:01PM -0500, Peter Geoghegan wrote: > On Sat, Jan 6, 2024 at 5:44 PM Noah Misch wrote: > > 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? > > I suppose that a hybrid of these two approaches makes the most sense. > A design that's a lot closer to your #1 than to your #2. > > Under this scheme, pruneheap.c would be explicitly aware of > OldestXmin, and would promise to respect the exact invariant that we > need to avoid getting stuck in lazy_scan_prune's loop (or avoid > confused NewRelfrozenXid tracking on HEAD, which no longer has this > loop). But it'd be limited to that exact invariant; we'd still avoid > unduly imposing any requirements on pruning-away deleted tuples whose > xmax was >= OldestXmin. lazy_scan_prune/vacuumlazy.c shouldn't care if > we prune away any "extra" heap tuples, just because we can (or just > because it's convenient to the implementation). Andres has in the past > placed a lot of emphasis on being able to update the > GlobalVisState-wise bounds on the fly. Not sure that it's really that > important that VACUUM does that, but there is no reason to not allow > it. So we can keep that property (as well as the aforementioned > high-level OldestXmin immutability property). > > More importantly (at least to me), this scheme allows vacuumlazy.c to > continue to treat OldestXmin as an immutable cutoff for both pruning > and freezing -- the high level design doesn't need any revisions. We > already "freeze away" multixact member XIDs >= OldestXmin in certain > rare cases (i.e. we remove lockers that are determined to no longer be > running in FreezeMultiXactId's "second pass" slow path), so there is > nothing fundamentally novel about the idea of removing some extra XIDs > >= OldestXmin in passing, just because it happens to be convenient to > some low-level piece of code that's external to vacuumlazy.c. > > What do you think of that general approach? That all sounds good to me. > I see no reason why it > matters if OldestXmin goes backwards across two VACUUM operations, so > I haven't tried to avoid that. That may be fully okay, or we may want to clamp OldestXmin to be no older than relfrozenxid. I don't feel great about the system moving relfrozenxid backward unless it observed an older XID, and observing an older XID would be a corruption signal. I don't have a specific way non-monotonic relfrozenxid breaks things, though.