Thread: one more question about LISTEN / NOTIFY

one more question about LISTEN / NOTIFY

From
max
Date:
Hello,

I asked about the Listen / Notify commands some weeks ago. I decided to
give it a trial.
But I have one more question about it. What happens to notifications if
the connection from a listener application disconnects unexpected. Does
PostgreSQL store all notifications that are triggered during this period
and submit it to the next listener that (re)connect? Or can I lose
notifications if something unexpected happened with my connection?

Thanks,

Max

PS: the PgNotification utilities from Craig Ringer are a little too much
for my purpose ;)


Re: one more question about LISTEN / NOTIFY

From
Craig Ringer
Date:
On 08/08/10 10:40, max wrote:
> Hello,
>
> I asked about the Listen / Notify commands some weeks ago. I decided to
> give it a trial.
> But I have one more question about it. What happens to notifications if
> the connection from a listener application disconnects unexpected. Does
> PostgreSQL store all notifications that are triggered during this period
> and submit it to the next listener that (re)connect? Or can I lose
> notifications if something unexpected happened with my connection?

You lose notifications during any period you don't have a connection.
Usually you'd be re-reading anything of interest from the database if
you have to reconnect, as any operation on the old connection would've
failed and you'd have to re-try your transaction. You'd be re-populating
any caches, etc.

In my own app, if I lose a connection I re-issue LISTEN s on any keys of
interest, *then* SELECT them to refresh the copies my app has in case
they've changed. If you're using listen/notify as a change notification
system that works great.

If you're trying to use listen/notify as a message queuing mechanism,
you should probably look at dedicated queuing systems. Building your own
queuing system is harder than you'd think, and listen/notify is not
particularly well suited to reliable message queuing.

--
Craig Ringer