Connection Pooling with PostgreSQL JDBC Connection Pooling with PostgreSQL JDBC postgresql postgresql

Connection Pooling with PostgreSQL JDBC


Use org.postgresql.ds.PGPoolingDataSource
Here is an example: http://jdbc.postgresql.org/documentation/head/ds-ds.html
I've checked this example using JDBC4 driver and it worked fine.

However in documentation from this link they discourage from using postgreSQL pooling data source because of it's limitations:

The pooling data-source implementation provided here is not the most feature-rich in the world. Among other things, connections are never closed until the pool itself is closed; there is no way to shrink the pool. As well, connections requested for users other than the default configured user are not pooled. Its error handling sometimes cannot remove a broken connection from the pool. In general it is not recommended to use the PostgreSQL˘ provided connection pool. Check your application server or check out the excellent jakarta commons DBCP project.

They recommend to use DBCP connection pool: http://commons.apache.org/proper/commons-dbcp/check it, it is much better - just download library files, place them in a classpatch and import to the project, documentation from the above link contains examples how to use it in code.

Most (all?) application servers implements their own connection pools, if you are using the application server, it's the best option.
For Example Tomcat 7 has it's own implementation of the connection pool, it's even better than DBCP, check documentation: http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html