Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The situation is the following. This is an Ubuntu box:

Linux ns3mx3 2.6.32-41-server #89-Ubuntu SMP Fri Apr 27 22:33:31 UTC 2012 x86_64 GNU/Linux

Which means that when I first issue \e in psql, I'm asked to choose an editor. Then there is the .selected_editor file, which contains

# Generated by /usr/bin/select-editor

So far this is OK (it's my problem that I consider this completely useless, but never mind).

Then I set up a .psqlrc file:

\set PSQL_EDITOR /usr/bin/vim
\set EDITOR /usr/bin/vim
\set VISUAL /usr/bin/vim

As you can see, I wanted to be sure not to miss a candidate variable for editor setting. The file is used as expected:

test=# \echo :EDITOR

But when I issue the \e command, none of these is used - I fall back to SELECTED_EDITOR. The situation remains just the same if I append an \unset SELECTED_EDITOR to the .psqlrc file.

Now how can I make .psqlrc setting win over the default editor?

(PostgreSQL version id 9.1.4)

share|improve this question
up vote 3 down vote accepted

From what I can understand by reading the psql documentation, PSQL_EDITOR, EDITOR or VISUAL are supposed to be shell environment variables. Therefore you should set them, for example, in your .bashrc, by adding the following line:

export PSQL_EDITOR=/usr/bin/vim

I have tested this by executing the following command line (which sets the given environment variable just for the executed command):

PSQL_EDITOR=/usr/bin/nano psql

and when I executed the \e command in psql, nano was correctly executed as the editor, even though my default selected editor is vim.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.