Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 48BD66353C6 for ; Wed, 14 Apr 2010 20:10:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 16754-10 for ; Wed, 14 Apr 2010 23:10:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 7F202632F71 for ; Wed, 14 Apr 2010 20:10:38 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 89708AE27E; Thu, 15 Apr 2010 07:10:30 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail2.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id whijs6-0CrWN; Thu, 15 Apr 2010 07:10:24 +0800 (WST) Received: from [10.1.1.5] (203-206-36-38.dyn.iinet.net.au [203.206.36.38]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 7D758AE261; Thu, 15 Apr 2010 07:10:24 +0800 (WST) Message-ID: <4BC64B64.5070608@postnewspapers.com.au> Date: Thu, 15 Apr 2010 07:10:28 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100404 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: Dave Crooke CC: pgsql-performance Subject: Re: JDBC question for PG 8.3.9 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201004/179 X-Sequence-Number: 38429 On 15/04/10 04:49, Dave Crooke wrote: > Hi foilks > > I am using PG 8.3 from Java. I am considering a performance tweak which > will involve holding about 150 java.sql.PreparedStatment objects open > against a single PGSQL connection. Is this safe? > > I know that MySQL does not support prepared statements /per se/, and so > their implementation of PreparedStatement is nothing more than some > client-side convenience code that knows how to escape and format > constants for you. Is this the case for PG, or does the PG JDBC driver > do the real thing? Pg supports real server-side prepared statements, as does the JDBC driver. IIRC (and I can't say this with 100% certainty without checking the sources or a good look at TFM) the PostgreSQL JDBC driver initially does only a client-side prepare. However, if the PreparedStatement is re-used more than a certain number of times (five by default?) it switches to server-side prepared statements. This has actually caused a bunch of performance complaints on the jdbc list, because the query plan may change at that switch-over point, since with a server-side prepared statement Pg no longer has a specific value for each parameter and may pick a more generic plan. Again only IIRC there's a configurable threshold for prepared statement switch-over. I thought all this was in the PgJDBC documentation and/or javadoc - if it's not, it needs to be. -- Craig Ringer