Re: Create Action for psql when NOTIFY Recieved

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Jerry Regan" <jerry(dot)regan(at)concertoglobalresources(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>,"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 15:21:01
Message-ID: 8b517878-9397-4d4f-bce4-381c928804f0@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jerry Regan wrote:

> 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.

As a hack around psql, you could have a script that feeds psql
with "SELECT 1" from time to time and capture only the
notifications output:

(echo "listen foo;"; while true; do echo "select 1;"; sleep 1; done) | \
psql | grep notification

When another session issues NOTIFY foo, 'bar'
that output filtered by the above command is, for example:

Asynchronous notification "foo" with payload "bar" received from
server process with PID 20033.

which just needs to be piped into another step that runs your custom
action.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John McKown 2017-08-29 15:30:45 Re: Create Action for psql when NOTIFY Recieved
Previous Message Andres Freund 2017-08-29 14:09:41 Re: Unlogged Crash Detection