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?
-
What platform are you on? And how did you install PostgreSQL exactly?Craig Ringer– Craig Ringer2014年02月26日 12:10:33 +00:00Commented 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".Colin 't Hart– Colin 't Hart2014年02月26日 13:01:43 +00:00Commented Feb 26, 2014 at 13:01
-
Yeah, I noticed the bash, too (and removed the comment.)ypercubeᵀᴹ– ypercubeᵀᴹ2014年02月26日 13:11:29 +00:00Commented Feb 26, 2014 at 13:11
-
Have you tried PowerShell?Neil McGuigan– Neil McGuigan2014年02月26日 19:07:56 +00:00Commented Feb 26, 2014 at 19:07
1 Answer 1
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"
The command history can be controlled via Command history Buffer size
in the Options pane:
And you can adjust the scrollable output via Screen Buffer Height
in the Layout pane:
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.