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.96) (envelope-from ) id 1vWK8b-00H2dA-2V for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 19:58:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWK8a-003ymS-1y for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 19:58:13 +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.96) (envelope-from ) id 1vWK8a-003ymI-0b for pgsql-hackers@lists.postgresql.org; Thu, 18 Dec 2025 19:58:13 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vWK8Z-001NuG-1i for pgsql-hackers@lists.postgresql.org; Thu, 18 Dec 2025 19:58:12 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-64b81ec3701so782552a12.1 for ; Thu, 18 Dec 2025 11:58:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766087890; x=1766692690; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=02d8lSJI/eXGkRL+adJdqUh/C+HFuoRO99cXUojjmDc=; b=INVbI6AFgAOt2SPdI1P6z2VPLqd9xmlP9ClcnDfd6XqWP8vsWmW2JMBQPcr63zIxT7 Kt/tgX3QGOwfPgsxCaJ7RwbjhFxGkR+ExkZDDOlYD5ffxRgNvQUGPQK4Oqfu1pAWZXHW 7hEq6htThnM8qeQr2d9rtubK+2KJeKxswLRYUgY/XRmu83Jd1qbVXDwxBszD/n9ceCPf NaEsLry9ZGChI6J/HHkjcvzupO90cYkrhziSr00kC5NOxBFbxJTKE1pCUBEt4FJiJNwV Q4aoZ756Ja/Gxl21PKfJK+TgtdJeXkAkAuF/EUJ85eIdt2+6jRqbmVvySmGSGoHGNOt3 3XWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766087890; x=1766692690; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=02d8lSJI/eXGkRL+adJdqUh/C+HFuoRO99cXUojjmDc=; b=HxyZrUncDA4zKWZ8l0Wt5cQ5gahJWrGcgEF2y/oefg0xacPGc6vUsNNsyJti4pEKPm kI0jm/12LG6SVp8Jfkz3QtpJrxc9jbevcJ5zhjW/ay7IsdR0z51eLtEf9ES0wuW65yRp FsVV9fjaNJJowaCglRBJ5K7V8QmqHYCaSo1D3fC2r5iLyBUJDCH2Sgo0jBWe24JR+yNH eYM66n89XFkhkXIFPtAOAMxUTWb79Xnw+W5rqe/k0xdJbd0v8cjA6kNiDO76lmNzzxuE wKyZl2At9dlNzSYpTibHP0EP1ESdz4u2KGlOcdHsA2Q3TbjuoAbY1s3ertjdOEXCBruS AAbA== X-Forwarded-Encrypted: i=1; AJvYcCV3u7VnOCO1AwTiKmpgxNG30nH74Zxdo/ISK1DSK0FNu/jKLSWqP/eWQ/fprhR/KL89jAldCP/GaQgonqFC@lists.postgresql.org X-Gm-Message-State: AOJu0Yx8iKCKMnRCNZH5g/s0urUr1nol/PpXsj4S7v16I9AlEol+jGSS 8NXXveAFfNaf8cbjjly6HXgoGrhrwq+lQ4VWcxRUMX+We4vtZuart8iNeGef0g7b2r0Q9LYsevo HeSVY2Di+BYnPjhFQmOuiqKZ+AOuN0j4= X-Gm-Gg: AY/fxX4Gj7OqRbsVjkbiMzaBIvLXA1A7aDGHgIEnLqdcbpnUglEGuIepeeR/NVAoezT 73G8cl1/9tZkPIynR7jaCqp4/0Kjtivy6L5TaYp5DpxAkT1T0odjweKDTp+SNm7Eeh47YnPWIJE yJUXod67XbrwBmgqPWCWZv83iEdKjik51H6XYSwSez45n5GuSMGKKMwRYnuswqFEnYAHR3s3MjY Rd3ZXTAENqs+IsmF5pXGooDqhpBRKdayFBF6sDUlRJ85Uzf99Zg1JDTzeLKIO164IvBWlTF X-Google-Smtp-Source: AGHT+IGfV15k6Un8hB2qhVsnlQlxDx1fiRxpMJTFTBniRs6X2+TouWDV7kpiQ2rA/dEY3WhqiMtDtXe4xHFHwm0If7g= X-Received: by 2002:a05:6402:1ecf:b0:649:cb90:2858 with SMTP id 4fb4d7f45d1cf-64b8ecaf225mr559931a12.28.1766087889374; Thu, 18 Dec 2025 11:58:09 -0800 (PST) MIME-Version: 1.0 References: <2wk7jo4m4qwh5sn33pfgerdjfujebbccsmmlownybddbh6nawl@mdyyqpqzxjek> In-Reply-To: From: Melanie Plageman Date: Thu, 18 Dec 2025 14:57:57 -0500 X-Gm-Features: AQt7F2oIIO4xamB3eWGNmObB60DrAJJ6YX-ALP8thwfWxpVcMa8T0TO53IzEXnA Message-ID: Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) To: Kirill Reshke Cc: Andres Freund , Robert Haas , Andrey Borodin , PostgreSQL Hackers , Heikki Linnakangas , Chao Li Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Dec 18, 2025 at 1:07=E2=80=AFPM Kirill Reshke wrote: > > On Thu, 18 Dec 2025 at 20:18, Melanie Plageman > wrote: > > > But you are right, I don't see any non-error code path where a heap > > page would become empty (all line pointers set unused) and then not be > > set all-visible. Only vacuum sets line pointers unused and if all the > > line pointers are unused it will always set the page all-visible. > > > > I think, though, that if we error out in lazy_scan_prune() after > > returning from heap_page_prune_and_freeze() such that we don't set the > > empty page all-visible, we can end up with an empty page without > > PD_ALL_VISIBLE set. You can see how this might work by patching the VM > > set code in lazy_scan_prune() to skip empty pages. > > Thank you for your explanation! I completely forgot that PD_ALL_VIS > is a non-persistent change (hint bit). so its update can be trivially > lost. > The simplest real-life example is being killed just after returning > from heap_page_prune_and_freeze, yes. > PFA tap test covering lazy_scan_new_or_empty code path for > empty-but-not-all-visible page Cool test! I'm going to have to think more about whether or not it is worth adding a whole new TAP test for this codepath. Is there an existing TAP test we could add it to so we don't need to make a new cluster, etc? How long does the test take to run? Obviously it will be quite short, but every bit we add to the test suite counts. I don't actually know how much overhead there is with injection points. I was chatting with Andres and he mentioned there is one other case where you can end up in this code path (empty page without PD_ALL_VISIBLE set) and this case does actually trigger this code: if (RelationNeedsWAL(vacrel->rel) && !XLogRecPtrIsValid(PageGetLSN(page))) log_newpage_buffer(buf, true); If you are inserting to a new page and you successfully call PageInit() (making the page no longer considered new by PageIsNew() because pd_upper will be set) but you error out before actually inserting the tuple, then you will have an empty page without PD_ALL_VISIBLE set. And assuming you error out before emitting WAL, the page will not have a valid LSN set. So you will hit that code which calls log_newpage_buffer(). I would say this case is so narrow (the log_newpage_buffer() codepath in lazy_scan_new_or_empty()), it's not worth the added test overhead, but I just wanted to share what I learned about when this code could be hit. Previously it was more common in the bulk extension case to have empty pages not set PD_ALL_VISIBLE because bulk extension would call PageInit() on all of the pages it extended so all the pages except the target page were empty (today they are not initialized so they go into the PageIsNew() branch). So, in both cases, it seems like the empty page not set PD_ALL_VISIBLE mostly only hit if we previously errored out. - Melanie