Re: Asynchronous query execution

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: John R Pierce <pierce(at)hogranch(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Asynchronous query execution
Date: 2010-12-08 15:32:02
Message-ID: AANLkTikxoVadpC9WGEkBh=U=239mFgE4iGoHHxEQBWt-@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

On Wed, Dec 8, 2010 at 8:40 AM, John R Pierce <pierce(at)hogranch(dot)com> wrote:
> On 12/08/10 5:35 AM, c k wrote:
>>
>> Hello,
>> I would like to know how can we execute the queries asynchronously?
>> If we use and execute plpgsql functions they just completes the execution
>> or throws an error on error. In between next sql statement waits for the
>> previous one to complete the execution. But in few situations it is required
>> not to wait for getting the completion of previous sql statement. How can
>> this e achieved?
>>
>
> one postgresql connection can only run one query at a time.
>
> run your asynchronous queries from a thread with its own connection

This is only asynchronous from client point of view. Meaning, while
the query is running, you can go off and do other work on the client.

There is iron clad rule of one query running per database session at a
time. From pl/pgsql point of view, only method of working around this
is using dblink style tricks to connect to the database from within
function and run queries. dblink supports asynchronous querying so
you can leverage that:

dblink_send_query(text connname, text sql) returns int

From client point of view, you have a number of techniques.
async_queries/threads and multiple connections would be the most
common approaches.

merlin

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Samuel Stearns 2010-12-10 03:17:49 Postgres Crash
Previous Message Robert Gravsjö 2010-12-08 14:01:38 Re: [GENERAL] Asynchronous query execution

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-12-08 16:04:07 Re: Maximum size for char or varchar with limit
Previous Message Adrian Klaver 2010-12-08 15:19:27 Re: Maximum size for char or varchar with limit