When working with PostgreSQL's psql
interactive terminal, you might notice that command outputs (like \d table_name
or query results) get piped through a pager when they exceed your terminal height. This behavior is controlled by the PAGER
environment variable and psql's internal settings.
The simplest way to disable paging completely is to run:
\pset pager off
Or start psql with:
psql --pset=pager=off
To make this change permanent, add to your ~/.psqlrc
file:
\pset pager off
Alternatively, you can control this through environment variables:
export PAGER=
psql
Or more specifically:
export PSQL_PAGER="cat"
psql
The pager functionality was introduced to improve readability of large outputs. When active:
- Outputs longer than your terminal height get paginated
- Press
q
to quit the pager (but this clears output in some terminals) - Navigation follows your configured pager's commands (usually
less
-style)
If you want to keep paging for some commands but not others:
\pset pager on
\o | less
SELECT * FROM large_table;
\o
Or use conditional paging based on output size:
\pset pager always
\pset footer off
For PuTTY users experiencing the disappearing output issue, try:
\pset pager off
\setenv PAGER ''
This ensures output remains visible after quitting commands.
The pager behavior changed significantly between PostgreSQL 8.3 and 9.0. In newer versions (9.0+):
- Pager is enabled by default when output exceeds terminal height
- The
PSQL_PAGER
environment variable takes precedence overPAGER
- Pager behavior can be controlled per-command using
\pset
When working with PostgreSQL's command-line interface psql
, you might notice that output longer than your terminal height gets piped through a pager (similar to less
). This behavior was introduced as a default in PostgreSQL 9.0+.
Several scenarios make pager behavior undesirable:
- Using terminal emulators like PuTTY that already handle scrollback (
Shift+PgUp/PgDn
) - When you want to keep output visible after inspection (pager clears screen when exiting)
- During scripting or automation where paging breaks workflow
Here are three ways to disable the pager:
1. Temporary Disable for Current Session
\pset pager off
2. Permanent Disable via .psqlrc
Add this line to your ~/.psqlrc
file:
\setenv PAGER ''
3. Environment Variable Approach
Set this before launching psql:
export PAGER=
psql -U username -d database
If you want to keep paging but change the behavior:
\setenv PAGER 'less -SXF'
This makes less:
-S
: Chop long lines instead of wrapping-X
: Don't clear screen on exit-F
: Exit immediately if content fits one screen
After making changes, verify with:
\d+ pg_class
This normally produces paged output - it should now display directly in the terminal if pager is properly disabled.
Note that some psql commands like \help
might still use internal paging. For these, you'll need to use:
\pset pager off