Re: NOTIFY/LISTEN in Postgresql

From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: "P(dot) Broennimann" <peter(dot)broennimann(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: NOTIFY/LISTEN in Postgresql
Date: 2012-10-15 13:26:12
Message-ID: 507C0EF4.1020001@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/15/2012 08:54 PM, P. Broennimann wrote:
> Hi there
>
> 1) Can a Pg/SQL function "listen" for a notification sent from an
> external instance?

No, it's the other way around. A client can `LISTEN` for a `NOTIFY` sent
by another client, either directly or via a PL/PgSQL function.

What you want is a NOTIFY callback or NOTIFY trigger, something that
invokes a function without any client action when a NOTIFY comes in. No
such feature exists.

> I would like my stored function to pause/wait and continue its execution
> once an external event (NOTIFY event) occurs.

Use an advisory lock, they're ideal for that job:

http://www.postgresql.org/docs/current/static/explicit-locking.html#ADVISORY-LOCKS

> 2) In Pg/SQL I can implement a loop (until something happens) to
> pause/wait. This costs CPU time -> Is there another solution?

Depends on what you're waiting for. Details?

Again, an advisory lock may be a candidate.

--
Craig Ringer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message P. Broennimann 2012-10-15 13:44:16 Re: NOTIFY/LISTEN in Postgresql
Previous Message P. Broennimann 2012-10-15 12:54:05 NOTIFY/LISTEN in Postgresql