Postgresql – How to change the default external text editor in psql

configurationpostgresqlpsql

I want to change the external editor in psql. But the command select-editor does not work. How can I change it? How do I run the command?

Best Answer

There are environmental variables you can set, from man psql

PSQL_EDITOR, EDITOR, VISUAL

Editor used by the \e, \ef, and \ev commands. These variables are examined in the order listed; the first that is set is used.

The built-in default editors are vi on Unix systems and notepad.exe on Windows systems.

The PSQL_EDITOR is if you want to specify a unique editor for just PostgreSQL. You can probably ignore that as not many people have a different editor for that, but in the event you're using a SQL Editor, go for it.

On Linux, you probably want to change EDITOR. On Ubuntu and Debian, that's done like this,

sudo update-alternatives --config editor