Skip site navigation (1) Skip section navigation (2)

Re: [INTERFACES] libpq + multiple connections ...

From: "E(dot)E(dot) Mellor" <eem21(at)cam(dot)ac(dot)uk>
To: pgsql-interfaces(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, The Hermit Hacker <scrappy(at)hub(dot)org>
Subject: Re: [INTERFACES] libpq + multiple connections ...
Date: 1999-11-29 10:42:49
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
--On 29 November 1999, 02:45 -0500 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> The Hermit Hacker <scrappy(at)hub(dot)org> forwards:
>> Hmm, sorta, I'm a bit troubled, I was trying to add an async connection
>> function to libpq and I stumbled across some problems.
> Someone else was already working on that --- check the archives from
> a few months back.

'twas me.  In fact, it's been ready for ages, but I've had so much on that
I've not had time to write the docs.  I'll do them today for you.

>> It seems that libpq makes use of some static variables, meaning i'm not
>> sure if it's safe to use libpq for multiple database connections.
>> What i'm refering to is:
>> postgresql-6.5.3/src/interfaces/libpq/fe-connect.c
>> line 79 has a structure that seems to be shared amongst the entire
>> library, am I likely to stumble upon more stuff that makes it somewhat
>> dangerous to have more than one active database connection in my program?
> The PQconnectdb() function uses that static array, meaning that you can't
> safely run two PQconnectdb() calls in parallel.  But you can open two
> connections in sequence and then use them in parallel; and you can do
> the opens in parallel if you use one of the older, less-friendly
> connection-opening calls.  There aren't any other non-constant statics
> in libpq AFAIR.

This is correct.  Someone else was looking at thread-safety across the
whole of libpq, but as far as I'm aware, it's not _guaranteed_ to be
thread-safe anywhere.  My changes allow one to use libpq in a single
thread, but with multiple connections and without blocking the thread at

> The static array sucks, I agree, but I don't see any way to get rid of
> it without changing libpq's API for PQconnectdb() and PQconndefaults().
> Do we want to consider doing that (and breaking some apps) for 7.0?

I think it should be possible to arrange it so that these functions still
exist (but are deprecated and marked as non-thread-safe).  I'll leave that
for others to decide though.

Ewan Mellor.

In response to


pgsql-interfaces by date

Next:From: Bill BarnesDate: 1999-11-29 10:59:48
Subject: pgaccess on win95 connection
Previous:From: Michael KatkinDate: 1999-11-29 10:06:27
Subject: unsubscribe

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group