Re: Backend freezes at "idle in transaction" while using libpq PQexec (PostgreSQL version 9.1.2) - Mailing list pgsql-novice

From Tom Lane
Subject Re: Backend freezes at "idle in transaction" while using libpq PQexec (PostgreSQL version 9.1.2)
Date
Msg-id 20072.1342888136@sss.pgh.pa.us
Whole thread Raw
In response to Backend freezes at "idle in transaction" while using libpq PQexec (PostgreSQL version 9.1.2)  (Prima Chairunnanda <prima.ch@gmail.com>)
List pgsql-novice
Prima Chairunnanda <prima.ch@gmail.com> writes:
> I have a problem with using libpq to execute query. I am using it in a
> program which coordinates multiple queries, so the program will open
> several PGconn connections. However, intermittently, some sessions just
> appear to "freeze", and the back-end status is "idle in transaction
> (aborted)".

> Upon closer inspection with gdb, I found that both the front-end and
> back-end are waiting to receive message!

I would say the odds are at least ten-to-one that this is the
consequence of different threads trying to manipulate the same PGconn
object concurrently.  libpq itself is not multi-threaded and does not
provide any protection against such mistakes.  In a multi-threaded
environment it's frequently a good idea to wrap a PGconn in a larger
object that includes a mutex, so that you can prevent this type of
problem via locking.

            regards, tom lane

pgsql-novice by date:

Previous
From: Prima Chairunnanda
Date:
Subject: Backend freezes at "idle in transaction" while using libpq PQexec (PostgreSQL version 9.1.2)
Next
From: David Raznick
Date:
Subject: copy a text type.