Re: Prepared Statements and Pooling

Поиск
Список
Период
Сортировка
От Andomar
Тема Re: Prepared Statements and Pooling
Дата
Msg-id D3E7067F-F571-45FE-ABB1-764F7320F00D@aule.net
обсуждение исходный текст
Ответ на Prepared Statements and Pooling  (Mister Junk <junkmail3568540@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Mister Junk
Дата:
Сообщение: Prepared Statements and Pooling
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: Prepared Statements and Pooling