Re: libpq thread safety

From: Mark Morgan Lloyd <markMLl(dot)pgsql-general(at)telemetry(dot)co(dot)uk>
To: pgsql-general(at)PostgreSQL(dot)org
Subject: Re: libpq thread safety
Date: 2012-12-27 20:19:46
Message-ID: kbiah3$phu$1@pye-srv-01.telemetry.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Mark Morgan Lloyd <markMLl(dot)pgsql-general(at)telemetry(dot)co(dot)uk> writes:
>> Do any special precautions need to be taken when PQNotifies is being
>> called, to make sure that nothing else is referencing the handle?
>
> It's pretty much the same as any other operation on a PGconn: if there
> could be more than one thread touching the connection object
> concurrently, you'd be well advised to add some application-level
> locking.
>
> http://www.postgresql.org/docs/9.2/static/libpq-threading.html
>
> The lack of any such locking inside libpq is partly historical, and
> partly because in many practical situations you'll need application-side
> locks anyway to protect application data structures associated with the
> connection.

Thanks, Tom. I'm fairly happy with the ways I've used it so far, but I'm
just trying to think ahead for the future.

In the case of Delphi/Lazarus, where you can have multiple queries on
top of the same connection object, my experience so far is that using
the connection object's handle is safe. But I think that to be
absolutely confident of that I need to do some tracing, and find out
under what circumstance calls are being issued directly against that
handle rather than it just being a placeholder for authentication etc.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alejandro Carrillo 2012-12-27 21:17:29 pg_dirtyread doesnt work
Previous Message Scott Ribe 2012-12-27 20:10:19 Re: progress of long running operation