title: should i activate c3p0 statement pooling?
body: <p>we are running java6/hibernate/c3p0/postgresql stack.
  Our JDBC Driver is 8.4-701.jdbc3</p>
  
  <p>I have a few questions about Prepared Statements. I have read 
  excellent document about <a href="http://www.theserverside.com/news/1365244/Why-Prepared-Statements-are-important-and-how-to-use-them-properly" rel="noreferrer">Prepared Statements</a></p>
  
  <p>But i still have a question how to configure c3p0 with postgresql.</p>
  
  <p>At the moment we have</p>
  
  <pre><code> c3p0.maxStatements = 0
   c3p0.maxStatementsPerConnection  =   0
  </code></pre>
  
  <p>In my understanding the prepared statements and statement pooling are two different things:</p>
  
  <p>Our hibernate stack uses prepared statements. Postgresql is caching the 
  execution plan. Next time the same statement is used, postgresql reuses the 
  execution plan. This saves time planning statements inside DB.</p>
  
  <p>Additionally c3p0 can cache java instances of "java.sql.PreparedStatement" 
  which means it is caching the java object. So when using<br>
  c3p0.maxStatementsPerConnection  =  100 it caches at most 100 different<br>
  objects. It saves time on creating objects, but this has nothing to do with 
  the postgresql database and its prepared statements.</p>
  
  <p>Right?</p>
  
  <p>As we use about 100 different statements I would set 
    c3p0.maxStatementsPerConnection  =   100</p>
  
  <p>But the c3p0 docs say in <a href="http://www.mchange.com/projects/c3p0/index.html#performance" rel="noreferrer">c3p0 known shortcomings</a></p>
  
  <blockquote>
    <p>The overhead of Statement pooling is
    too high. For drivers that do not
    perform significant preprocessing of
    PreparedStatements, the pooling
    overhead outweighs any savings.
    Statement pooling is thus turned off
    by default. If your driver does
    preprocess PreparedStatements,
    especially if it does so via IPC with
    the RDBMS, you will probably see a
    significant performance gain by
    turning Statement pooling on. (Do this
    by setting the configuration property
    maxStatements or
    maxStatementsPerConnection  to a value
    greater than zero.).</p>
  </blockquote>
  
  <p>So: Is it reasonable to activate maxStatementsPerConnection with c3p0 and Postgresql?
  Is there a real benefit activating it? </p>
  
  <p>kind regards
  Janning</p>