title: java.lang.OutOfMemoryError when reading from a large table
body: <p>I'm trying to pre generate reports from a very large table(300GB) in PostgreSQL. I do something like this:</p>
  
  <pre><code>rs = stmt.executeQuery("SELECT * FROM tbl");
  System.out.println("select all finished");
  while (rs.next()) {
      /* generate report and save it in report table */
      /* generated reports are not in memory, 
       * They are saved in a summary table in each iteration */
  }
  </code></pre>
  
  <p>When I start the application it gives <code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space</code>. I tried to use <code>stmt.setFetchSize(1000)</code> But it doesn't solve the problem.</p>
  
  <p>What is the solution? I'm using PostgreSQL 8.4.11 on Debian 6.0.5 and openJDK 6.</p>
  
  <p><strong>[UPDATE]</strong></p>
  
  <p>The printed stack trace shows that the <code>OutOfMemoryError</code> exception has been generated in <code>rs = stmt.executeQuery("SELECT * FROM tbl");</code> line. Also <code>System.out.println("select all finished");</code> never shows. </p>
  
  <ol>
  <li>I'm running in <code>autocommit</code> mode.</li>
  <li><code>stmt.getResultSetConcurrency()</code> returns 1007.</li>
  <li><code>stmt.getResultSetHoldability()</code> return 2.</li>
  <li><code>rs.getType()</code> returns 1003.</li>
  </ol>