Re: Server->Client notification (without polling)?

From: Shane Ambler <pgsql(at)007Marketing(dot)com>
To: Wolfgang Keller <wolfgang(dot)keller(dot)nospam(at)gmx(dot)de>, PostgreSQL Mailing lists <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Server->Client notification (without polling)?
Date: 2006-09-22 05:12:39
Message-ID: C139A6DF.4EA64%pgsql@007Marketing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 21/9/2006 23:19, "Wolfgang Keller" <wolfgang(dot)keller(dot)nospam(at)gmx(dot)de> wrote:

>>> I read the manual again and now I understand that it's the libpq client
>>> library which requires polling a function to retrieve the notifications
>>> received from the server. Is there no way to tell the library "please
>>> call me when a notification arrives"?
>>
>> No, because it's only a library, it doesn't have its own thread of
>> control.
>
> Just to learn something new:
>
> Is this because the library implementor has chosen to do it this way or
> because there is no way to spawn a thread from this library?
>

A library is just a static collection of functions stored in a file.
Although some may be used by the system, a library is not 'running' as a
program would be so can't respond to activity of any sort.

Some of the functions in the pg library would provide the functionality that
a program would use to connect to, monitor and respond to notifications from
the pg server but you would need to write or have someone else write a
program that runs constantly and takes actions when something happens.
This program would be running constantly as PostgreSQL is.

> The reason why I am asking for notification without polling is that I would
> like to use a shared PostgreSQL database for data exchange with other
> applications, and the data exchange is likely to happen very intermittently,
> i.e. the data from other applications it will typically arrive in large
> batches, with long pauses (sometimes hours) in between. But I still want to
> get the data as soon as it is available, to not let the end-users wait for
> minutes.

Maybe you could look at adding this to your PostgreSQL server - start up one
of your python scripts after the data has been added. Not sure how you are
'sharing' your data but you could maybe add in a step after it has been
added to start your script.

The other option is to write a trigger for the table that receives the data,
any time a row is inserted to that table you could have it start up your
python script which could tell everyone that it is there.
I haven't tried this myself but I do believe hearing that pl/perl could run
an external script.

--

Shane Ambler
Postgres(at)007Marketing(dot)com

Get Sheeky @ http://Sheeky.Biz

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message pr0v4 2006-09-22 08:26:12 pass date type data to PQexecparams
Previous Message Wolfgang Keller 2006-09-21 15:10:59 Re: Server->Client notification (without polling)?