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 1wUsy4-001W53-1v for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 21:17:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUsy3-003Qsw-0k for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 21:17:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUsy2-003Qsn-2Z for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 21:17:38 +0000 Received: from mail-oa1-x2d.google.com ([2001:4860:4864:20::2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUsy0-000000017ZE-3573 for pgsql-hackers@postgresql.org; Wed, 03 Jun 2026 21:17:38 +0000 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-43fc82b52afso37421fac.1 for ; Wed, 03 Jun 2026 14:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780521454; x=1781126254; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zwKhwpYgvzxAtDZpqIqrA6j6gt10ueny0L1T20vv/1Q=; b=IwshpQ1MiLxjkjujecDQhd0g8qa44Io57JL3KTPT67kupVSWQz2759CjyrK7XcQr1K EEq0GLSyvcxIaJaWbT47pWBTxkgQKkmrEEbLZxbJIgwrDdYFp8nHDrwtd6mxu6gQNm00 2ir07/2AiEEC/NkMKLTvFB3pg9/7cDil33/9HfVNBQSbTd8SyZXSzs4pnWgmNNM8EN4o 6Cm3SOE2CyYgNDobIto0S9UNwjkIKLXCZ72DE9dOHQ3DnQW2u3t6giwz+J/3DuMLXmJo A6PxWHC6MyBf9Y3xYkSLGmaPaYoq6FidVH3HmJTAbItoSYUWkER/43SIxWmM6pHekwwf zlVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780521454; x=1781126254; h=in-reply-to:content-disposition: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; bh=zwKhwpYgvzxAtDZpqIqrA6j6gt10ueny0L1T20vv/1Q=; b=LfDLGi7JIAQxeKKKaY5iaUKyAsFC1V3wfYb0ZzdwN6QRi9A0J2jz3/2nG6kAyW90Yg 1KGx5SKMP+jeeEULzAO7RNXY83CkBEysppDBLxlE7ivTBWqlCQIrKoHw3EB8PSOZ4Cbr evczPnAjWmD2dQasl7Lu8kwteQXAc/y9IKfGyYhJsR3naDK7t3RK7hzsXJUIFmOweTFH 5gplXphNBUuvGnjst4Ew7kbfkdP9FptTbRuVgWgvLcfCEBL6bRKSXm5wAKQQNTiyikU/ uujGWOzcF0MoqgwX7Xk/kXYnkNMqNZ84sQUI91QMDKMbp/MCGG2lzryba3Lx/PKzh8pR lWbg== X-Forwarded-Encrypted: i=1; AFNElJ+YQpOuI4pp34+MZr7+y2aNeiAj9eFYkfx+p29paao5M2WCCPkgiYKK9dyhPi37sxaHbdUjDoc5K2/iylPM@postgresql.org X-Gm-Message-State: AOJu0YzzEw6DoDKJCxowj9DW4+t4FtUgnVtEnD7iq9yHf3Zk4l7b7CYj xpM2/ZPz5+WBiAsCdXvBGcQcyHxTsKzvsHvGvmzZi025TLLp+VS7/Pti X-Gm-Gg: Acq92OFPErkRk0pQo/q3d5vjP2vZeYzr1IQ30cQzyRVxVGTC7zfcdvZL/Qt7GvaIk3p b0LIssERj5BavSrYq0OfagN6S0FaGHlGpbZgXet4EtjOf/RBU8NEfevIri3mPbjOdmD4YQba1bH C1f8axdysM4t4FwTyTtZIonS+DJP6uWwvPuL6OenBvppzEE/k03w/bPHXuBQhPl9gqvFBiVi5Nm 218+8iB9WhrWWzn3tiAnD1y1cjX5j9qFXBVpv7Y4Zv5n+Xt5QEY/Z7DMIVeZwozlMeXA8Mgh/rb MCjrcNQJvdoeFGBz0Q6nBgVaEOEYDMBcDYLbgrov382AWqpdUo0qtRwCPVDhDlIPvkNm1hmMXb+ EW1MyssbuKz04qOu0x7/XX3TNOddwVL1Z9CfbOk8k4g8XoUZqJ4lEB29SV947w63jABVkpz1DTC vgvy8gc4yJ0gOKtxukcx6fMRL83uK3mmep9xpTO4Umd1i/btUZwX4bLKks0AIlE4grmQa2zPP5O juEMvecx1z6064+cCBEt3fmtYnXPPKGhIP9PPbIWSg= X-Received: by 2002:a05:6870:179e:b0:43b:fbd9:3c4c with SMTP id 586e51a60fabf-440db7e1e18mr3283556fac.20.1780521453861; Wed, 03 Jun 2026 14:17:33 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-440d7c351e3sm3156639fac.5.2026.06.03.14.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 14:17:33 -0700 (PDT) Date: Wed, 3 Jun 2026 16:17:31 -0500 From: Nathan Bossart To: Tom Lane Cc: Jacob Champion , pgsql-hackers@postgresql.org Subject: Re: alert clients when prepared statements are deallocated Message-ID: References: <1689313.1780074543@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jun 02, 2026 at 05:11:52PM -0500, Nathan Bossart wrote: > * I'm a little worried about race conditions involving a client trying to > use a statement while a deallocation message is in flight, but I haven't > identified anything concrete so far. This is something I'd like to > investigate some more, though. Hm. So there's actually a pretty obvious problem here. Say a user executes something like PQsendQuery(conn, "DISCARD ALL") and then tries to execute an lo_* function (modified to use prepared statements) prior to consuming the result. In that case, the callback won't be called in time and the LO function will fail. My first instinct is that this is a showstopper for $subject, but perhaps it is a rare enough scenario that we could live with documenting it. My suspicion is that it's uncommon for folks to asynchronously deallocate all prepared statements, and I don't know why you'd use PQsendClosePrepared() on statements named libpq_internal_*. Nevertheless, this seems like a rather large hole. I think this calls into question whether moving the libpq interface to prepared statements makes sense. If we can't do that, I think we're pretty much forced to keep the fast-path around forever or to accept a larger performance hit. In any case, I find it a little strange that there's not a great way to use prepared statements internally in libpq, which is why I'm chasing this a little more than perhaps I should. -- nathan