How to set default display mode in psql

There is an option of -x but it does not do the job for me as I am using COPY to send output to a file. Without copy "-x" works well!

So here is what I have done to read:

# psql -U postgres -o /tmp/output_file_name.txt <<EOF
\x
SELECT * FROM pg_stat_activity;
EOF

Expanded display is on.

One can morph the above to whatever he/she needs to do. One can also do the same with an input file.


Use .psqlrc to set defaults.

For the specific case of \x, newer psql versions (9.3, I think, but it might just be the 9.4 pre-release) can automatically switch to expanded output mode when the rows are too wide to fit on a line. From \?:

\x [on|off|auto] toggle expanded output (currently off)

So I suggest putting \x auto in your .psqlrc, rather than forcing it to on.


It should also be noted that the psql command line option -x or --expanded is the same as using \x from within.


psql command-line options:

-P expanded=auto
--pset expanded=auto
-x
--expanded

within the psql shell:

\x