Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
NOTIFY/LISTEN in Postgresql
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
"P. Broennimann"  
View profile  
 More options Oct 15 2012, 8:54 am
Newsgroups: pgsql.general
From: peter.broennim...@gmail.com ("P. Broennimann")
Date: Mon, 15 Oct 2012 14:54:05 +0200
Local: Mon, Oct 15 2012 8:54 am
Subject: NOTIFY/LISTEN in Postgresql

Hi there

1) Can a Pg/SQL function "listen" for a notification sent from an external
instance?
I would like my stored function to pause/wait and continue its execution
once an external event (NOTIFY event) occurs.

2) In Pg/SQL I can implement a loop (until something happens) to
pause/wait. This costs CPU time -> Is there another solution? Actually I
would need something like a trigger to give my stored function the signal
to continue.

Thx & cheers,
Peter


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Ringer  
View profile  
 More options Oct 15 2012, 9:26 am
Newsgroups: pgsql.general
From: ring...@ringerc.id.au (Craig Ringer)
Date: Mon, 15 Oct 2012 21:26:12 +0800
Local: Mon, Oct 15 2012 9:26 am
Subject: Re: NOTIFY/LISTEN in Postgresql
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#A...

> 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

--
Sent via pgsql-general mailing list (pgsql-gene...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
"P. Broennimann"  
View profile  
 More options Oct 15 2012, 9:44 am
Newsgroups: pgsql.general
From: peter.broennim...@gmail.com ("P. Broennimann")
Date: Mon, 15 Oct 2012 15:44:16 +0200
Local: Mon, Oct 15 2012 9:44 am
Subject: Re: NOTIFY/LISTEN in Postgresql

Thx for the feedback I will take a look.

Here some details. Basically what I'd like to achieve:

  Internet <-> AppliA <-> PostgreSQL <-> AppliB

1) AppliA receives a request from the internet and calls a Pg/SQL function.
2) The Pg/SQL function informs AppliB that there is some work waiting
(NOTIFY).
3) AppliB does the work and posts the result back to PostgreSQL.

... and now here's the problem -> The initial Pg/SQL function should give
back the result computed by AppliB -> It has to wait somehow and get
informed when the work from AppliB is done.

Thx & cheers,
Peter

2012/10/15 Craig Ringer <ring...@ringerc.id.au>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Travers  
View profile  
 More options Oct 15 2012, 9:49 am
Newsgroups: pgsql.general
From: chris.trav...@gmail.com (Chris Travers)
Date: Mon, 15 Oct 2012 06:49:43 -0700
Local: Mon, Oct 15 2012 9:49 am
Subject: Re: NOTIFY/LISTEN in Postgresql

On Mon, Oct 15, 2012 at 6:44 AM, P. Broennimann <peter.broennim...@gmail.com

two options:

1) advisory locks as Craig suggested.  Beware of the fact that this will
result in delays however.

2) Return an interrim result to AppliA and the notify AppliA that the new
results are waiting using Listen/Notify (or maybe even pg_message_queue
with an xml payload).

Best wishes,
Chris Travers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Merlin Moncure  
View profile  
 More options Oct 15 2012, 10:41 am
Newsgroups: pgsql.general
From: mmonc...@gmail.com (Merlin Moncure)
Date: Mon, 15 Oct 2012 09:41:07 -0500
Local: Mon, Oct 15 2012 10:41 am
Subject: Re: NOTIFY/LISTEN in Postgresql
On Mon, Oct 15, 2012 at 8:44 AM, P. Broennimann

<peter.broennim...@gmail.com> wrote:
> Thx for the feedback I will take a look.

> Here some details. Basically what I'd like to achieve:

>   Internet <-> AppliA <-> PostgreSQL <-> AppliB

> 1) AppliA receives a request from the internet and calls a Pg/SQL function.
> 2) The Pg/SQL function informs AppliB that there is some work waiting
> (NOTIFY).
> 3) AppliB does the work and posts the result back to PostgreSQL.

> ... and now here's the problem -> The initial Pg/SQL function should give
> back the result computed by AppliB -> It has to wait somehow and get
> informed when the work from AppliB is done.

I have done this exact workload many times and it's 100% doable.  It
relies on dblink and read committed hacks but it's very robust.

In step step 2, you write out a record that is going to hold the
response from AppliB.  It can be a simple text field or whatever you
need.  Then you spawn a dblink call and issue the notify (it has to be
dblink, because notifications are not delivered till end of
transaction.  After you spawn, you start sleep looping, waiting for
AppliB to set the response field.  You can see it because AppliB is
writing it in a different transaction, and in ReadCommitted mode you
are allowed to see other transactions that complete.  Once the
response is set (make sure you have a timeout), you can return the
reponse or optionally grab more data.

merlin

--
Sent via pgsql-general mailing list (pgsql-gene...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »