Re: [HACKERS] thread-safe libpq and DBD::Pg

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Goran Thyni <goran(at)bildbasen(dot)se>
Cc: pgsql-interfaces(at)postgreSQL(dot)org, PostgreSQL-development <hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] thread-safe libpq and DBD::Pg
Date: 1998-08-08 18:30:37
Message-ID: 1623.902601037@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-interfaces

Goran Thyni <goran(at)bildbasen(dot)se> writes:
> Has anyone any experience of the thread-safeness of libpq?

PQconnectdb() is not thread-safe, because it scribbles temporary
data in the static PQconninfoOptions array. You can get around
that easily enough by not using PQconnectdb (or PQconndefaults)
--- use PQsetdbLogin() instead. In any case the problem exists
only if different threads try to open database connections
at the same time.

As far as I can think at the moment, ordinary operations while
the database connection is open should be thread safe. That's
assuming that your libc (esp. malloc/free) is thread safe of course.
It also assumes that only one thread is using any one PGconn
object (at a time, anyway). Multiple threads using the same
PGconn to issue concurrent requests definitely will not work.

There is also some thread risk during connection shutdown because
libpq momentarily commandeers the SIGPIPE handler. I am thinking
it'd be nice to get rid of that code if possible --- see discussion
from a couple weeks ago on the hackers (or was it interfaces?) list.

I had thought a little bit about ripping out PQconnectdb's use of
changeable fields in PQconninfoOptions, but it looks like this
could break applications that access PQconninfoOptions.
Does anyone have any feelings about that, pro or con?

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1998-08-08 18:41:00 Re: [HACKERS] Re: type coersion (was OR clause status)
Previous Message The Hermit Hacker 1998-08-08 18:17:45 Re: [HACKERS] re: Informix on Linux

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 1998-08-09 00:35:55 libpq cleanup for SIGPIPE and stderr concerns
Previous Message Ulrich Voss 1998-08-07 19:58:47 Re: [INTERFACES] DBF2PG