Postgres implements statement caching on the server-side. However, activating it through JDBC is a little tricky. The Postgres JDBC driver's Connection class has a proprietary method called setPrepareThreshold() that must be called, or else the driver will not inherently use the "PREPARE" command on the wire (it will instead treat even PreparedStatements as "one shot").
Even if you use another connection pool which provides "statement caching", without the above in reality each statement will be executing as "one shot". What you will effectively be caching is simply the Java PreparedStatement objects and nothing more. I have never seen this mentioned by other pools, probably because they never dove down into the PostgreSQL JDBC driver code.
Here is what you need to do. First, you will need to use the
dev branch of HikariCP until 1.2.7 is released (probably in a day or three). I have added the ability to
customize a connection before it is added to the pool. What you need to do is create an implementation of the
IConnectionCustomizer interface, like so:
public class PostreSQLConnectionCustomizer implements com.zaxxer.hikari.IConnectionCustomizer {
public void customize(Connection connection) throws SQLException {
((AbstractJdbc2Connection) connection).setPrepareThreshold(1);
}
}
Then set the HikariConfig connectionCustomizerClassName property to the qualified name of your class.
As noted above, switching to another pool that does "statement caching" will be of no actual benefit because what you really need is for PostgreSQL to cache the query plan. The PostgreSQL query plans are associated with the session (Connection), not with individual PreparedStatements.