Search Postgresql Archives

Re: How about synchronous notifications?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 21, 2010 at 12:23 PM, Lincoln Yeoh <lyeoh@xxxxxxxxxxxxx> wrote:
> To me what would also be useful would be synchronous notifications.
>
> This would allow many programs to wait for events to happen rather than all
> of them polling the database (and wasting CPU cycles, battery life, etc).
> You could still poll with a suitable timeout if you want.
>

Here's how you do it: first, make sure you are not within a
transaction or other Pg activity.  Get the socket's file handle from
the Pg connection handle.  When you're ready to wait for a notify
event, just do a select() system call on that file handle waiting
until there is data to read on that socket.

When you return from the select, just check for the notifications and
you're ready to go.  If you did not find a notification, return to the
select() call.  Of course, this assumes you've issued the necessary
LISTEN command.

This has worked for me (and is tested well) up thru Pg 8.3. I cannot
imagine it would stop working as the wire line protocol doesn't really
change.

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux