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?

mustaccio
28.7k24 gold badges60 silver badges77 bronze badges
asked Feb 26, 2014 at 11:50
4
  • What platform are you on? And how did you install PostgreSQL exactly? Commented 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". Commented Feb 26, 2014 at 13:01
  • Yeah, I noticed the bash, too (and removed the comment.) Commented Feb 26, 2014 at 13:11
  • Have you tried PowerShell? Commented 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\PostgreSQL9円.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.

Pang
2091 silver badge8 bronze badges
answered Jan 11, 2018 at 13:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.