Thread: Is libpq thread-safe?

Is libpq thread-safe?

From
Mike Mascari
Date:
Hello. After a search of the mailing list (on dejanews) I
found some articles regarding libpq WRT thread-safeness. The
newest articles regarding its state are quite old (3/8/2000)
but the discussion lead me to believe that all globals were
to be removed for the 7.0 release. I see in the HISTORY
document the following entry:

Make libpq's PQconndefaults() thread-safe (Tom)

Can I assume that libpq as of version 7 is now thread-safe?

Thanks for any info,

Mike Mascari

Re: Is libpq thread-safe?

From
Tom Lane
Date:
Mike Mascari <mascarm@mascari.com> writes:
> Can I assume that libpq as of version 7 is now thread-safe?

The SSL option seems to have a static variable, as do the Kerberos auth
methods (both 4 and 5).  Not sure what the implications are for thread
safeness; you might have to serialize connection opening when using
these options.

PQoidStatus is not thread-safe (as documented, but it's deprecated
anyway).  I also see a completely unnecessary static variable in
PQprint, which I shall get rid of today.

Other than that, I don't see any static variables in libpq.  This is not
really the same thing as thread-safeness; in particular, if you have
multiple threads accessing the same PQconn object, it's up to you to
interlock them.  But you could have multiple threads each using its own
PQconn.  You could also have one thread making the queries (touching
PQconn) and then hand off PQresults to other threads for processing.

            regards, tom lane