Thread

  1. Listen and notify in psql process

    Sakshi Jain <sakshijain10388@gmail.com> — 2021-06-17T11:01:41Z

    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
    
  2. Fwd: Listen and notify in psql process

    Sakshi Jain <sakshijain10388@gmail.com> — 2021-06-17T11:04:27Z

    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
    
  3. Re: Listen and notify in psql process

    Ravi Krishna <srkrishna@yahoo.com> — 2021-06-17T11:45:27Z

    https://www.postgresql.org/docs/current/sql-notify.html
    
    https://www.postgresql.org/docs/13/sql-listen.html
    
    
      
  4. Re: Listen and notify in psql process

    Torsten Förtsch <tfoertsch123@gmail.com> — 2021-06-17T13:34:05Z

    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);
        }
    }
    
    >
    
  5. Re: Listen and notify in psql process

    Erik Brandsberg <erik@heimdalldata.com> — 2021-06-17T14:22:34Z

    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>