Re: LISTEN considered dangerous

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Gregory Stark <gsstark(at)mit(dot)edu>
Cc: harding(dot)ian(at)gmail(dot)com, Flemming Frandsen <ff(at)partyticket(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: LISTEN considered dangerous
Date: 2006-08-02 05:45:28
Message-ID: 20060802054528.GA29699@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Aug 01, 2006 at 07:50:19PM -0400, Gregory Stark wrote:
> > > However that just doesn't work, because listen is broken, allow me to
> > > illustrate, here A and B are two clients:
> > >
> > > A: BEGIN
> > > A: SELECT * FROM foo and cache the result.
> > > A: LISTEN foochange
> > > B: BEGIN
> > > B: update foo
> > > B: NOTIFY foochange
> > > B: COMMIT
> > > A: COMMIT

> I haven't used LISTEN/NOTIFY myself yet and I do indeed find the behaviour he
> shows somewhat surprising. Normally in read-committed mode uncommitted
> transactions are affected by other transactions when they commit. In this case
> the uncommitted LISTEN is not being affected by the committed NOTIFY.

Eh? At the point the LISTEN is run, the NOTIFY hasn't committed, so a
row is inserted. At the time the NOTIFY is committed, the LISTEN hasn't
committed yet so won't be visible. Only LISTEN is stored, not NOTIFY so
there's nothing wrong with the read-committed semantics.

It's slightly surprising though. I havn't seen anyone else complain
about this before though. The only way to fix this is to make the
LISTEN completely atransactional, so NOTIFY can see uncomitted LISTENs
also.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Flemming Frandsen 2006-08-02 05:57:55 Re: LISTEN considered dangerous
Previous Message Joshua D. Drake 2006-08-02 05:05:11 Re: Best Procedural Language?