4

I'm running

psql -U postgres template1 -c "select * from pg_stat_activity"

and the output is too wide for my terminal. Is there a *nix command I can use to prevent the output from wrapping? Maybe a setting in screen that enables virtual horizontal scrolling?

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
erikcw
  • 697
  • 13
  • 22

4 Answers4

7

Try

psql ... | less -S

The -S option to less enables horizontal scrolling instead of line wrapping.

David Z
  • 5,376
  • 2
  • 24
  • 22
1

If you don't want to (or can't) use a pager for some reason, you can also use cut:

psql ... | cut -c1-60

This takes only the first 60 characters of each line. No scrolling however.

Chris Lercher
  • 3,982
  • 9
  • 34
  • 41
1

fmt is probably what you want; it will wrap lines at a given column. pr has more options and is more complex.

mpez0
  • 1,492
  • 9
  • 9
0

Consider adding -P format=wrapped to your psql invocation, if you're using pg 8.4 or newer.