Disable pager for psql
PostgreSQL's CLI psql
offers a myriad of helpful features.
For example, psql
detects whenever a large result-set is returned and uses a pager to display the content.
While this is great for viewing your data, it is really inconvenient for automating tasks, as the pager needs user input to be terminated.
So, how can we circumvent / deactivate the pager?
# original, shows the pager
psql -h localhost -U postgres -c "SELECT * FROM pg_class"
# just pipe the output to `cat`
psql -h localhost -U postgres -c "SELECT * FROM pg_class" | cat
# if you are not interested in the output, you can also write to /dev/null
psql -h localhost -U postgres -c "SELECT * FROM pg_class" > /dev/null
# alternatively, you can use the environment variable `PAGER` to choose which pager should be used
PAGER=cat psql -h localhost -U postgres -c "SELECT * FROM pg_class"
# best method: completely turn off the pager
psql -h localhost -U postgres -P pager=off -c "SELECT * FROM pg_class"
Additionally, if you want to disable the pager while in interactive mode, just type \pset pager off
.