<?php
$c = pg_connect( $connectionString, PGSQL_CONNECT_FORCE_NEW );

$queries = array (
        "SELECT COUNT(*) AS data FROM articles",
        "SELECT * FROM posts WHERE visible = TRUE",
        "SELECT * FROM countries WHERE visible = FALSE",
        "SELECT * FROM types WHERE visible = TRUE"
);

foreach ( $queries as $query ) {
        $res = @pg_query( $c, $query );
        if ( empty( $res ) ) {
                echo "[ERR] " . pg_last_error( $c ) . "\n";
        } else {
                echo "[OK]\n";
        }
}

The snippet of code above is generating for the first time this:

[OK]
[OK]
[OK]
[OK]

but for the second time this:

[OK]
[OK]
[ERR] server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
[ERR] server closed the connection unexpectedly
    This probably means the server terminated abnormally
        before or while processing the request.

This means that some cached queries cause a problem. We tried to change the order of quires, but it didn't help. Only simple queries like SELECT 1+8, which are probably not cached always run well.

Similar problem can be simulated using psql and probably any other language driver (not only PHP).

All troubles came up when we installed PostgreSQL Query Cache.

Should the query cache be configured somehow not behave this way?

Our config files are here: http://pastebin.com/g2dBjba0 – pcqd_hba.conf http://pastebin.com/X9Y3zrjx – pcqd.conf

link|improve this question

PostgreSQL or Postgres for short. There is no "Postgre". More here. – Erwin Brandstetter Dec 21 '11 at 22:10
Have you tried using PDO pgsql driver? – Kenaniah Dec 22 '11 at 1:12
As I told, even with the original psql (shell tool for PostgreSQL) it behave the same. It doesn't matter which driver I use. – Radek Simko Dec 22 '11 at 7:59
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.