Re: Prepared Statements and Pooling - Mailing list pgsql-general

From Andomar
Subject Re: Prepared Statements and Pooling
Date
Msg-id D3E7067F-F571-45FE-ABB1-764F7320F00D@aule.net
Whole thread Raw
In response to Prepared Statements and Pooling  (Mister Junk <junkmail3568540@gmail.com>)
List pgsql-general
> I have considered opening a single connection to the server and letting all threads execute statements through it,
anduse prepared statements (serviced by postgresql, not JDBC or DBCP).  Or simply opening 50 connections and
establishingprepared statements and then handing them off to the threads.  Is there a reason I shouldn't do this?  I
readthat the JDBC driver for postgres is thread safe. 

Connection pooling reduces the overhead for creating a new connection, and allows Postgres to reuse execution plans for
preparedstatements. Both things will gain you a few milliseconds per query. For a small or medium sized project that is
entirelyirrelevant. 

It is far more important to have stable and easy to understand code. To gain that, keep each connection open for as
shorta time as you can. Run a single query and then close it. 

When the time comes where the few milliseconds matter, it is easy to add connection pooling without changing a single
lineof code. Postgres offers pgbouncer and pgpool for that job, but if DBCP can do it, that’s fine too. 

Kind regards,
Andomar



pgsql-general by date:

Previous
From: Mister Junk
Date:
Subject: Prepared Statements and Pooling
Next
From: Alban Hertroys
Date:
Subject: Re: Prepared Statements and Pooling