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 1rDPza-001xVv-0l for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Dec 2023 14:13:42 +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 1rDPzV-00EqoH-S2 for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Dec 2023 14:13:37 +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 1rDPzT-00Eqo7-WF for pgsql-bugs@lists.postgresql.org; Wed, 13 Dec 2023 14:13:37 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rDPzM-00ACge-AH for pgsql-bugs@lists.postgresql.org; Wed, 13 Dec 2023 14:13:34 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 855C03200BD4; Wed, 13 Dec 2023 09:13:25 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 13 Dec 2023 09:13:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1702476805; x=1702563205; bh=7p3gysVmkd 6HQBetR/XOzEcs/pO1lIikxKtsvn3DuWY=; b=hKloRNKkZpmo+qxuOey+S4KnrN cG90geVrBVGVjcNV0gAaQIihqO/x9pE0hpmAm8s2DJWCUcaDTRMYDlDbFB/zhiD2 i3CxtpyMQfZ18ro9TdJrUMmjkkfMbon3i4DIS/+dnDPZSoxnX2UcQOIZHkGUgTob Hyww48Nt0f9C4r9+l1OVLllgbeSpJWw/SuRdV61evXakXFo2SOmzqKNJwLlsMIpw AIZOGYeMyUT2YVEiSvekcm2OFt4l96Hb6hPJetP4uwdikiaduSyxE+Ykn6EAJeX5 ICsGIHSwltuk2eqqkelZbsKJKCLSGASYxBcIvUypz30W/tD2y6RPt+U1GVjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1702476805; x=1702563205; bh=7p3gysVmkd6HQBetR/XOzEcs/pO1 lIikxKtsvn3DuWY=; b=aHJs9LQqtTx1IlQ+aX7cA248WwCpsOU0dDYHS2XeTTw/ B/DoIuJrWnMdLZJkwu8HqQWZ0X2aHTBmdGngvxK4W5obJ70JHu9H743Wk+1oQ5PS 6bv/92NDhcJZDMStwaTWhJdlGgf/TwHyUOqljLhShlMKwrSvYojYRCD5wadPg0M/ nXNUe/4YwVe/hm7t7BW1wIxTsWkEY9J23It3V/vS7NYDBNbNMnU4Dx4tOhY0kXSF pyr7qp8c7O04IU48vBjCIZWnZRPrEh/YHlGIurPC6AOXeXSV1riAhoefA5mN5qHE +YgiHbn5KqaIpflIVGvCmhgCUIUV5AR1f+bOnzubhA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeljecutefuodetggdotefrodftvfcurf hrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlh cuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvden ucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprghquh hivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeggeff hfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Dec 2023 09:13:23 -0500 (EST) Date: Wed, 13 Dec 2023 15:13:20 +0100 From: Michael Paquier To: Alvaro Herrera Cc: Kyotaro Horiguchi , feichanghong@qq.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18241: PushTransaction may cause Standby to execute ItemIdMarkDead Message-ID: References: <202312121711.tzjyb5yeb3fa@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="LRjFRBuVI37RIk+2" Content-Disposition: inline In-Reply-To: <202312121711.tzjyb5yeb3fa@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --LRjFRBuVI37RIk+2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Dec 12, 2023 at 06:11:44PM +0100, Alvaro Herrera wrote: > What a horrible bug. Thanks for pushing the fix. It looks OK to me: > nowhere else do we create a TransactionStateData that would need the > initialization. Yep. > I wonder if this can cause data corruption, if you happen to have a > broken standby that improperly kills some index entry and is later > promoted. Maybe this bug explains these mysterious cases where an index > seems to lack a pointer to some heap tuple for no known reason -- > especially notorious when you try to REINDEX a unique index and that > turns out not to work due to duplicates. AFAIK, this only impacts the visibility of the data retrieved in transactions began when recovery was still running when doing an index scan, and, even if the HOT chains would get inconsistent, we'd still clean up them one the xmin gets updated on the standby because there are no snapshots requiring it. REINDEX after promotion does not looks like an issue to me as we'd take a lock or wait for the necessary snapshots to be gone in the concurrent case. Or perhaps my imagination with the HOT chains is too limited? > I would be happier if the order of initialization of the struct member > followed the order to the struct, with comments to note the missing > members. That might make it more visible to future patches that would > add more members. Something like this: That crossed my mind, but it is not like we have other code paths where we assume some fields to be initialized based on a palloc0() or similar, so I don't see why we'd need that for this case. > Also, the way this function checks for overflow is strange. Why > increment then check, leading to a forced free and decrement, instead of > just testing and throwing error right away? It's less code: Saying that, agreed that this suggestion is an improvement compared to what's on HEAD. So +1 from me to change this code as you are suggesting. -- Michael --LRjFRBuVI37RIk+2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmV5u/8ACgkQnvQgOdby QH13dQ//S81s793sETry9nlKflwqiJq9WOAnaWzAB3zZaFe8SdLsMbiwsXZpy+BY Ov/7lLzn+JjMDV7ZcIL+MoNKUFMXa6GrfFg+mLg2C+6+pu8fAIe+I6mzn19me5z8 psZ3QoiywKMP4nCks/NpwJd+D2/HprcsO6qUoSpRFUhB3bEGAW0gKWfpb6HfQn4L 6ieeTjTzfhJ3SmNUDmq/fo/HDWoxKqm8uIsgoj40BMWVyM4Y4wd+RhRLti09USA0 UFa+dreXRPmlq5YNo1nEtgQkHwq3wgswS7yD5+bMmj3ZJoXI1nMfQyRMTaLkjgcg FQMLq0h0iZF6Asuag1HhwbJLQuznaawKbZFkT993u/uTuuzVGGzOejMRAx9QmjSr k7/uNmSHGdHSMyPutDyacW8gjTWSRuF/2c7sP+NQ4u5kG9FEo65M0DtfhASIYgA7 nu8pgfLYCxFgO+H6TlPqyi5llHtDBoz0OGkJ5jNX4eHgfMWHAlsmuzPqabZEbs6Y w2XHKI6DJvMIfUWZQclSrwbi2Z/JzUySiDY6BE+goAczIoqrBibP29VbN4+w9Ns1 S994X42q97s8kpGLiApBJDw61q/AEsP7BbgkA1g8toreEbVRksTfogufLvYiEwQY +6f3f8mviahjGbHYoAPmRkFciJ7W91Mny0ZBFA+LiOjgV/9MBfQ= =AS2V -----END PGP SIGNATURE----- --LRjFRBuVI37RIk+2--