Re: Create Action for psql when NOTIFY Recieved

From: Jerry Regan <jerry(dot)regan(at)concertoglobalresources(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "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:24:50
Message-ID: A7E46060-A03E-4576-A1DC-05454E875ED1@concertoglobalresources.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom,

I understand all you’ve said. I was hoping for a different answer. C’est la vie.

I think I could justify the effort to ‘script’ psql. I’m not so sure I can justify the effort to write a standalone program.

At least I have an answer.

Thanks!

/s/jr
Consultant
Concerto GR
Mobile: 612.208.6601

Concerto - a composition for orchestra and a soloist

> On 28Aug, 2017, at 6:08 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
>> On Mon, Aug 28, 2017 at 1:28 PM, Jerry Regan <
>> 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.
>
> Yes, and psql is not designed to do anything of its own accord,
> so I think the answer is really "use another program".
>
>> ​"​Whenever a command is executed, psql also polls for asynchronous
>> notification events generated by LISTEN and NOTIFY."
>
> Exactly. If you don't feed it a command, it just sits there.
>
>> I suspect the feature request would be something like:
>> \set NOTIFY_PROGRAM './process-notify-request.bash' (or an equivalent
>> meta-command)
>> And psql would invoke said program and pass the content of the notification
>> payload to it via stdin.
>
> Such a program could only execute after the next time you give a command
> to psql. You could maybe imagine feeding it a continuous stream of dummy
> commands, but that's pretty silly (and rather defeats the point of LISTEN,
> which is to *not* eat cycles while waiting).
>
> This isn't something that could be easily fixed, AFAICS. Even if we
> wanted to make psql pay attention to asynchronous data arrival, how
> would we get control back from libreadline? And what would happen
> if the user had typed a partial line of input?
>
> You really are much better off creating a program that opens its own
> connection to the DB and sits there listening. psql cannot help you
> meaningfully with this request, and I can't see a way to make it do
> so that wouldn't be a monstrous kluge.
>
> regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jerry Regan 2017-08-29 01:42:21 Re: Create Action for psql when NOTIFY Recieved
Previous Message Jerry Regan 2017-08-29 01:21:02 Re: Create Action for psql when NOTIFY Recieved