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 1vR1cc-004VaL-20 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 05:11:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vR1ca-000Xto-0x for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 05:11:16 +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 1vR1cZ-000Xtg-2q for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 05:11:16 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vR1cX-0032yi-0C for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 05:11:15 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2953e415b27so6190235ad.2 for ; Wed, 03 Dec 2025 21:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764825073; x=1765429873; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GlKr70mQ14qs6Fzi/0nWD6lU24y1nJ5v29hwrvsnL4M=; b=R2b/9gm7tAhMyjjgfluIQm32Lp5W5s59LVKRpJ/5J3/GDbU3oAxChQM1k02yCZPFfp mvzNSbLEZrxH4HxPIRMQZ5RGOfEdNhdH4dDjXXtO9ftBf188/YTYYo7NTnTzWw0xV6Wr USTHr7rrsEY2UgT+KxKSzz829t+9k+140yDCOlhcChQHmze7rbvFjzAaLCh1OjLjb+X8 Aod7x9ewkVBtibttJIj8Mr6cTlq/04Qp7NVirGCtYKJ29y72GKhrNVywEbZRXR1DTwm5 W3jLS6wcPiSSnzawooDXqDafNGlCXjgOGAayCJl9Qbuk/dhNNDsRexRYIVkkGjmqv+N9 nbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764825073; x=1765429873; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GlKr70mQ14qs6Fzi/0nWD6lU24y1nJ5v29hwrvsnL4M=; b=WdMs2wVofWX3DYTIDLnJQU7SQZi49R83ug05AggQMwlOnXPGMe4CvCehFi/qg91hba VHhB1aIUBo2ACnOTZiX+hAIPdqQ3s+3bHeqI4XR1K79Nkgn4Fj7OHavGM55iAVMieZmI lmFXCCp2JY7EHCH4spAllkxe+ZVlx9ZsCVLDBVp6qFu81cxkdW5yOJrU2xiuodDMRg9L GXDXJyUKn189CuCd6Qznnz3vTLZog7DeWJfJ/H2P5FjJ9/C5h4fVkX3gk0h5kV5WCqyn DakKZfZRG2MXrRx0ou5LDtbsVMYv2cGrw0R+qrVUp6voOc7WUGnEbIuxtMPmHtNAPGqS BpuQ== X-Forwarded-Encrypted: i=1; AJvYcCXY6MjWWQ3B29asx5P1/QGXPE585GBGITBPEl4h0xsUQqF2Z9gfchMKbYhrfi9uv9gFZ1KifXClaoy5CIfh@lists.postgresql.org X-Gm-Message-State: AOJu0YzKbVxaSCiJsvzIl2vLU1+HrV8qmALcQUG2tpatM/bh2POoRjzd bSYdZOmo0tU9EjpuCW1YFc26DJY1elJx3O/3kd9256X/7fkEkJlUsfRo X-Gm-Gg: ASbGncsexWRWGiSGCUipvKEbcXIfcVPmxYNQ5LlzzRJM76zfpoXADyHXSk2gwX2ALM5 Vu1lXkFKCR2fKE5P8JP7fvLjG88qlO1iZEC5JRJoTya/LcbY4jO6JGA5Sgr75gBq9YCtaKd9uCM dRthqDET/dnMVLzwh6YYApdQglufwvg7Fb3eBtr5kkDnSY//G5blcDoKAXxyVfU96eyO1Zpww08 5b45KbX1P+8M5EzvMYVUMiw6KjU43RCELfpY6e/KTfHpsNVCte3kwnZT9NGuS7ypYVUDARsjRkF stQ7X8uMUq22+r4eaitHimsQ4NYthB0HoBmA1kUJD82jtTizXcupqmw1v9jCXB3pWMLPMh1vwC9 97ixhLI63EAFCZ2Y3SzsHWZvVqyp4auHw5hhLCVgbpnsbLYMOkNw0VPh3lVqKhKf/+FSL6eiU/o eRZyqawluvgMxzLMH/rPk= X-Google-Smtp-Source: AGHT+IGmPE1nywPF/Dth//xpwZVxECGQ6/TXWTy/DSR5MwMXMzZ1YnyZ/PeNMmG+S92xxtuXvnfjPw== X-Received: by 2002:a17:903:1103:b0:27d:6f49:febc with SMTP id d9443c01a7336-29d9f67d67dmr21171525ad.1.1764825072762; Wed, 03 Dec 2025 21:11:12 -0800 (PST) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29daeaab9b1sm5602525ad.77.2025.12.03.21.11.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Dec 2025 21:11:11 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) From: Chao Li In-Reply-To: Date: Thu, 4 Dec 2025 13:10:33 +0800 Cc: Andres Freund , Kirill Reshke , Robert Haas , Andrey Borodin , PostgreSQL Hackers , Heikki Linnakangas Content-Transfer-Encoding: quoted-printable Message-Id: <9B2211B5-14B4-4C22-96BD-F7B32E577DB6@gmail.com> References: <2wk7jo4m4qwh5sn33pfgerdjfujebbccsmmlownybddbh6nawl@mdyyqpqzxjek> To: Melanie Plageman X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Melanie, I resisted this patch again today. I reviewed 0001-0004, and got a few = more comments: > On Dec 4, 2025, at 07:07, Melanie Plageman = wrote: >=20 > = 1 - 0002 ``` +static bool +heap_page_will_set_vis(Relation relation, + BlockNumber heap_blk, + Buffer heap_buf, + Buffer vmbuffer, + bool = all_visible_according_to_vm, + const PruneFreezeResult = *presult, + uint8 *new_vmbits, + bool *do_set_pd_vis) ``` Actually, I wanted to comment on the new function name in last round of = review, but I guess I missed that. I was very confused what =E2=80=9Cset_vis=E2=80=9D means, and finally = figured out =E2=80=9Cvis=E2=80=9D should stand for =E2=80=9Cvisibility=E2=80= =9D. Here =E2=80=9Cvis=E2=80=9D actually means =E2=80=9Cvisibility map = bits=E2=80=9D. There is the other =E2=80=9Cvis=E2=80=9D in the last = parameter=E2=80=99s name =E2=80=9Cdo_set_pd_vis=E2=80=9D where the = =E2=80=9Cvis=E2=80=9D should be mean =E2=80=9CPD_ALL_VISIBLE=E2=80=9D = bit. So the two =E2=80=9Cvis=E2=80=9D feels making things confusing. How about rename the function to =E2=80=9Cheap_page_will_set_vm_bits=E2=80= =9D, and rename the last parameter to =E2=80=9Cdo_set_all_visible=E2=80=9D= ?=20 2 - 0002 ``` + * Decide whether to set the visibility map bits for heap_blk, using + * information from PruneFreezeResult and all_visible_according_to_vm. = This + * function does not actually set the VM bit or page-level hint, + * PD_ALL_VISIBLE. + * + * If it finds that the page-level visibility hint or VM is corrupted, = it will + * fix them by clearing the VM bit and page hint. This does not need to = be + * done in a critical section. + * + * Returns true if one or both VM bits should be set, along with the = desired + * flags in *new_vmbits. Also indicates via do_set_pd_vis whether + * PD_ALL_VISIBLE should be set on the heap page. + */ ``` This function comment mentions PD_ALL_VISIBLE twice, but never mentions = ALL_FROZEN. So =E2=80=9CReturns true if one or both VM bits should be = set=E2=80=9D fells unclear. How about rephrase like "Returns true if the = all-visible and/or all-frozen VM bits should be set.=E2=80=9D 3 - 0002 ``` + /* + * Now handle two potential corruption cases: + * + * These do not need to happen in a critical section and are not + * WAL-logged. + * + * As of PostgreSQL 9.2, the visibility map bit should never be = set if the + * page-level bit is clear. However, it's possible that the bit = got + * cleared after heap_vac_scan_next_block() was called, so we = must recheck + * with buffer lock before concluding that the VM is corrupt. + */ + else if (all_visible_according_to_vm && = !PageIsAllVisible(heap_page) && + visibilitymap_get_status(relation, heap_blk, = &vmbuffer) !=3D 0) + { + ereport(WARNING, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("page is not marked all-visible = but visibility map bit is set in relation \"%s\" page %u", + = RelationGetRelationName(relation), heap_blk))); + + visibilitymap_clear(relation, heap_blk, vmbuffer, + = VISIBILITYMAP_VALID_BITS); + } ``` Here in the comment and error message, I guess =E2=80=9Cvisibility map = bit=E2=80=9D refers to =E2=80=9Call visible bit=E2=80=9D, can we be = explicit? Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/