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 1wzXJx-0044S5-26 for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Aug 2026 10:26:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wzXJw-001Prf-2A for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Aug 2026 10:26:56 +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 1wzXJw-001PrX-1E for pgsql-hackers@lists.postgresql.org; Thu, 27 Aug 2026 10:26:56 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wzXJu-00000002fIQ-2mPV for pgsql-hackers@lists.postgresql.org; Thu, 27 Aug 2026 10:26:55 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-482e29049adso696733f8f.2 for ; Thu, 27 Aug 2026 03:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787826411; x=1788431211; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=xYSKlEMb3wpBrHnRybkCnFzz09PPmheV89kMoj6nyPY=; b=s/UqyYapkTFf4dZQc13GbhhxQYgl8QLW7jx1rglh6XcdRUFlgHulrgq6FoW6MNTHfe Tra0BBJl9afyPLLRvH8qkvrqgYyHv9femftlX4u7oJfRKiFFUMUqTlv/YbvfbYWn73TC Ck1nL6pi1nglsQ2Itek1FtEDGIi82Tw8GWAn0tyeRcwiikNUScsXPgUi+xy2FniE1sC2 J+qWpzxL/6730sy33Qh2QSaN6jqMx9jOEevgJnj/IwX8WRRpeocArPIQjA6/V3YQoQRD i4weKI++HsTFQYutyCNTXaIo2I8/YP2NxOx4DvUstCDneQeOl6gQSruDSDyU0DU0GMPg jagQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787826411; x=1788431211; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=xYSKlEMb3wpBrHnRybkCnFzz09PPmheV89kMoj6nyPY=; b=Sgo+bhIocVRcoxW14N1Zy0VWd/dyw2N7cn/zF5c+DQ8XDoz6MC8SaQXWfGFwa+9Nn5 0EiRUdCtVsijfC9wPkEWGQKkspmhFi4v5sVUPk08QMz9Rt0TWRu4AaStxo8qG+INyHzJ CGc67njtH3JCapTswMrZlf3RvTUZfBnghHn7EkDLx4h0V5Vh/O9x2bnukPL3bd02ZE62 LUG2i2+pTJKOFBzP20WW3JUeCqXxehVMX7ZmCJFi8S0R3Olu70XGie+pQK5pIyhTKprT cOmRK/JYBBjUx5EXxVPXBeuhf1RbpGUbRYXc2JiMaNOkuWErhtjGvxfRzeTdqSGRd6vW Kpxg== X-Gm-Message-State: AFuF++nKdayE+2NFo4t76V0jX6A0Ff4ZpxpbRgDBu+Zm7XKRp8sg8Z84 de2FtxMMRpgKOMh9K/U/l90EUnBNTt09WtZwl4EsLX6IJ9rh1sHe4sID X-Gm-Gg: AR+sD11VnGGG+dEkTeQpa69u5HqzqdjQ31sRuTtNWylmqNMc0oP9Rzpbi8MU1VY1woh FhssqoSUEIAlAqNBoqJggiaOE2tNlu9j0Zga/M44oqfYDEgN1KMxYv3A83VUvSdVgGR8qx1sWQQ Cju3PEDK+TnjHfOC5y7iM1K880DEPf1R2YEizh3KtzcjoKPrXjOoqeMFot1v4HzaO+347JcRLCY PRf7kYqMjYflP8dopT2n0EYEn49JJqYOhH3lbtGV8qQumElxhc1QDRvL4N/LE01uJLXSX7YLG6e aMSO1jwm1JRjVDq8KenlPbZ7XRAu2N0H+C2MLnuk9SAcnX7QTnHgBZvrCPYOwtV8VK5qigKme+g UN+pbb5DS9fZlGTq95SI3BdkR6eHJR/G8TtTriUt4h5VRqisERE0OepwqW/78So7Oi2CWsSRGE9 ifzNBokpEd72qwgnhRQLK828Ee5CS6t1IIEo2coOrHoXMoEGYdHcBpDhj6RKf/4FrO3XKp1rwkf O11gzPE6AzCE8/0Jtf9JUq/H1o8Lm7xl8ATdingpZeAhU2Mog== X-Received: by 2002:a05:6000:41e8:b0:482:e960:eaf5 with SMTP id ffacd0b85a97d-482e960eda9mr11615111f8f.7.1787826411330; Thu, 27 Aug 2026 03:26:51 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482e27ab1f3sm8433767f8f.11.2026.08.27.03.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2026 03:26:50 -0700 (PDT) Date: Thu, 27 Aug 2026 10:26:49 +0000 From: Bertrand Drouvot To: Kyotaro Horiguchi Cc: pgsql-hackers@lists.postgresql.org, amit.kapila16@gmail.com Subject: Re: Persist slot invalidations before publishing them Message-ID: References: <20260827.170647.1942062682007402092.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260827.170647.1942062682007402092.horikyota.ntt@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Horiguchi-san, On Thu, Aug 27, 2026 at 05:06:47PM +0900, Kyotaro Horiguchi wrote: > Hello, > > At Wed, 26 Aug 2026 13:49:24 +0000, Bertrand Drouvot wrote in > > If ReplicationSlotSave() errors before replacing the state file, the slot is > > invalid in shared memory but still valid on disk. That sounds problematic as the > > resource horizon computations could stop accounting for the slot, remove required > > WAL or rows, and then an immediate restart would restore the old valid slot image. > > I've spent some time looking through the related discussions and > patches, Thanks for looking at it! > For the InvalidatePossiblyObsoleteSlot() case, at least for > RS_INVAL_XID_AGE, if the server crashes after the slot is invalidated > but before the invalidation is persisted, it seems that the restored > slot would still satisfy the same XID-age condition and would > eventually be invalidated again by vacuum or checkpoint. Is the main > reason for making the invalidation durable here that we don't want to > leave the slot valid until that next opportunity? Yeah, for XID age the condition should still hold after restart. On a primary, the end of recovery checkpoint should detect it before connections are accepted. On a hot standby, however, connections can be accepted before the next successful restartpoint, so a restored slot could be used while valid although rows it needed may already have been removed. Also, other causes are not necessarily rediscovered immediately. For example, inactive_since is reset at startup, so an idle timeout invalidation would not be detected again until the timeout has elapsed again. > If so, I'm a little uncomfortable with persisting a modified copy of > the normal slot state before that state has actually been published in > shared memory. It seems to make the state transition somewhat harder > to follow, since the slot state file no longer necessarily represents > the current slot state. > > Would it be simpler to persist the invalidation separately? > example, we could write the invalidation cause to a small file such as > pg_replslot//invalidated and make it durable before > publishing the invalidation in shared memory. On restart, that file > would cause the slot to be restored as invalidated with the recorded > cause. This would keep the normal slot state file as a representation > of the actual slot state, and would also naturally avoid the race with > concurrent slot saves. Your proposal could probably work too. I’m not sure it would be simpler though, as it would add another on disk state and startup handling. I also could not find a precedent for introducing such a persistent file in back branches, but I may have missed one. The proposed patch reuses the existing slot state and format, which probably makes it more suitable for backpatching. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com