title: Cursor error with postgresql, pgpool and php
body: <p>Hey, I am struggling a bit to determine the exact cause of an error that has been popping up in our release environment. There does not seem to be much dealing with this particular error on Google.</p>
  
  <p>This is the error message we are getting:</p>
  
  <blockquote>
    <p>SQLSTATE[34000]: Invalid cursor name:
    7 ERROR:  portal "" does not exist</p>
  </blockquote>
  
  <p>The error only pops up when we are using PDO prepared statements. </p>
  
  <p>This is the setup for our release environment:</p>
  
  <ol>
  <li>pgpool 3.0.1 (The postgresql backend is in Streaming Replication mode!)</li>
  <li>PHP 5.3.5</li>
  <li>PostgreSQL 9.0 </li>
  </ol>
  
  <p>Edit: Architecture is 64bit.</p>
  
  <p>The same error does not manifest in our test environment (Edit: forgot to mention, the standard test environment uses Postgresql 9.0 without pgpool). Thus, I am led to suspect that pgpool is at least partly suspect. </p>
  
  <p>Does anyone know what the probable causes for this error are? </p>
  
  <p>Edit: ok, here is an example of the kind of code that causes the error. </p>
  
  <pre><code>$sql = 'SELECT * ';
  $sql .= 'FROM "myTable" as "myStuff" ';
  $sql .= 'WHERE "myTable"."status" = 1 ';
  $sql .= 'AND "myTable"."myTableId" = :tableId ';
  $sth = $this-&gt;_db-&gt;prepare($sql);
  $sth-&gt;bindParam(':tableId', $tableId, PDO::PARAM_INT);
  $sth-&gt;execute();
  </code></pre>
  
  <p>Edit: Some log file output;</p>
  
  <p>Postgresql:</p>
  
  <pre><code>postgresql-Sun.log-129- ORDER BY "id" 
  postgresql-Sun.log:130:ERROR:  portal "" does not exist
  postgresql-Sun.log-131-ERROR:  prepared statement "pdo_stmt_00000011" does not exist
  postgresql-Sun.log-132-STATEMENT:  DEALLOCATE pdo_stmt_00000011
  
  
  postgresql-Mon.log-82-  where "id" = 32024
  postgresql-Mon.log:83:ERROR:  portal "" does not exist
  postgresql-Mon.log-84-ERROR:  prepared statement "pdo_stmt_00000002" does not exist
  postgresql-Mon.log-85-STATEMENT:  DEALLOCATE pdo_stmt_00000002
  </code></pre>
  
  <p>pgpool:</p>
  
  <pre><code>LOG:   pid 22071: Replication of node:1 is behind 2080 bytes from the primary server (node:0)
  LOG:   pid 22071: Replication of node:2 is behind 2080 bytes from the primary server (node:0)
  LOG:   pid 13499: pool_send_and_wait: Error or notice message from backend: : DB node id: 0 backend pid: 8470 statement:  message: portal "" does not exist
  LOG:   pid 13499: pool_send_and_wait: Error or notice message from backend: : DB node id: 0 backend pid: 8470 statement: DEALLOCATE pdo_stmt_00000003 message: prepared statement "pdo_stmt_00000003" does not exist
  </code></pre>