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

Re: active queries

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Alban Hertroys" <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
Cc: "Miklosi Attila" <amiklosi(at)freemail(dot)hu>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: active queries
Date: 2008-05-28 18:41:26
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
"Alban Hertroys" <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> writes:

> THE 'active' query (not AN) is the query that's currently being  executed on a
> connection. There can be multiple connections with an  active query each. You
> can't execute multiple queries in parallel on  the same connection. You can
> execute them in sequence of course.
> What people are trying to tell you is that you apparently have  multiple
> threads that perform queries simultaneously on the same  connection, and that's
> not possible.

FWIW it's not just queries that are a problem. You pretty much can't call
*any* libpq function on a connection while another thread is calling any other
libpq call on the same connection. 

It is however safe (assuming you built postgres with the thread-safe option)
to call two libpq calls from different threads on *different* connections. And
it's always safe to call two libpq calls from different threads on the same
connection as long as you ensure that one is finished before the second one
begins. In either case the normal way to guarantee either property is to put a
mutex around either each connection or all of libpq.

You can actually have more than one query simultaneously active in the same
connection using named portals. But if you called PQgetResult() on one you
have to ensure all threads wait until it returns before issuing PQgetResult()
(or any other libpq function) on the other portal.

  Gregory Stark
  Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!

In response to

pgsql-general by date

Next:From: Bob PawleyDate: 2008-05-28 18:50:12
Subject: Re: Bottom Posting
Previous:From: Gregory StarkDate: 2008-05-28 18:32:41
Subject: Re: Open Source CRM - Options?

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