From: Tom Lane <tgl@sss.pgh.pa.us>
To: Goran Thyni <goran@bildbasen.se>
Cc: pgsql-interfaces@postgreSQL.org, PostgreSQL-development <hackers@postgreSQL.org>
Subject: Re: [HACKERS] thread-safe libpq and DBD::Pg
Date: Sat, 08 Aug 1998 14:30:37 -0400
Message-ID: <1623.902601037@sss.pgh.pa.us> (raw)
In-Reply-To: <35CB453A.3646F3B6@bildbasen.se>
Goran Thyni <goran@bildbasen.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: tgl@sss.pgh.pa.us, goran@bildbasen.se, hackers@postgreSQL.org
Subject: Re: [HACKERS] thread-safe libpq and DBD::Pg
In-Reply-To: <1623.902601037@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox