1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Add PSQL_WATCH_PAGER for psql's \watch command.

Allow a pager to be used by the \watch command.  This works but isn't
very useful with traditional pagers like "less", so use a different
environment variable.  The popular open source tool "pspg" (also by
Pavel) knows how to display the output if you set PSQL_WATCH_PAGER="pspg
--stream".

To make \watch react quickly when the user quits the pager or presses
^C, and also to increase the accuracy of its timing and decrease the
rate of useless context switches, change the main loop of the \watch
command to use sigwait() rather than a sleeping/polling loop, on Unix.

Supported on Unix only for now (like pspg).

Author: Pavel Stehule <pavel.stehule@gmail.com>
Author: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/CAFj8pRBfzUUPz-3gN5oAzto9SDuRSq-TQPfXU_P6h0L7hO%2BEhg%40mail.gmail.com
This commit is contained in:
Thomas Munro
2021-07-13 11:13:48 +12:00
parent f014b1b9bb
commit 7c09d2797e
6 changed files with 184 additions and 15 deletions

View File

@ -3002,6 +3002,16 @@ lo_import 152801
(such as <filename>more</filename>) is used.
</para>
<para>
When using the <literal>\watch</literal> command to execute a query
repeatedly, the environment variable <envar>PSQL_WATCH_PAGER</envar>
is used to find the pager program instead, on Unix systems. This is
configured separately because it may confuse traditional pagers, but
can be used to send output to tools that understand
<application>psql</application>'s output format (such as
<filename>pspg --stream</filename>).
</para>
<para>
When the <literal>pager</literal> option is <literal>off</literal>, the pager
program is not used. When the <literal>pager</literal> option is
@ -4672,6 +4682,24 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
</listitem>
</varlistentry>
<varlistentry>
<term><envar>PSQL_WATCH_PAGER</envar></term>
<listitem>
<para>
When a query is executed repeatedly with the <command>\watch</command>
command, a pager is not used by default. This behavior can be changed
by setting <envar>PSQL_WATCH_PAGER</envar> to a pager command, on Unix
systems. The <literal>pspg</literal> pager (not part of
<productname>PostgreSQL</productname> but available in many open source
software distributions) can display the output of
<command>\watch</command> if started with the option
<literal>--stream</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><envar>PSQLRC</envar></term>