4

I am trying to use psql from a Windows command prompt (cmd.exe), but can't access any of the previous commands with the up/down cursors. I could also really do with finding out where the PostgreSQL equivalent to .bash_history is (if there is one), as I could read the command history from there.

\s produces the following error:

history is not supported by this installation

Is there a way to get the psql command history on Windows?

4
  • What platform are you on? And how did you install PostgreSQL exactly? Feb 26, 2014 at 12:10
  • @ypercube Does he mean "command prompt windows" or "Windows" the OS? His reference to .bash_history is confusing, whereas he talks about "command prompt" and not "shell". Feb 26, 2014 at 13:01
  • Yeah, I noticed the bash, too (and removed the comment.) Feb 26, 2014 at 13:11
  • Have you tried PowerShell? Feb 26, 2014 at 19:07

1 Answer 1

3

On Windows, there isn't an exact equivalent to a .bash_history because cmd.exe is an intrinsically different type of shell. I think you're referring more to the .psql_history (see related question).

There is a "SQL Shell" available in the SQL Command Line Terminal of the EnterpriseDB Windows distribution of PostgreSQL that supports a command history. However, I prefer to use the Windows command prompt instead of the GUI.

The error message you are getting indicates that psql.exe was built without readline support (reference).

The best way I have found to run psql via the normal Windows command prompt is to create a shortcut:

Target: %SystemRoot%\system32\cmd.exe /U /c "chcp 1252 & C:\Progra~1\PostgreSQL\9.6\bin\psql.exe -U database_username -d database_name"

psql shortcut

The command history can be controlled via Command history Buffer size in the Options pane:

psql shortcut options

And you can adjust the scrollable output via Screen Buffer Height in the Layout pane:

psql shortcut layout

This will get you a history via the up and down arrows, but only within your current session. It will not be preserved across sessions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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