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 1uOf4Z-008MNa-Pg for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Jun 2025 16:10:08 +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 1uOf4X-00AnWA-JE for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Jun 2025 16:10:06 +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.94.2) (envelope-from ) id 1uOf4X-00AnW0-4T for pgsql-hackers@lists.postgresql.org; Mon, 09 Jun 2025 16:10:05 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uOf4U-0016IZ-27 for pgsql-hackers@postgresql.org; Mon, 09 Jun 2025 16:10:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1749485399; bh=d7VUBwVsRGmpN22LqHSc1GvABwzSDMpRKCm8z1QhvPQ=; h=From:In-Reply-To:References:Date:Cc:To:Message-ID:Subject: User-Agent:From; b=LHzRN03m42AaJxq8+M7cndmyk5yy+ewcQ7ToPRVgUTKQGDLSY7P7cr8WBhfSEX7OS 5hm8GoeDEZIiA0d15x+akyagPZK9+t2wPPbVdcLe3771YYQaiS1dQX48AmFQ2KLhRx nT8JWuvJ7bzzl+Fxkb+ow+WNaLEW4U3kWX0/gN2vaQOmVmkIAa841ZkEhUrdVuphOq WeLVQi+a2wGQGvQIPJKWZkHTYX9Jt8wMJB8OJQsNqiXh8xC0Wg3E2hHJLbpfvsjLXz syfBQrH+Bbj3OZb4gJEx2Vqm/79bYup3s3dpIaBIwkNFoRnZJB/9M7lXINXh6pUbLg lz2Tig68tCsgA== Received: from sogo.postgrespro.ru (sogo.l.postgrespro.ru [192.168.2.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mail.postgrespro.ru (Postfix/587) with ESMTPS id DA9F860797; Mon, 9 Jun 2025 19:09:58 +0300 (MSK) From: "Vitaly Davydov" In-Reply-To: Content-Type: text/plain; charset="utf-8" X-Forward: 93.174.131.138 References: <1d12d2-67235980-35-19a406a0@63439497> <683f3c82-d38e-436d-88fd-27722af62005@vondra.me> <8679fea7-94ce-4a52-8e48-1a8cd0857fcb@vondra.me> <135e8-675c4600-21-304d7f40@228322535> <1538a2-67c5c700-7-77ec5a80@179382871> <27589a-680a4b80-6d-6e07880@117064404> <3ea6a1-68150580-1-7b53be0@80017081> <309f08-682ca380-25-139bf240@62751029> <2c1d-68344100-b7-3411b8c0@256938178> <1d97ec-6841b600-3-b7b4780@40747246> Date: Mon, 09 Jun 2025 19:09:58 +0300 Cc: "Alexander Korotkov" , "pgsql-hackers" , "Masahiko Sawada" , tomas@vondra.me To: "Amit Kapila" MIME-Version: 1.0 Message-ID: <28c8bf-68470780-3-51b29480@89454035> Subject: =?utf-8?q?Re=3A?= Slot's =?utf-8?q?restart=5Flsn?= may point to removed WAL segment after hard restart unexpectedly User-Agent: SOGoMail 5.12.0 Content-Transfer-Encoding: quoted-printable X-KSMG-AntiPhishing: NotDetected 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: 2025/06/09 14:50:00 #27554574 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 Amit, > I think we can use this approach for HEAD and probably keep the > previous idea for backbranches. Keeping some value in shared=5Fmemory > per slot sounds risky to me in terms of introducing new bugs. Not sure, what kind of problems may occur. I propose to allocate in shm= em an array of last=5Fsaved=5Frestart=5Flsn like below which is not a part of= the public api (see below). It will be allocated and deallocated in shmem the same= way as ReplicationSlotCtlData. I can prepare a patch, if needed. typedef struct ReplicationSlotCtlDataExt { XLogRecPtr last=5Fsaved=5Frestart=5Flsn[1]; } ReplicationSlotCtlDataExt; > Yeah, but with physical slots, it is possible that the slot's xmin > value is pointing to some value, say 700 (after restart), but vacuum > would have removed tuples from transaction IDs greater than 700 as > explained in email [1]. I think, we have no xmin problem for physical slots. The xmin values of physical slots are used to process HSF messages. If I correctly underst= ood what you mean, you are telling about the problem which is solved by hot stan= dby feedback messages. This message is used to disable tuples vacuuming on = the primary to avoid delete conflicts on the replica in queries (some queri= es may select some tuples which were vacuumed on the primary and deletions are replicated to the standby). If the primary receives a HSF message after= slot saving, I believe, it is allowable if autovacuum cleans tuples with xmi= n later than the last saved value. If the primary restarts, the older value wil= l be loaded but the replica already confirmed the newer value. Concerning re= plica, it is the obligation of the replica to send such HSF xmin that will sur= vive replica's immediate restart. >> Taking into account these thoughts, I can't see any problems with th= e alternative >> patch where oldest wal lsn is calculated only in checkpoint. >> >The alternative will needlessly prevent removing WAL segments in some >cases when logical slots are in use. IMHO, I'm not sure, it will significantly impact the wal removal. We re= move WAL segments only in checkpoint. The alternate solution gets the oldest WAL= segment at the beginning of checkpoint, then saves dirty slots to disk, and rem= oves old WAL segments at the end of checkpoint using the oldest WAL segment obta= ined at the beginning of checkpoint. The alternate solution may not be so effec= tive in terms of WAL segments removal, if a logical slot is advanced during checkpoint, but I do not think it is a significant issue. From the othe= r hand, the alternate solution simplifies the logic of WAL removal, backward co= mpatible (avoids addition new in-memory states), decreases the number of locks i= n ReplicationSlotsComputeRequiredLSN - no need to recalculate oldest slot= s' restart lsn every time when a slot is advanced. With best regards, Vitaly