At 07:55 PM 9/22/2010, Vick Khera wrote:
>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.
How'd one get the socket file handle if using JDBC/ODBC? It seems
possible if using perl DBD-Pg, but I haven't tested that to see if
you can really get out of a transaction.
Given these issues I guess it would be easier to use a separate
messaging server (despite that still not being that easy :) ). This
would have the characteristic of not being DB specific, so apps
wouldn't be locked in to postgresql. Whether this is a benefit or not
depends on your POV ;).
Regards,
Link.