Обсуждение: Asynchronous query execution

Поиск
Список
Период
Сортировка

Asynchronous query execution

От
c k
Дата:
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?

Waiting for you response.

CPK

Re: Asynchronous query execution

От
John R Pierce
Дата:
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



Re: Asynchronous query execution

От
Robert Gravsjö
Дата:

On 2010-12-08 14.35, 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?

Is this what you're looking for:
http://www.postgresql.org/docs/current/interactive/libpq-async.html

>
> Waiting for you response.
>
> CPK
>

--
Regards,
Robert "roppert" Gravsjö

Re: Asynchronous query execution

От
Merlin Moncure
Дата:
On Wed, Dec 8, 2010 at 8:40 AM, John R Pierce <pierce@hogranch.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

Re: Asynchronous query execution

От
Merlin Moncure
Дата:
On Wed, Dec 8, 2010 at 8:40 AM, John R Pierce <pierce@hogranch.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

Re: Asynchronous query execution

От
c k
Дата:
thanks to all of you.

Regards,
CPK

On 12/8/10, Merlin Moncure <mmoncure@gmail.com> wrote:
> On Wed, Dec 8, 2010 at 8:40 AM, John R Pierce <pierce@hogranch.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
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>