Re: Backend freezes at "idle in transaction" while using libpq PQexec (PostgreSQL version 9.1.2)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Prima Chairunnanda <prima(dot)ch(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Backend freezes at "idle in transaction" while using libpq PQexec (PostgreSQL version 9.1.2)
Date: 2012-07-21 16:28:56
Message-ID: 20072.1342888136@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Prima Chairunnanda <prima(dot)ch(at)gmail(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2012-07-21 16:58:20 Re: A very long running query....
Previous Message Ioannis Anagnostopoulos 2012-07-21 09:22:09 Re: A very long running query....