Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id F0CB59F9BF2 for ; Fri, 28 Sep 2007 21:30:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 37125-03 for ; Fri, 28 Sep 2007 21:30:36 -0300 (ADT) X-Greylist: delayed 00:05:19.781119 by SQLgrey-1.7.5 Received: from mirth.inuus.com (mirth.inuus.com [67.100.95.85]) by postgresql.org (Postfix) with ESMTP id A186E9FA513 for ; Fri, 28 Sep 2007 21:30:41 -0300 (ADT) Received: from mirth.inuus.com (localhost.localdomain [127.0.0.1]) by mirth.inuus.com (8.14.1/8.14.1) with ESMTP id l8T0PD8A009544 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 Sep 2007 17:25:13 -0700 Received: (from lindner@localhost) by mirth.inuus.com (8.14.1/8.14.1/Submit) id l8T0PDLp009543; Fri, 28 Sep 2007 17:25:13 -0700 X-Authentication-Warning: mirth.inuus.com: lindner set sender to lindner@inuus.com using -f Date: Fri, 28 Sep 2007 17:25:13 -0700 From: Paul Lindner To: pgsql-jdbc@postgresql.org Subject: Prepared Statements vs. pgbouncer Message-ID: <20070929002513.GG3140@inuus.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="APlYHCtpeOhspHkB" Content-Disposition: inline User-Agent: Mutt/1.5.14 (2007-02-12) X-Virus-Scanned: ClamAV 0.91.2/4422/Fri Sep 28 14:44:56 2007 on mirth.inuus.com X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/130 X-Sequence-Number: 17552 --APlYHCtpeOhspHkB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, I've been trying to implement pgbouncer in my environment and have come up against a few issues with the JDBC driver. The symptoms surface as an error redefining a the statement S_1. "S_1" already exists I read the documentation and set prepareThreshhold=3D0, and the problem decreased but did not go away. Digging deeper I believe I've found out why this occurs. The problem only occurs when JDBC statements use a non-zero fetchSize. This results in the driver creating a named statement. Specifically the problem occurs when clients use a recycled backend. Here's the scenario: * Client A creates statement S_1, fetches results. When finished the statement is put in a cleanup queue. * time passes * pgbouncer notices that client A is idle and reassigns backend to=20 client B * client B tries to create statement S_1, but fails. (S_1 is already defined) ...=20 So the combination of lazy cleanup and the assumption of a singular client->server backend is causing this problem. I can see two solutions: 1) Forcing cleanup of prepared statements when exiting a transaction block. (Seems like this would be hard...) 2) Allowing the client to specify a unique prefix for the statement handles. (This seems easy, but could result in a leak of named statements in the scenario above) I'd be fine with #2, since we can configure pgbouncer to recycle backend connections to protect us against prepared statement leaks. I'd be happy to work to make this possible. Thanks! --=20 Paul Lindner ||||| | | | | | | | | | lindner@inuus.com --APlYHCtpeOhspHkB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFG/Zto+FkoUnP1gFQRAjhLAJwN7OFHwdsYAuPeXY0WGT1fisIosgCgnAZz wsnsszylJobd6+XfiPYciFY= =468Q -----END PGP SIGNATURE----- --APlYHCtpeOhspHkB--