Thursday, February 2, 2012

Disabling Postgres Pagination

If you query your PostgreSQL DB and the results are too long to fit on one page, the default postgres behavior is to paginate the results with something like `more` or `less`. Sometimes you don't want this. Here's how to disable pagination:

To disable pagination temporarily when you in the postgres command line:
=# \pset pager
This will toggle pagination, so you can use it again to go back to the normal mode. (The "=#" is just the prompt; type the stuff following that)

To disable it when you start up psql:
$ psql -U admin db_name --pset pager=off

And finally, if you always want it to be off, you can add this to your `.bashrc` file:
alias psql='psql --pset pager=off'

3 comments:

  1. Just wanted to add that you can also do "\pset pager off" if you always want to turn the pager off regardless of what it's previous setting was.

    ReplyDelete
  2. Just to complement, instead of an alias you can setup ~/.psqlrc with "\pset pager off".

    Also, default less config is a bit annoying when you have many or long columns, so I tend do use: \setenv PAGER 'less -SFXC'

    ReplyDelete