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

Re: [HACKERS] Using libpq in a multithreaded environment

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rini Dutta <rinid(at)rocketmail(dot)com>
Cc: pgsql-interfaces(at)postgreSQL(dot)org, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Using libpq in a multithreaded environment
Date: 2000-02-25 18:19:34
Message-ID: 7802.951502774@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-interfaces
Rini Dutta <rinid(at)rocketmail(dot)com> writes:
> I need to use libpq in a multithreaded environment.
> Ideally I would like to open a single connection to
> the database and use that for all threads. 

Not unless you provide some interlock that will prevent multiple threads
from issuing queries at the same time...

> I just discovered that the PGconn returned when a
> connection is opened is usable for only one thread
> since it also seems to store the result (PGresult *)
> and the errorMessage.

This is the least of your worries --- the backend is not multithreaded
either, so it will not accept concurrent queries; nor is the frontend-
to-backend protocol capable of keeping track of concurrent queries.

Unless your intended use of the connection is considerably more
restricted than you have indicated, you will want one connection
per query-issuing thread.

This would not prevent you from handing off completed PGresults to
other threads for processing; but operations on a PGconn should be
either restricted to one thread or protected by a mutex.

			regards, tom lane

In response to

pgsql-hackers by date

Next:From: M. BradyDate: 2000-02-25 18:44:53
Subject: XML and Security
Previous:From: Bruce MomjianDate: 2000-02-25 16:54:40
Subject: Re: [SQL] how to create index on timestamp field in pre v7 database

pgsql-interfaces by date

Next:From: Don OliverDate: 2000-02-25 19:19:46
Subject: Pgaccess - missing file, can't start
Previous:From: Rini DuttaDate: 2000-02-25 16:47:31
Subject: Using libpq in a multithreaded environment

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