agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
Listen and notify in psql process
5+ messages / 4 participants
[nested] [flat]

* Listen and notify in psql process
@ 2021-06-17 11:01 Sakshi Jain <sakshijain10388@gmail.com>
  2021-06-17 11:04 ` Fwd: Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
  2021-06-17 14:22 ` Re: Listen and notify in psql process Erik Brandsberg <erik@heimdalldata.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Sakshi Jain @ 2021-06-17 11:01 UTC (permalink / raw)
  To: pgsql-sql@lists.postgresql.org

Hi Team,

How to listen from within a psql process and get the payloads?

Do Postgres have any such a mechanism where in a session a process send a
"listen <name>" sql command and then gets a message if someone in the other
session issued a "notify <name>".

Please provide an example of how to do this.

-- 
*Thanks & Regards*
Sakshi Jain
New Delhi
8882433263

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Fwd: Listen and notify in psql process
  2021-06-17 11:01 Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
@ 2021-06-17 11:04 ` Sakshi Jain <sakshijain10388@gmail.com>
  2021-06-17 11:45   ` Re: Listen and notify in psql process Ravi Krishna <srkrishna@yahoo.com>
  2021-06-17 13:34   ` Re: Listen and notify in psql process Torsten Förtsch <tfoertsch123@gmail.com>
  1 sibling, 2 replies; 5+ messages in thread

From: Sakshi Jain @ 2021-06-17 11:04 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi Team,

How to listen from within a psql process and get the payloads?

Do Postgresql have any such a mechanism where in a session a process send a
"listen <name>" sql command and then gets a message if someone in the other
session issued a "notify <name>".

Please provide an example of how to do this.

I am looking for listen to return some thing when a notify has been issued.

-- 
*Thanks & Regards*
Sakshi Jain
New Delhi
8882433263



-- 
*Thanks & Regards*
Sakshi Jain
New Delhi
8882433263

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Listen and notify in psql process
  2021-06-17 11:01 Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
  2021-06-17 11:04 ` Fwd: Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
@ 2021-06-17 11:45   ` Ravi Krishna <srkrishna@yahoo.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Ravi Krishna @ 2021-06-17 11:45 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; Sakshi Jain <sakshijain10388@gmail.com>

https://www.postgresql.org/docs/current/sql-notify.html

https://www.postgresql.org/docs/13/sql-listen.html


  

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Listen and notify in psql process
  2021-06-17 11:01 Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
  2021-06-17 11:04 ` Fwd: Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
@ 2021-06-17 13:34   ` Torsten Förtsch <tfoertsch123@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Torsten Förtsch @ 2021-06-17 13:34 UTC (permalink / raw)
  To: Sakshi Jain <sakshijain10388@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On Thu, Jun 17, 2021 at 1:04 PM Sakshi Jain <sakshijain10388@gmail.com>
wrote:

How to listen from within a psql process and get the payloads?
>
> Do Postgresql have any such a mechanism where in a session a process send
> a "listen <name>" sql command and then gets a message if someone in the
> other session issued a "notify <name>".
>
> Please provide an example of how to do this.
>
> I am looking for listen to return some thing when a notify has been issued.
>

Here is an example in perl. Basically you issue the LISTEN command. Then
you sit and watch the file descriptor to become ready. You do that outside
of a transaction. Once the descriptor is ready you call your driver's
version of notification read function until it comes back empty. That is
when you go back and wait for the next arrival.

$dbh->do("LISTEN channel");
my $sel = IO::Select->new;
$sel->add($dbh->{pg_socket});
while ($sel->can_read) {
    while (my $notify = $dbh->pg_notifies) {
        my ($name, $pid, $payload) = @$notify;
        do_something($payload);
    }
}

>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Listen and notify in psql process
  2021-06-17 11:01 Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
@ 2021-06-17 14:22 ` Erik Brandsberg <erik@heimdalldata.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Erik Brandsberg @ 2021-06-17 14:22 UTC (permalink / raw)
  To: Sakshi Jain <sakshijain10388@gmail.com>; +Cc: pgsql-sql@lists.postgresql.org

Google for Postgres listen notify... ;)  It is in the documentation.

On Thu, Jun 17, 2021 at 7:02 AM Sakshi Jain <sakshijain10388@gmail.com>
wrote:

> Hi Team,
>
> How to listen from within a psql process and get the payloads?
>
> Do Postgres have any such a mechanism where in a session a process send a
> "listen <name>" sql command and then gets a message if someone in the other
> session issued a "notify <name>".
>
> Please provide an example of how to do this.
>
> --
> *Thanks & Regards*
> Sakshi Jain
> New Delhi
> 8882433263
>
>


-- 
*Erik Brandsberg*
erik@heimdalldata.com

www.heimdalldata.com
+1 (866) 433-2824 x 700
[image: AWS Competency Program]
<https://aws.amazon.com/partners/find/partnerdetails/?n=Heimdall%20Data&id=001E000001d9pndIAA;

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2021-06-17 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 11:01 Listen and notify in psql process Sakshi Jain <sakshijain10388@gmail.com>
2021-06-17 11:04 ` Sakshi Jain <sakshijain10388@gmail.com>
2021-06-17 11:45   ` Ravi Krishna <srkrishna@yahoo.com>
2021-06-17 13:34   ` Torsten Förtsch <tfoertsch123@gmail.com>
2021-06-17 14:22 ` Erik Brandsberg <erik@heimdalldata.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox