customize pager in psql
Asked Answered
G

2

46

When I use psql, the command line tool of PostgreSQL, in interactive mode, it lists data as paginated output.

However, because I use psql in a terminal application which can handle long outputs itself, I rather would like to get the whole output without the paginating with the annoying --more-- line.

Is there any way to customise the paging behavior in psql? I tried to set LESS in the surrounding shell environment to cat, but this din't help.

Any suggestions?

Goldfish answered 23/1, 2013 at 7:2 Comment(0)
D
58

From the fine psql manual:

\pset option [ value ]
[...]
pager
Controls use of a pager program for query and psql help output. If the environment variable PAGER is set, the output is piped to the specified program. Otherwise a platform-dependent default (such as more) is used.

When the pager option is off, the pager program is not used. When the pager option is on, the pager is used when appropriate

So you can say this from the psql prompt:

psql> \pset pager off

to turn the pager off. If you want this to always apply, you can add \pset pager off to your ~/.psqlrc file.

You can also use \? from the psql prompt to get a quick summary of the special commands at your disposal.

Dinger answered 23/1, 2013 at 7:43 Comment(6)
Thanks for this. I should have found it myself in the help, but because of the pager I never got to the \pset command. ;-)Goldfish
It is so nice to do this... export PAGER="vim -c 'set nomod nolist syntax=sql' -" and then use psql ...!Connelly
For anyone coming here years later: \pset is case-sensitive!!!Proselytism
Just a word to tell that there is apparently no way to force the pager value to on. It's either off or "long output". Which is in some case (long field content, low record count) not working properly >_<Ezarra
@RomualdBrunet Maybe \x auto would help.Dinger
Note: if you're using the postgres user, the change to ~/.psqlrc for it to be permanent will not workWashstand
M
4

For completeness we might mention that for a one-off or to use as a setting in one of your scripts... (and as mentioned by "mu", see the psql --help (manual))

As a command in a script

psql --pset=pager-off -c "<sqlCommand>" <databaseName>

From your commandline

psql --pset=pager=off <databaseName>

This would be in effect for the single command only so it is most useful in a script.

You can use this method in lieu of making temporary changes within the psql utility or permanent settings via the init file (~/.psqlrc).

Mccalla answered 27/6, 2019 at 18:40 Comment(2)
I wonder if the answer given here is for a different version of psql. This did not work for me. The following worked for me: psql -P pager=off <other params>, via https://mcmap.net/q/131015/-postgresql-disable-more-outputSandhurst
There is typo: Use --pset=pager=off instead of psql --pset=pager-offCalyptra

© 2022 - 2024 — McMap. All rights reserved.