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 1rts2j-000SN7-Ng for pgsql-general@arkaria.postgresql.org; Mon, 08 Apr 2024 16:40:26 +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 1rts2i-00A0Uz-Ge for pgsql-general@arkaria.postgresql.org; Mon, 08 Apr 2024 16:40:24 +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.94.2) (envelope-from ) id 1rts2i-00A0Ur-67 for pgsql-general@lists.postgresql.org; Mon, 08 Apr 2024 16:40:24 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rts2e-001bHA-6E for pgsql-general@lists.postgresql.org; Mon, 08 Apr 2024 16:40:22 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5aa400b917dso602337eaf.0 for ; Mon, 08 Apr 2024 09:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712594418; x=1713199218; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=vEkhIyimv0thm8Ec5beio9vRDyHqZVgdfKFInMNLQHY=; b=mJ9G3j01BKC803LDXSgAvqcBq0dlrbByXAhlpJUZ8pJ4Zj6G00PhZ6ODVKtV2JwKMj uqwzTBVaSUZfJHRqQoeUOJOlTVUEmsDz/OoH4Sr5zJq+KJJvIk0+9q/goClSTqhxow9q WipnsGOkndwgkeZzFXr91uqMwvcPWCsYom4zHQ65r1+w+Qih+pS0Kyic3nARioDFVspk 4N1ql/dtLkZaQMojWGXH6mXWRwl4fRNVsyLfEekxkV57JmbGQibjUdsDPimC/sOoX9Yg b9I4S6R2nImAmXIVirYg6+Siytlndnt2UDp7leP7AgS7UXUWn0mxD+fFjHg5NiwPG4Ei iBug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712594418; x=1713199218; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vEkhIyimv0thm8Ec5beio9vRDyHqZVgdfKFInMNLQHY=; b=ZBppQumVWOnd+29c3Akb1lNakAflRl7xe2TRK2e2ed50oI0n+v/2SYBEau9UfxZbUc Uec6nLDUcUijAt3E/tIQx3WW5PoTsk2PUX6YNXoNDn072TW8XVQEVa+5GoyJnsCjUwIw KtNoWAFa4ag66NJW8muHW2xqABZXLxpYlFBBqIUB8xzdVsyti+Ne9mjEq6w1V4kUMsDh +CZuF5KPprZgd7m2imwoM3UQ/xcoMVs/7e7LSgSaMd9Ru8tvl3y/YeHvs4eqOGfD1SWs h7JFav8NiIwuphn725rInsScGHNbz+ZoH5qJk34J13C6m9Gimk1TQNFfXUefTy/UQvRr 4hVQ== X-Gm-Message-State: AOJu0YwVC0NmT+qhx1tGmk45vsIpOi5yr9OsWsLQGSiBds8VZUhU7ZHH hrpmPfttCXlf9w1m7WgNb4ISBDPyqF1iX8G32y4AaL0bBQHBUgxLLc6NhLGtqCJbe+Ci5U6Ga5e 8gjd6cLdgigG90EclGm2uyK+S7SY= X-Google-Smtp-Source: AGHT+IF1Hhc87tTm8T+ayJ5NCpU5TKgPnydA6hr2DeRUdARylJoM8TyfdZMViWTSDqHdcNL60jdGV0mHQJgb/wGspF4= X-Received: by 2002:a05:6871:8aa:b0:22e:e1e5:b8d with SMTP id r42-20020a05687108aa00b0022ee1e50b8dmr10470704oaq.51.1712594418119; Mon, 08 Apr 2024 09:40:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Dominique Devienne Date: Mon, 8 Apr 2024 18:40:07 +0200 Message-ID: Subject: Re: prepared statement "cu1" already exists (but it does not) To: Sebastien Flaesch Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000efc2260615987536" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000efc2260615987536 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 8, 2024 at 5:31=E2=80=AFPM Sebastien Flaesch wrote: > I understand when this can happen, but in fact I do de-allocate prepared > statements when I should. > We've run into similar issues. We're in C++, and with RAII deallocate resources (Prepared Statements, Cursors) in Dtors. But as you saw, when a TX is KO, any Dtor trying to release resources via libpq will fail. So what I do it record those resources (stmt and cursor names basically) on the Connection (in our wrapper), and will release them at the first opportunity, once the TX has rolled back for example. FWIW. OTOH, we tend not to reuse names, generating random ones, since when using our wrappers, the name is an impl details basically. We also tend to prepare outside transactions, so can't answer your question on whether prepared statements within TX are "scoped" or not. --DD --000000000000efc2260615987536 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Apr 8, 2024 at 5:31=E2=80=AFPM Se= bastien Flaesch <sebastien.= flaesch@4js.com> wrote:
I understand when this can happen, but in fact I do de-alloca= te prepared statements when I should.

We've run into similar issues. We're in C++= , and with RAII deallocate resources (Prepared Statements, Cursors) in Dtor= s.
But as you saw, when a TX is KO, any Dtor trying to release re= sources via libpq will fail. So what I do it record those
resourc= es (stmt and cursor names basically) on the Connection (in our wrapper), an= d will release them at the first opportunity,
once the TX has rol= led back for example. FWIW.

OTOH, we tend not to r= euse names, generating random ones, since when using our wrappers, the name= is an impl details basically.
We also tend to prepare outside tr= ansactions, so can't answer your question on whether prepared statement= s within TX are "scoped" or not. --DD
--000000000000efc2260615987536--