Re: setPrepareThreshold

From: Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
To: Robert DiFalco <robert(dot)difalco(at)gmail(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: setPrepareThreshold
Date: 2014-01-17 15:49:38
Message-ID: CAH7T-aqtP0BFAuWSCQjdR9-hdz8NFGKK=vLsOLADxO11HZDrgw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Fri, Jan 17, 2014 at 10:31 AM, Robert DiFalco
<robert(dot)difalco(at)gmail(dot)com> wrote:
> I was wondering why this setting exists and why it is by default disabled?

This setting is the number of times a PreparedStatement needs to be
reused before the driver instructs the PostgreSQL server to create a
server side prepared statement for it. Server side prepared statements
have cached executions plans so in theory they should run a bit
faster. The down side is that they take up resources (memory to cache
the plan) and since the plan is cached, it won't change if you change
based up on the passed in parameters.

The default isn't disabled, it's "5". That means that if you execute
the same PreparedStatement 5 times it will be converted to server side
prepared statement and subsequent executions will use the server side
one.

> Is there some danger associated with it or some reason I would NOT want it
> to be set?

If you set it very low and you have a lot of different SQL statements
that aren't actually being reused, then you will have a lot of
prepared statements on the server side taking up needless resources.
The default of "5" should be fine for most purposes.

Check out these links for more details:

http://jdbc.postgresql.org/documentation/81/server-prepare.html
http://stackoverflow.com/questions/8104595/why-is-the-postgresql-jdbc-prepared-statement-threshold-defaulted-to-5

Regards,
-- Sehrope Sarkuni

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jeremy Whiting 2014-01-17 16:48:10 Re: Performance improvement proposal. Removal of toLowerCase calls.
Previous Message Dave Cramer 2014-01-17 15:47:41 Re: setPrepareThreshold