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 1wT1xI-000Gj0-2K for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 18:29:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wT1xF-003xqP-36 for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 18:29:10 +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 1wT1xF-003xqH-20 for pgsql-hackers@lists.postgresql.org; Fri, 29 May 2026 18:29:10 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wT1xD-00000000BZZ-1mQM for pgsql-hackers@postgresql.org; Fri, 29 May 2026 18:29:09 +0000 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7e61da76fd9so4958600a34.0 for ; Fri, 29 May 2026 11:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780079345; x=1780684145; 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=in0th6SJ/pFoIg3w7BpBoqegzFvHhl01s04LgZNB++I=; b=Pga70aFUdQqNTnQ7ygOwVCvNSzZLxr6tN8kbremj/TzOF+T0pN99yePOY5mMrQB5mQ Z7DByiAbzxcgYa/790Wf81Lf0ISJEsrjduhNys3TWFhcVet5oaQN1dIBJtnSiJ+7rJK2 96aVqjYoEJLY26umVbFDob2uYl1qZWkFTtIpNmr2MWagVvRJ5jR3vQU4P9vL28Hiee2A wv3EengN3V9zzUpSfFA62kWZYoq2MYNT710kNd3d8FdXDN3wU3K60R8DCPQAGDNu5pJT wPK64GobLC8zTprht6AHNBCWtkvqyX1uwmB88GIQEzHJrbBMSMAim7IqXVov6wO7soZQ qhsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780079345; x=1780684145; 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=in0th6SJ/pFoIg3w7BpBoqegzFvHhl01s04LgZNB++I=; b=grsyDyxEqvhdo3E/d94L9vKfb7hCHLro0GWFrK7VDzqPvjwCOON2AkUWstkHuz19k8 42SwdekgG75nfHvMup8Pa2pc2umHHzg+VY6b98LZSnZMuvWWbEfI79ZSJhYSD4g/yNYo VA6+kMm48O4cyTQsn9NnF2I3OGkrpCTadDU0RBIWB+xrFjri5SXYmfM2N51iXMHjFEaW t4ubGxwpBy0clSOXELTuVDM1LzxBCOUfoR3ysEOqywnYWVPTCDzScsVqAsVE0TIP5LYR wKaUuIpPFfbu3BcZcjA05GoFFtizW780OFhsKj2PBTflIEZmcZIR5bUotKsWKaAnFin+ RauQ== X-Forwarded-Encrypted: i=1; AFNElJ+vL23UeUVqqaC65FuBzTL41nXGKDnopP09ZJA4D+8a25du+XwHNMHK1s2BdQy55fUFNJgGKVLIZn9JU0kc@postgresql.org X-Gm-Message-State: AOJu0YxYnrbg+lTbAOExfcgejJWixKaVtl8mEaeDqogntSnNyYXBdLZl lAnYnGTEGD59wZnC2lhwc8NJutaN4RZMGtr7dp3Cak9+wk1vn/yH4F+9 X-Gm-Gg: Acq92OEyIPb0+FcAIGyUW8oH+DnNuhzT2vaYhVK6CyEJEVfXCDVKfY1KAi/rEuCNDO3 ZhaxfDlG82w9ATVHAOQTq74ffW8DBLgnp57aeA6gWZh5p44NkgucwmEd8lKg7ig3qxWQG/e8ANV 8InML5C5NwKUGHk4S1twHk/yMNijA2f+bziPe/vaqIQNPpsdEuGgcBqWp1WhFQIutMqaV/EE16K 4Ie7LhTrd96YUQUGv6W8F0ugRb1q4Aqxyhidrnh9Q9VML5Yc46YJDgwr4evrbfrMW0HShfT6OPS Ya/YvM+Nm3XAdD3MKmNCUq6cTCiWTIfG9EA+KbpQD73wN8jNNpuckDBd2kKMB4FAhLUvq1aI+5+ 25pPKwBPaxEWx2KlCM+BQCZsBeAQc8oVEhqVbpwROeg+eW8+ijVIDmMgEyrQebxFtqH+/yfWCkR qooGb7mvpb5vlNQaH6ztDrpDJ3F0t5ghi5Ybz4OJnJdF6xVukZSG1Jli+76xpi6Nloggdh8U/T7 a3MijvDzSJDWGs0uSnPnIBt+RtQD3Ji X-Received: by 2002:a05:6820:199b:b0:67e:eb4:238f with SMTP id 006d021491bc7-69e102f271cmr286455eaf.18.1780079345257; Fri, 29 May 2026 11:29:05 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-69e0696e089sm1434028eaf.9.2026.05.29.11.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 11:29:04 -0700 (PDT) Date: Fri, 29 May 2026 13:29:02 -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: <1689313.1780074543@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, May 29, 2026 at 01:09:03PM -0400, Tom Lane wrote: > Nathan Bossart writes: >> 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. > > Of course the first question about that is "why doesn't the client > know that already ... didn't it issue the deallocate itself?". > The core answer to that question is that there might be multiple > levels of client code involved, so that while some level of the client > stack probably knows it in some way, other levels might have created > prepared statements and not be aware that they're gone. Right. > Therefore, having the server report this is only a partial answer > to the problem: it will only directly provide a fix to the bottom > client code level. To go further you'd need some inside-the-client > mechanism for propagating the notification up the client stack. > We can't really create that in general, but we can at least make > libpq be a responsible citizen in that chain. In short, a proposed > fix for this must also provide a way for the calling application to > hear about these reports, and a way for it to fall back if they're > not available. This is the intent of the callback mechanism. In short, a libpq user could register a callback that runs as soon as a deallocation notification is received. We could also add a default callback that stores a list of deallocated prepared statements (or a subset that a caller has indicated interest in). Callers could then call libpq-provided functions to retrieve and reset that list. My hunch is that might be more convenient for projects that use language bindings. -- nathan