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