Re: active queries

Поиск
Список
Период
Сортировка
От Gregory Stark
Тема Re: active queries
Дата
Msg-id 87prr6p8yx.fsf@oxford.xeocode.com
обсуждение исходный текст
Ответ на Re: active queries  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Список pgsql-general
"Alban Hertroys" <dalroi@solfertje.student.utwente.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
  EnterpriseDB          http://www.enterprisedb.com
  Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!

В списке pgsql-general по дате отправления:

Предыдущее
От: Gregory Stark
Дата:
Сообщение: Re: Open Source CRM - Options?
Следующее
От: Richard Huxton
Дата:
Сообщение: Revealing the "postgres" user service-account in Windows XP Home