HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Avoid output disappearing in psql

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
psqldisappearingoutputavoid

Problem

I open psql and write:

mydb=> \dt


and this list of tables is shown:

List of relations
 Schema |            Name            | Type  |  Owner  
--------+----------------------------+-------+---------
 public | auth_group                 | table | foouser
 ...


The I have to press Esc to return to the prompt, and the output disappears like it was a less session.

I want to keep the output around so that I can use the information in it to write queries, but googling does not find an option to do that.

Solution

Assuming your pager is less, try LESS=-FX; export LESS in your shell environment.

From man less:

-F or --quit-if-one-screen
Causes less to automatically exit if the entire file can be dis‐
played on the first screen.

-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 clear‐
ing the screen.

To have this only in psql, set it with a meta-command in .psqlrc:

\setenv LESS -FX

Context

StackExchange Database Administrators Q#163561, answer score: 8

Revisions (0)

No revisions yet.