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 1wT09Z-000FcC-1u for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 16:33:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wT09Y-003UcO-0f for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 16:33:44 +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 1wT09X-003UcG-2C for pgsql-hackers@lists.postgresql.org; Fri, 29 May 2026 16:33:44 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wT09V-0000000099w-0iXr for pgsql-hackers@postgresql.org; Fri, 29 May 2026 16:33:43 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-43bfe209e45so3200317fac.0 for ; Fri, 29 May 2026 09:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780072420; x=1780677220; darn=postgresql.org; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=SUIwF0RltraTJu6xtwcQAUlarL8HmcMc6dS0Md6IzGY=; b=ru21qbE96xJIdHY3CeHBiWE3LIIQL+8iknb7CuSmSZ6GraZtDtBBxO9ZaW8gDObMI8 OAi5vHJeJeHSQ4OvrWT2cdaThWO4nNN+pczw97TIPwnzroRRdJ7yhwq9R0YVAvFgJjCs Qin5xkS1OsNxP2Cj9SdalCFzCXHvOPCTw71KokSPyF513/QOzz2rayzrpQN3UC1SsS53 zC1Z+8m0ytGI4T1dawg79H9WUBSjZvc1ggUpW+fLvIaDfM87tC+XWHIDFnI2QJELrbC8 9MUsAmg0Wq5MxwzfVxO4bwuoleV4VDo44U9kpIUnx+XsJFdF4FXEPtwSdUlP6ZzT/WmK Jozw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780072420; x=1780677220; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SUIwF0RltraTJu6xtwcQAUlarL8HmcMc6dS0Md6IzGY=; b=VfDOuLep5X7R/NoL9kgn1yXhWzIeCL0GrJftvPdSMhEkFivKrz5C+A6Q1DC0Y2lYTV buOEE2M5jAynD0Yc4q7UUXfgYW7MMu++EXyiGoS+D8cei7HzEmPJFp3WI6vHh9AMxHJ+ Y9BruhW1Ru6zXgbpbf0jQPolKukBu7LvGvSNYnv4SDixt5EpsuuNASSwujh+e1LYTva2 u55CAxxzPwPpdwjBPMuVG8P2cF8ByF1jXc1RxgTl8wwcLL2feSFmLgtpuWTRa1yu888/ lrZxH2LcLKzFwoFNu4Jl/l35gsiIjERfmV11xxnrUTs9Cb7EFUGz3vCciLNK1hiuPRUf +aVg== X-Gm-Message-State: AOJu0YzDhbWl2LCiqtGQMnB/4Ae3Lh7IecDEhSeUbUdEWKW2Bm0id4gW 4vqEaQVvftcw3lSwD7aP+bL+aAFo3ZAdJk/nl9fGQbb4Vp+0zmZaOA02 X-Gm-Gg: Acq92OG3/EsdZO5IzX5O9UKenGpDBXovDAbNmTnGqTaMsdtG9Q3Orlq/DhH+BG0fzwD swWqeqsAApSofffjXoykzQZ5TDoIpnvBpaFI8hKdocP681AiK270G9Vwiu2VQom9uOcRujFoZMm EITJVqigL4IhMv9fajCzbI23Ho1laNml0eMSrK/WLD/u0RAvYjsF1KfthAJ9miyCbaTHHDWaZPE /qxuyY4+jE/DRkf45Z+AvzOjOe2Nb/6TO24mJ09DKrWfw2qF0u1fggbukOF6Sb4lw1FbktJByuN 127jofhHaLtfirmLMLDetMqidE+ol+Si2ZchOdPDWdBxNNpB9wF7ginCSrTrccgBYPAkpRNDZNs SCYGdmjqiKK9qbDlny0vJuVh1cR0QMJYMzhKOTEVIpbZHdE0bxyvtvMa8Os2MUg8SVyGYzVsRUM 0k4AAB/m0r7oj7aWiodIMgEj8Grc5+Ad1Y0i4OLidBIYW+/nsvrLnKLxA/2fL58NJQvVHXQDAjJ L7Ok1V066kT0fenu2zXZ1aFEgNGpwwO X-Received: by 2002:a05:6871:81e:b0:43b:9922:9ddd with SMTP id 586e51a60fabf-43ca425b65dmr327674fac.27.1780072420218; Fri, 29 May 2026 09:33:40 -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-43c93b15991sm1264710fac.8.2026.05.29.09.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 09:33:39 -0700 (PDT) Date: Fri, 29 May 2026 11:33:37 -0500 From: Nathan Bossart To: Jacob Champion Cc: pgsql-hackers@postgresql.org Subject: alert clients when prepared statements are deallocated Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tbByXeXYMjI7URMk" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --tbByXeXYMjI7URMk Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit (Moving to a new thread since this seems like an independent feature. Original discussion can be found here: https://postgr.es/m/ahXE28klgxIJXBLq%40nathan) When trying to take our own advice and teach the frontend LO interface to use prepared statements instead of PQfn(), I discovered a couple of problems. The biggest problem is that clients aren't alerted when a prepared statement is deallocated with DISCARD or DEALLOCATE. Since this seems like a general problem that affects more than just libpq's LO functions, I'm seeing whether it makes sense to add some sort of notification mechanism so that clients can re-prepare as needed. Some initial discussion about the work-in-progress patch (which I've attached again here) follows: On Fri, May 29, 2026 at 11:10:58AM -0500, Nathan Bossart wrote: > On Fri, May 29, 2026 at 08:43:07AM -0700, Jacob Champion wrote: >> On Fri, May 29, 2026 at 8:14 AM Nathan Bossart wrote: >>> Here is a work-in-progress patch set that goes this direction. >> >> At a high level, I think advertising support for a single new message >> needs to be done in a protocol extension rather than a minor version >> bump. > > WFM > >>> This >>> introduces a callback mechanism in libpq that is used to handle statement >>> deallocation notifications. Older servers/clients fall back to >>> PQexecParams(), which is slower, but the alternative is to leave PQnfn() >>> and related code around indefinitely. >> >> IMO there's no hurry in getting rid of that path. If we decide to go >> this direction, a fallback to PQnfn() seems like it'd fine for a few >> releases; we could eventually swap to a PQexecParams() fallback and >> get rid of the extra code once the older servers have aged out. > > That's fine with me, too. > >>> I'm wondering whether this new message type is general enough. For >>> example, perhaps we could make an extensible message type for tracking >>> various things. And I want to ensure this is useful for other clients, >>> too. >> >> If it's just a general notification message, what does negotiating >> "support" mean? Is best-effort notification okay, if the client has no >> idea what a future message type means, or if the server doesn't send >> the specific type of message the client is hoping for? > > That's what I had in mind. But if we don't have anything specific in mind > that this mechanism could be extended to support, maybe we shouldn't > bother. Especially if we can just add protocol extensions as necessary. > >> (In general, I'm kind of down on the "notify the client that X >> happened" method of working around architectural issues. Maybe that's >> what we need to move this specific part forward, but it doesn't feel >> like a long-term solution and I don't know that we need to genericize >> it without a solid set of use cases.) > > I'm certainly open to other ideas, but I'm afraid this is the best I've > come up with in my admittedly limited time thinking about the problem. -- nathan --tbByXeXYMjI7URMk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0001-tell-client-when-prep-stmts-are-deallocated.patch