Ruby-on-rails 在 Windows 环境中无法识别 postgres 'psql' 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15869808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
postgres 'psql' command is not recognized in windows environment
提问by hellomello
It seems like I have it set up, I have my database.yml using postgres, and I can connect the database with pgadmin III, but when I tried using the psql command to test what version, it says that is is not recognized? Any idea what I should be doing?
好像我已经设置好了,我的database.yml使用postgres,我可以用pgadmin III连接数据库,但是当我尝试使用psql命令测试什么版本时,它说无法识别?知道我应该做什么吗?
I'm using windows and using command prompt with Ruby on Rails. Using PostgreSQL 9.2 installed with the EnterpriseDB one-click installer.
我正在使用 Windows 并在 Ruby on Rails 中使用命令提示符。使用随 EnterpriseDB 一键安装程序一起安装的 PostgreSQL 9.2。
回答by Craig Ringer
Assuming you installed PostgreSQL on Windows with the PostgreSQL "One-click" installer packaged by EnterpriseDB, psqlis not added to the PATHautomatically. That's partly because adding it to the path could otherwise cause confusion when people have multiple versions of PostgreSQL installed.
假设您使用 EnterpriseDB 打包的 PostgreSQL“一键式”安装程序在 Windows 上安装 PostgreSQL,psql不会PATH自动添加到PostgreSQL 。这部分是因为当人们安装了多个版本的 PostgreSQL 时,将它添加到路径中可能会导致混淆。
You need to specify the full explicit path to psql, eg:
您需要指定到 的完整显式路径psql,例如:
"%PROGRAMFILES%\Postgresql.2\bin\psql.exe"
or add psqlto the user PATHenvironment variable, see eg this guide.
或添加psql到用户PATH环境变量中,例如参见本指南。
回答by Rumi
Open Command Line
打开命令行
psql --version
if on above line psql version is not displayed, then follow below steps
如果上面的行没有显示 psql 版本,则按照以下步骤操作
(For Windows 7 OS)
Mycomputer->Properties->Advanced System Settings->EnvironmentVariables->Path->Edit->
(Donot remove any existing Path)
Add this
添加这个
;C:\Program Files\PostgreSQL.5\bin;C:\Program Files\PostgreSQL.5\lib
save it then
然后保存它
Reopen Command Prompt and repeat
重新打开命令提示符并重复
psql --version
C:\Users\rumi>psql --version
psql (PostgreSQL) 9.5.0
回答by FRANK WANG
it is because there should not be space between the ;and your psql path so it should be like *****;C:\Program Files\PostgreSQL\9.2\bin\.
这是因为;和你的 psql 路径之间不应该有空格,所以它应该像*****;C:\Program Files\PostgreSQL\9.2\bin\.
If there is a space after ******; then it will not work. You can actually type %PATH%in your cmd prompt and see how your environment variable and space looks like. I tried both cases for you, the first with space had the same error you mentioned and the second without space worked.
如果后面有空格******; 那么它就行不通了。您实际上可以输入%PATH%cmd 提示符并查看环境变量和空间的外观。我为您尝试了这两种情况,第一个有空格的错误与您提到的相同,第二个没有空格的错误。
回答by u84six
You need to set both the bin AND the lib path in your PATH environment variable separated by semicolons:
您需要在以分号分隔的 PATH 环境变量中设置 bin 和 lib 路径:
%PROGRAMFILES%\Postgresql\9.2\bin;%PROGRAMFILES%\Postgresql\9.2\lib
%PROGRAMFILES%\Postgresql\9.2\bin;%PROGRAMFILES%\Postgresql\9.2\lib

