86

We switched from PostgreSQL 8.3 to 9.0. Perhaps it's a new feature or perhaps just a configuration change, but now when output from commands (like, \d tablename) exceeds visible vertical space, psql seem to pipe the output through something similar to less. I could not find a way to turn this behaviour off. Any advice? Thanks.

P.S. I'm scrolling the buffer using PuTTY's Shift+PgUp/PgDn so I don't need psql's paging. Plus, when I press q in the psql's paging, its output disappears from the screen entirely (just like after running less in bash), which is wrong from the general use-cases point of view.

Yuri Ushakov
  • 983
  • 2
  • 7
  • 9
  • 1
    If you're here from Google just trying to scroll through the pager, it's `Space` -- not n or PgDn or down arrow like I tried. – Noumenon Dec 29 '16 at 15:51

6 Answers6

86

TL;DR:

\pset pager 0

From the \pset section of the psql manual:

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, i.e., when the output is to a terminal and will not fit on the screen. The pager option can also be set to always, which causes the pager to be used for all terminal output regardless of whether it fits on the screen. \pset pager without a value toggles pager use on and off.

Alex R
  • 972
  • 3
  • 12
  • 26
Sven
  • 97,248
  • 13
  • 177
  • 225
  • 12
    Thank you. The complete solution looks like: `psql -P pager`. – Yuri Ushakov Feb 14 '11 at 09:50
  • 3
    I guess you can even put an option in your ~/.psqlrc file to avoid having to enter this every time. – Sven Feb 14 '11 at 09:52
  • Anyway to pass arguments to less? – snapfractalpop Nov 07 '12 at 21:17
  • @snapfractalpop: Please post this as a new question. – Sven Nov 07 '12 at 21:32
  • 3
    I also ran into Yuri's problem. As described above. You can use `\pset pager` in psql to toggle whether the output goes to the pager. However, you should be able to use a pager and not have the output disappear from the screen when you quit. The answer is to use 'more' instead of 'less' as the pager. You can either do that by setting the PAGER environment variable in your shell or by adding a PAGER environment variable to a ~/.psqlrc file. – Michael Rush Apr 04 '14 at 16:29
  • 5
    @MichaelRush: Set `PAGER` to `less -X` and it won't clear the screen. – Sven Apr 04 '14 at 16:40
  • 1
    For others, here's what the -X (or --no-init) option to less does: Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen. – Michael Rush Apr 25 '14 at 00:53
26

Try switcher:

database_name=# \pset pager
Pager is used for long output.
database_name=# \pset pager
Pager usage is off.
masegaloeh
  • 17,978
  • 9
  • 56
  • 104
Lebnik
  • 369
  • 3
  • 2
24

To turn off the pager when using psql in the shell :

psql -P pager=off ...

You could also export an empty PAGER environment variable, so you don't need to add the option to every statement. It will stay set until you close your current shell.

export PAGER=
psql ...

Finally, a workaround that may be easier to remember: pipe the output through cat, which will disable the default pager

psql ... | cat
mivk
  • 3,457
  • 1
  • 34
  • 29
10

Switch the pager off with

\pset pager off
David Jones
  • 201
  • 2
  • 5
10

add below code in ~/.psqlrc to retain the behaviour

\pset pager off

Vivin Veerali
  • 201
  • 2
  • 2
2

Best way in summary is to set an environment variable for the pager, e.g.

PAGER='less -X' psql

or to set it once

export PAGER='less -X'

then run

psql

Brad Parks
  • 674
  • 13
  • 19
  • 1
    From the man page: `-X` or `--no-init` - "Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen." – Daniel Stevens Aug 31 '20 at 03:33