Re: Create Action for psql when NOTIFY Recieved

From: Jerry Regan <jerry(dot)regan(at)concertoglobalresources(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Create Action for psql when NOTIFY Recieved
Date: 2017-08-29 01:21:02
Message-ID: 149FA721-C505-4883-B0EB-A9FB5ECD02C3@concertoglobalresources.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David,

Thanks for your response!

/s/jr
Consultant
Concerto GR
Mobile: 612.208.6601

Concerto - a composition for orchestra and a soloist

> On 28Aug, 2017, at 5:36 PM, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> On Mon, Aug 28, 2017 at 1:28 PM, Jerry Regan <jerry(dot)regan(at)concertoglobalresources(dot)com <mailto:jerry(dot)regan(at)concertoglobalresources(dot)com>> wrote:
> My concern is how, after LISTENing in psql, I can tell it what to do when the NOTItFY is received.
>
> ​As far as I am aware you cannot. The docs for psql, and its feature set, with respect to LISTEN, are minimal and basically say psql will print out notifications to stdout (this I'm forced to assume or read the code) and will poll for notifications whenever it sends a query to the server.

I’ve tested using LISTEN and NOTIFY in psql. First I issued the LISTEN, then when my prompt came back, issued the NOTIFY from psql. This is an example from the psql docs, I believe. In any case, that the NOTIFY had occurred was reported in the psql window.
>
> https://www.postgresql.org/docs/current/static/app-psql.html <https://www.postgresql.org/docs/current/static/app-psql.html>
>
> ​"​Whenever a command is executed, psql also polls for asynchronous notification events generated by LISTEN and NOTIFY."
>
> I suspect the feature request would be something like:
>
> \set NOTIFY_PROGRAM './process-notify-request.bash' (or an equivalent meta-command)
Since the database would issue the NOTIFY, not sure \set would be used, but otherwise, yes. Or, I may just send information about the inserted row. It depends on what psql would need.
>
> And psql would invoke said program and pass the content of the notification payload to it via stdin.

I’d rather have psql know the program name to invoke, but since I don’t really know how all this works, I may have no choice.
>
> Given what we allow for "\copy" I don't see any technical or conceptual problems with such a feature. Just needs someone to be its primary author.
>
> David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jerry Regan 2017-08-29 01:24:50 Re: Create Action for psql when NOTIFY Recieved
Previous Message Tom Lane 2017-08-28 23:08:28 Re: Create Action for psql when NOTIFY Recieved