Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default display mode in psql

Almost every psql query comes out an illegible mess if not preceded by display configuration commands such as \x auto. Typing this manually for each psql instance is annoying.

Expanded display is used automatically.

Is there any way to configure a better default display? Or perhaps the answer is to use a more advanced interactive terminal?

like image 569
Ryne Everett Avatar asked Jan 04 '14 16:01

Ryne Everett


People also ask

What does '# mean in psql?

postgres=# means you could start a new command. postgres-# means this is the continuation of the active command.

How can we turn on expanded mode in PostgreSQL?

within the psql shell: Also to note: the psql command line option -P expanded=auto or --pset expanded=auto is the same as using \x auto from within.

How do I get out of psql mode?

The meta-command for exiting psql is \q .

Is PostgreSQL and psql same?

psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results.


1 Answers

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.

like image 96
Craig Ringer Avatar answered Sep 21 '22 20:09

Craig Ringer