Sudden semi-deterministic disconnection between queries - Mailing list pgsql-general

From Peter Schuller
Subject Sudden semi-deterministic disconnection between queries
Date
Msg-id 200403100834.51880.peter.schuller@infidyne.com
Whole thread Raw
Responses Re: Sudden semi-deterministic disconnection between queries
Re: Sudden semi-deterministic disconnection between queries
List pgsql-general
Hello,

I have a difficult-to-debug problem. I will try to keep this as brief as
possible without leaving things out. In a certain situation my application
fails with:

   org.postgresql.util.PSQLException: Connection is closed.  Operation is not
permitted.

After some debugging I realized that this would happen on the first query,
regardless of what it is, *after* a specific previous query. In other words:

   query1
   query2
   ...
   queryN     <- seems to cause the failure
   queryN+1 <- failure

queryN *seemingly* completes successfully without any error messsage, but then
I get the above error when executing queryN+1.

By commenting out N+1 in my code I would get the error on the next query
instead. By not running N at all, there are no errors.

queryN is simple:

   INSERT
      INTO email (from_header, to_header, subject_header, body)
      VALUES (?, ?, ?, ?)

Note that the error *always* appears on the query executed immediately after
the above query - *however* it does not happen on all queries. At first I saw
this happening every now and then but I now have a reproducable situation
where I do something which triggers 10 E-Mails to be inserted into the
database. Exactly after which message it fails seems to vary - so far I've
seen it fail on the third and sevenths iteration.

The first thing I did was to upgrade the JDBC driver to the latest stable
version for 7.4 on jdbc.postgresql.org. Then I upgraded PostgreSQL from 7.3.4
to the latest 7.4 release (with a dump/reload of the database).

Unfortunately the code depends on a lot of other things and all database
access is going through a middle layer I wrote, so I can't produce a simple
few-line example which demonstrates the problem.

* All queries are running in a transaction with SERIALIZABLE isolation level.
* All queries are definitely executed on the same connection - I have verified
this in case there was some bug in my middle layer that would cause
it to suddently switch to another (perhaps stale) connection.

Does anyone have any suggestions at all of what might cause this, or how I
might debug further? Can I make postgresql do extremely verbose logging
somehow? For example, if the postmaster is intentionally closing the
connection it would be interesting to know why.

Someone on IRC suggested the server might be segfaulting, but I don't know of
a good way to check for this.

Thanks!

--
/ Peter Schuller, InfiDyne Technologies HB

PGP userID: 0xE9758B7D or 'Peter Schuller <peter.schuller@infidyne.com>'
Key retrieval: Send an E-Mail to getpgpkey@scode.org
E-Mail: peter.schuller@infidyne.com Web: http://www.scode.org


pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: C locale
Next
From: Frank van Vugt
Date:
Subject: Re: does this look more like a possible bug or more like a possible hardware problem...? (long)