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 1w9lvw-001jTZ-0G for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 15:32:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9lvu-009sm4-0q for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 15:32:10 +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 1w9lvt-009slu-2T for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 15:32:10 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w9lvq-00000000sEb-4BG5 for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 15:32:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1775489523; bh=CAFcjB8t+KVM8Dn88Q7OlAyDNIwa4B/ctq5vtkPigK4=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=Qm013Xiyx1e9zWZvtwFsUKVej4LY3bCliUEc13CmarrPa+jDPWnIO0X9cwLdwPnac utqt2mJESbcUGYNFMIlkWidGcSwxsVnSrMFQu3mlPzKGmzba64RaTHKXAfh5yu81Wc nqiYuZym5xTX+zsX6Am3IopTXIvXtczt9RItNQIP21alynCLXD22f6rThZpvayHEJN x7IpFrbn95fXyUyX8EBlWezoO9y8oY4Upsxz/0vm9q8pGmNpojK/7rL3EEJVEk/+jJ 22jfHJM+Fae4xEx/qE63kcmkovnpw4p5FBkBkyN8bCkdTmYbYjKkHKVHYVCCGBSVb7 YIQL6B7XR4NKw== Received: from [10.3.16.29] (broadband-188-255-38-164.ip.moscow.rt.ru [188.255.38.164]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.makhmutov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 5D1895FFD4; Mon, 6 Apr 2026 18:32:03 +0300 (MSK) Message-ID: Date: Mon, 6 Apr 2026 18:32:03 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) To: Andres Freund Cc: Melanie Plageman , PostgreSQL Hackers , Kirill Reshke , Andrey Borodin , Robert Haas , Heikki Linnakangas References: <7clovcjtacv6peujpfaimeynrkcd4anp6ohbdd3ncgtjo67anb@ylcccepdiuz2> Content-Language: en-US From: Alexey Makhmutov In-Reply-To: <7clovcjtacv6peujpfaimeynrkcd4anp6ohbdd3ncgtjo67anb@ylcccepdiuz2> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-KSMG-AntiPhishing: NotDetected, bases: 2026/04/06 14:46:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2026/04/06 10:19:00 #28376530 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Andres, On 4/6/26 17:44, Andres Freund wrote: > I don't have a strong opinion on this, but I think it's pretty defensible to > record only when there's free space. The whole goal of updating the FSM during > recovery is to make sure that free space can be found fairly quickly after > promotion (it's also beneficial in some crash recovery cases, but not that > much). > ... > Obviously the FSM is not crashsafe, so updating it with 0 during replay could > avoid some unnecessary page reads after a promotion. But I'm not sure that > that's particularly worth optimizing for. This makes sense. I'd like just to put some context here: I was checking the FSM update case in scope of the thread https://www.postgresql.org/message-id/flat/596c4f1c-f966-4512-b9c9-dd8fbcaf0928@postgrespro.ru, in which I was specifically looking at the case with outdated FSM data (showing lots of free space) on standby causing a significant performance hit after switchover. As example this include case with table having fillfactor<=80 which has prior bulk rows deletes + insertion. In this case (mostly) empty FSM block may be delivered to standby via FPI, but subsequent inserts may be lost due to the 20% heuristic. Moreover, updates to FSM may be lost even for blocks filled for more than 80% due to missing dirty flag as described in that thread. In my understanding the FSM update during processing of the 'heap_xlog_visible' function on standby was kind of 'last line of defense' for any corner case scenario with FSM update (as block would not be visited by the vacuum process once it's marked as 'all visible') and it was introduced in https://www.postgresql.org/message-id/20180802172857.5skoexsilnjvgruk@alvherre.pgsql (ab7dbd681) specifically for this purpose. Now, as logic of 'heap_xlog_visible' is merged into 'heap_xlog_prune_freeze', so this task is carried by this function. I fully agree that having exactly zero-space seems to be a very uncommon situation (and probably not reproducible with tables having fillfactor<=80). I've just noted that such case was processed by the old logic in the 'heap_xlog_visible', while current implementation in 'heap_xlog_prune_freeze' skips it. Thanks, Alexey