Re: proposal - psql - use pager for \watch command

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal - psql - use pager for \watch command
Date: 2021-03-03 18:16:47
Message-ID: CAFj8pRD0Ypmw2nH2Q0j0ZAUiMLWreDCNDm0wgNf13+GcOrO4eg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

út 16. 2. 2021 v 2:49 odesílatel Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
napsal:

> On Fri, Jan 8, 2021 at 10:36 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> > ne 19. 4. 2020 v 19:27 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
> >> last week I finished pspg 3.0 https://github.com/okbob/pspg . pspg now
> supports pipes, named pipes very well. Today the pspg can be used as pager
> for output of \watch command. Sure, psql needs attached patch.
> >>
> >> I propose new psql environment variable PSQL_WATCH_PAGER. When this
> variable is not empty, then \watch command starts specified pager, and
> redirect output to related pipe. When pipe is closed - by pager, then
> \watch cycle is leaved.
> >>
> >> If you want to test proposed feature, you need a pspg with
> cb4114f98318344d162a84b895a3b7f8badec241 commit.
> >>
> >> Then you can set your env
> >>
> >> export PSQL_WATCH_PAGER="pspg --stream"
> >> psql
> >>
> >> SELECT * FROM pg_stat_database;
> >> \watch 1
> >>
> >> Comments, notes?
>
> I tried this out with pspg 4.1 from my package manager. It seems
> really useful, especially for demos. I like it!
>
> * Set up rendering options, in particular, disable the pager,
> because
> * nobody wants to be prompted while watching the output of
> 'watch'.
> */
> - myopt.topt.pager = 0;
> + if (!pagerpipe)
> + myopt.topt.pager = 0;
>
> Obsolete comment.
>

fixed

> +static bool sigpipe_received = false;
>
> This should be "static volatile sig_atomic_t", and I suppose our
> convention name for that variable would be got_SIGPIPE. Would it be
> possible to ignore SIGPIPE instead, and then rely on another way of
> knowing that the pager has quit? But... hmm:
>
> - long s = Min(i, 1000L);
> + long s = Min(i, pagerpipe ? 100L :
> 1000L);
>
> I haven't studied this (preexisting) polling loop, but I don't like
> it. I understand that it's there because on some systems, pg_usleep()
> won't wake up for SIGINT (^C), but now it's being used for a secondary
> purpose, that I haven't fully understood. After I quit pspg (by
> pressing q) while running \watch 10, I have to wait until the end of a
> 10 second cycle before it tries to write to the pipe again, unless I
> also press ^C. I feel like it has to be possible to achieve "precise"
> behaviour somehow when you quit; maybe something like waiting for
> readiness on the pager's stderr, or something like that -- I haven't
> thought hard about this and I admit that I have no idea how this works
> on Windows.
>
>
I rewrote this mechanism (it was broken, because the timing of SIGPIPE is
different, then I expected). An implementation can be significantly simpler
- just detect with waitpid any closed child and react. You proposed it.

Sometimes I see a message like this after I quit pspg:
>
> postgres=# \watch 10
> input stream was closed
>

I don't see this message. But I use fresh 4.3 pspg

please, see attached patch

Regards

Pavel

Attachment Content-Type Size
PSQL_WATCH_PAGER-20200303.patch text/x-patch 7.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-03-03 18:54:18 Re: Libpq support to connect to standby server as priority
Previous Message Jacob Champion 2021-03-03 18:05:17 Re: Table AM modifications to accept column projection lists