title: Geoserver - PostGIS performance issue
body: <p>We have noticed something strange in the interaction between our Geoserver instance and Postgres/PostGIS.</p>
  
  <p>After setting Geoserver's log level to include developer debugging, I managed to capture a single request from Geoserver WMS to PostGIS.</p>
  
  <p>The (shortened) sequence of events and their timestamps:</p>
  
  <pre><code>12:31:22,658 - SELECT query for MSG is sent to Postgres
  12:32:10,315 - Rendering for MSG layer starts
  12:32:10,356 - DB Connection Closed
  ~ 48 seconds
  </code></pre>
  
  <p>Interestingly enough, when I execute the same query (MSG) directly from PgAdmin3:</p>
  
  <pre><code>SELECT "frp_mw",encode(ST_AsBinary(ST_Force_2D("the_geom")),'base64') as "the_geom" FROM "public"."af_msg_abba_datetime_today" WHERE ("the_geom" &amp;&amp; GeometryFromText('POLYGON ((-27.67968749408379 -46.92207325648429, -27.67968749408379 -6.186892358058866, 75.67968748740275 -6.186892358058866, 75.67968748740275 -46.92207325648429, -27.67968749408379 -46.92207325648429))', 4326) AND (("frp_mw" &gt;= -1 AND "frp_mw" &lt;= 150) OR ("frp_mw" &gt;= 151 AND "frp_mw" &lt;= 300) OR ("frp_mw" &gt;= 301 AND "frp_mw" &lt;= 600) OR ("frp_mw" &gt;= 601 AND "frp_mw" &lt;= 50000)));
  </code></pre>
  
  <p>I get 6515 rows in 380 ms.</p>
  
  <p>Ie Postgres is able to return the results of the query within 380ms if queried from PgAdmin3 but Geoserver takes about 48 seconds to get hold of the same resultset.</p>
  
  <p>Is this some kind of JDBC problem perhaps?</p>
  
  <p>Some details about our setup:</p>
  
  <p>Master Postgres database is on a separate VM from Geoserver, but we replicate to a slave Postgres cluster on the Geoserver VM (same host). So Geoserver is referencing the 'localhost' read-only Postgres cluster for its queries.</p>
  
  <p>The 380 ms response time shown above was from the slave Postgres cluster, same one that Geoserver is using.  </p>
  
  <p>All Linux (Ubuntu 11.10) based. Postgres 9.1 PostGIS 1.5 Geoserver 2.1.3</p>