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 1uqqRx-00DzwB-GG for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Aug 2025 09:58:46 +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 1uqqRw-004Vao-WD for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Aug 2025 09:58:45 +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 1uqqRw-004Vaf-MM for pgsql-hackers@lists.postgresql.org; Tue, 26 Aug 2025 09:58:45 +0000 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uqqRv-001vrV-0G for pgsql-hackers@lists.postgresql.org; Tue, 26 Aug 2025 09:58:45 +0000 Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-4b297962b9cso54176951cf.2 for ; Tue, 26 Aug 2025 02:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756202320; x=1756807120; 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=+5zmT5sFtdFJpe3UN79MdZMVRQyEa2PauMUcmdwS6lQ=; b=DFYTpu3AI8EHHvwWr0QwLo32C1GkY0pK85vwcCN6q5brqAsORXbYOt2EbliT5uc7wi YIl8ZPNWrX9oNIG1LlRU6gXmCpir7agh9zSzBZOvBYcJG7iG6uFVXmiCteugKU0CEtLw HcE9zGYev9iDVMCGckTBw2Rdp6f8Uwsp2O52LBGx2kQJKwiKH4+KBiP9LPo1RKOgT7Ae qS8yG82YsLNar9/Z/5TH+gzoA3esinKGLC/uUKajmY9DvUo9dJmcYAbyapVlIdeWk7wg N+XZSJT+qA4SDps9u90K8HiY1FMANOoksCl9IGpnA1pyaL87sQy3PDJ97a89fhyKJ7m/ hPFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756202321; x=1756807121; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+5zmT5sFtdFJpe3UN79MdZMVRQyEa2PauMUcmdwS6lQ=; b=JyMjleUzfl496sbuh87JbvUW0BEqI70wEhkiQvVXTAcb3e/NBaTtzSOfmb85Er7RrU fL+BjBk8SiZBS1lDPibI5mQ/ciWph72Aqsd6rikEL14MSPmgzi6rqJIUxyfWphAG9tk/ wy2GmJXCSBD7gsn3cotAYzX9lD6lD//cVX79nXrl+Uf2Czey6nKQ6fDF8WO74X8VYqcG KjPhsBQP8rsitbUxN6Qk6OwZ5kYs/HAqDU9x1BvQxSqSCcX2u1un+3Ji+vbYmYiZmjVd wl/DdCkMkn1/nKUXyM4+fcx7J9EXCcAo8xfPrKnNYgptyy5NTSEElwoeETQaVQyxMO8a rukA== X-Forwarded-Encrypted: i=1; AJvYcCXgV6AgJ/vbOabWqERlngOfDPjOflR+CoxcEBnjV23YxGT6+qh6pFo+hYkaAfeAdose1awP/lGAY2OWMYiO@lists.postgresql.org X-Gm-Message-State: AOJu0Ywn9TSVjTcqDqMKY6szqLn1BxZL6Aj51VsXEkYMtHLf50wPj1nA RblIe2CvaNBrER8NgPq0P7q0Kh5ZppJSLZ13FjS0tPsg3trmIwFDFGHkLWp74/0eRDmqd4b41fv HcyPpfs6MNcTN7vYP52lFFx3/dzRITKY= X-Gm-Gg: ASbGnctkA6vs3tI0ezeoiCM2z0W52ldBk3SIz2q72UUvZaTREEvTbgVq6LsPGTH5UkF QIFRe7Yfvw0P1/VRpb2D/TsXTjc2/07vQXdkPmGuRbYvaw7zQKiiB+kclkw0ctZ/OosWbs/7Ihk J4LMfV1uS8AL31LPCS7iaOsyY2IVWF3mL8qbsJDBfSoJskMh6SPJ+FEP5JJ9dJdEZcLM6jlNuCb SQXjsB6H4ohG0uOFRg= X-Google-Smtp-Source: AGHT+IHz61P0GB4amYl6fIZkzf+dGtksLCC3NcXUVyCVGTaaP4dKHynq9zSOgQ3SDVfZBJRmci7Av6dW2Ejoi4ncjy8= X-Received: by 2002:a05:622a:40d:b0:4b2:995a:5692 with SMTP id d75a77b69052e-4b2aaafa264mr187527271cf.47.1756202320517; Tue, 26 Aug 2025 02:58:40 -0700 (PDT) MIME-Version: 1.0 References: <87DD95AA-274F-4F4F-BAD9-7738E5B1F905@yandex-team.ru> In-Reply-To: From: Kirill Reshke Date: Tue, 26 Aug 2025 14:58:28 +0500 X-Gm-Features: Ac12FXxhpccRwiP8reN0sY4Mumbci1y1aee-R477dQKrIMvN5i833H1fdqJ403w Message-ID: Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) To: Melanie Plageman Cc: Andrey Borodin , PostgreSQL Hackers , Andres Freund , Robert Haas 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 Sat, 2 Aug 2025 at 02:36, Melanie Plageman w= rote: > > On Thu, Jul 31, 2025 at 6:58=E2=80=AFPM Melanie Plageman > wrote: > > > > The patch "Set-pd_prune_xid-on-insert.txt" can be applied as the last > > patch in the set. It sets pd_prune_xid on insert (so pages filled by > > COPY or insert can also be set all-visible in the VM before they are > > vacuumed). I gave it a .txt extension because it currently fails > > 035_standby_logical_decoding due to a recovery conflict. I need to > > investigate more to see if this is a bug in my patch set or elsewhere > > in Postgres. > > I figured out that if we set the VM on-access, we need to enable > hot_standby_feedback in more places in 035_standby_logical_decoding.pl > to avoid recovery conflicts. I've done that in the attached updated > version 6. There are a few other issues in > 035_standby_logical_decoding.pl that I reported here [1]. With these > changes, setting pd_prune_xid on insert passes tests. Whether or not > we want to do it (and what the heuristic should be for deciding when > to do it) is another question. > > - Melanie > > [1] https://www.postgresql.org/message-id/flat/CAAKRu_YO2mEm%3DZWZKPjTMU%= 3DgW5Y83_KMi_1cr51JwavH0ctd7w%40mail.gmail.com Hi! Andrey told me off-list about this thread and I decided to take a look. I tried to play with each patch in this patchset and find a corruption, but I was unsuccessful. I will conduct further tests later. I am not implying that I suspect this patchset causes any corruption; I am merely attempting to verify it. I also have few comments and questions. Here is my (very limited) review of 0001, because I believe that removing xl_heap_visible from COPY FREEZE is pure win, so this patch can be very beneficial by itself. visibilitymap_set_vmbyte is introduced in 0001 and removed in 0012. This is strange to me, maybe we can avoid visibilitymap_set_vmbyte in first place? In 0001: 1) should we add "Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(b= ufHdr), LW_EXCLUSIVE));" in visibilitymap_set_vmbyte? Also here `Assert(visibilitymap_pin_ok(BufferGetBlockNumber(buffer), vmbuffer));` can be beneficial: >/* >+ * If we're only adding already frozen rows to a previously empty >+ * page, mark it as all-frozen and update the visibility map. We're >+ * already holding a pin on the vmbuffer. >+ */ > else if (all_frozen_set) >+ { > PageSetAllVisible(page); >+ LockBuffer(vmbuffer, BUFFER_LOCK_EXCLUSIVE); >+ visibilitymap_set_vmbyte(relation, >+ BufferGetBlockNumber(buffer), >+ vmbuffer, >+ VISIBILITYMAP_ALL_VISIBLE | >+ VISIBILITYMAP_ALL_FROZEN); >+ } 2) in heap_xlog_multi_insert: + + visibilitymap_pin(reln, blkno, &vmbuffer); + visibilitymap_set_vmbyte(....) Do we need to pin vmbuffer here? Looks like XLogReadBufferForRedoExtended already pins vmbuffer. I verified this with CheckBufferIsPinnedOnce(vmbuffer) just before visibilitymap_pin and COPY ... WITH (FREEZE true) test. 3) >+ > +#ifdef TRACE_VISIBILITYMAP > + elog(DEBUG1, "vm_set %s %d", RelationGetRelationName(rel), heapBlk); > +#endif I can see this merely copy-pasted from visibilitymap_set, but maybe display "flags" also? 4) visibilitymap_set receives XLogRecPtr recptr parameters, which is set to WAL record lsn during recovery and to InvalidXLogRecPtr otherwise. visibilitymap_set manages VM page LSN bases on this recptr value (inside function logic). visibilitymap_set_vmbyte behaves vise-versa and makes its caller responsible for page LSN management. Maybe we should keep these two functions akin to each other? --=20 Best regards, Kirill Reshke