Re: Who is LISTENing? - Mailing list pgsql-general

From Chris Travers
Subject Re: Who is LISTENing?
Date
Msg-id CAKt_ZftQCqLypXYPPrN-4+vQZM47jKh+3m5rTWgqqbh2VVWxiQ@mail.gmail.com
Whole thread Raw
In response to Re: Who is LISTENing?  (Jasen Betts <jasen@xnet.co.nz>)
List pgsql-general


On Tue, Oct 16, 2012 at 5:18 AM, Jasen Betts <jasen@xnet.co.nz> wrote:
On 2012-10-15, rektide <rektide@voodoowarez.com> wrote:
> Hi pgsql-general,
>
> I'm interested in writing a supervisory process that can insure worker processes are
> running/spawn new ones if not. These workers will mainly be responsible for LISTENing to
> the db, which is emitting triggered_change_notification s.
>
> Is there any means to check a NOTIFY queue to see who or if anyone is LISTEN ing on it?
>

Notifies are not reliable, what I mean is they are "best effort"
this is unlike the other things postgres does, there's no guarantee
that you'll get the message, for example the network might go down at
the same time as the notifiy is emitted, if that happenss a listening
client would miss the notify message and by the time it reconnects the
message is gone.

If you need reliable mesaging use a mesage queue in a table:
Emit a notify when you insert into the queue and the listeners can check
the queue when they connect, and again after each notify.

OTOH, if best effort is good enough,  the table pg_stat_activity will give
you the username of each connected client. perhaps ypu can infer from that
who was probably listening when you last checked...

One of the goals of pg_message_queue was to create a simple message queue system with listen/notify support (which is missing in pgq btw).  It is designed to be reasonably reliable but is still relatively feature poor.  It will probably never be big and professional like pgq, but may be very helpful in many cases nonetheless.   http://pgxn.org/dist/pg_message_queue/

The basic idea is that it automates some of the basic bailing twine you might want to create in such a solution.  Future versions will have more logging, anti-refutation controls, etc.

Note the way we addressed this problem was that listen/notify was optional.  An application could be run from cron once a day and process queued items, or it could connect and wait for notifications.

As of 0.1, it supports payload types of text, xml, and bytea.  More types coming soon in 0.2.

I would be interested in feedback on this, and if anyone wants to contribute, I certainly will be happy to facilitate.

Best Wishes,
Chris Travers

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Strategies/Best Practises Handling Large Tables
Next
From: Matthew Kappel
Date:
Subject: PostgreSQL training recommendations?