windows Postgres“psql 未被识别为内部或外部命令”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30401460/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:04:59  来源:igfitidea点击:

Postgres "psql not recognized as an internal or external command"

windowspostgresqlcommand-line

提问by as1216

For Postgres, I keep getting this error multiple times even though I have already set the location of the bin folder to the path variable in Windows 8. Is there something else I'm missing?

对于 Postgres,即使我已经在 Windows 8 中将 bin 文件夹的位置设置为路径变量,我仍然多次收到此错误。还有什么我遗漏的吗?

(I can't post pictures since I don't have enough reputation)

(因为我没有足够的声誉,我无法发布图片)

回答by Shahin

Just an update because I was trying it on Windows 10 you do need to set the path to the following: ;C:\Program Files\PostgreSQL\9.5\bin ;C:\Program Files\PostgreSQL\9.5\lib

只是一个更新,因为我是在 Windows 10 上尝试的,您确实需要将路径设置为以下内容: ;C:\Program Files\PostgreSQL\9.5\bin ;C:\Program Files\PostgreSQL\9.5\lib

You can do that either through the CMD by using set PATH [the path]or from my

您可以通过 CMD 使用set PATH [the path]或从我的

computer => properties => advanced system settings=> Environment Variables => System Variables

计算机 => 属性 => 高级系统设置 => 环境变量 => 系统变量

Then search for path.

然后搜索路径。

Important:don't replace the PATHs that are already there just add one beside them as follows ;C:\Program Files\PostgreSQL\9.5\bin ;C:\Program Files\PostgreSQL\9.5\lib

重要提示:不要替换已经存在的路径,只需在它们旁边添加一个,如下所示;C:\Program Files\PostgreSQL\9.5\bin ;C:\Program Files\PostgreSQL\9.5\lib

Please note: On windows 10, if you follow this: computer => properties => advanced system settings=> Environment Variables => System Variables> select PATH, you actually get the option to add new row. Click Edit, add the /bin and /lib folder locations and save changes.

请注意:在 Windows 10 上,如果您遵循以下操作:计算机 => 属性 => 高级系统设置 => 环境变量 => 系统变量> 选择 PATH,您实际上可以选择添加新行。单击编辑,添加 /bin 和 /lib 文件夹位置并保存更改。

Then close your command prompt if it's open and then start it again try psql --version If it gives you an answer then you are good to go if not try echo %PATH%and see if the path you set was added or not and if it's added is it added correctly or not.

然后关闭你的命令提示符,如果它是打开的,然后再次启动它尝试 psql --version 如果它给你一个答案那么你很高兴如果不尝试echo %PATH%看看你设置的路径是否被添加,如果它被添加是它添加正确与否。

回答by Nate

Make sure that the path actually leads to the executables. I'm using version 11 and it did not work until this was set as the path:

确保路径实际上指向可执行文件。我正在使用版本 11,直到将其设置为路径才起作用:

C:\Program Files\PostgreSQL\11\bin\bin

C:\Program Files\PostgreSQL\11\bin\bin

Maybe this is how version 11 is structured or I somehow botched the installation but I haven't had a problem since.

也许这就是版本 11 的结构,或者我以某种方式搞砸了安装,但从那时起我就没有遇到过问题。

回答by voluntier

I had your issue and got it working again (on windows 7).

我遇到了你的问题并让它再次工作(在 Windows 7 上)。

My setup had actually worked at first. I installed postgresand then set up the system PATH variables with C:\Program Files\PostgreSQL\9.6\bin; C:\Program Files\PostgreSQL\9.6\lib. The psql keyword in the command line gave no errors.

我的设置一开始确实有效。我安装了 postgres,然后使用C:\Program Files\PostgreSQL\9.6\bin; C:\Program Files\PostgreSQL\9.6\lib. 命令行中的 psql 关键字没有给出错误。

I deleted the PATH variables above one at a time to test if they were both really needed. Psql continued to work after I deleted the lib path, but stopped working after I deleted the bin path. When I returned bin, it still didn't work, and the same with lib. I closed and reopened the command line between tries, and checked the path. The problem lingered even though the path was identical to how it had been when working. I re-pasted it.

我一次删除一个上面的 PATH 变量来测试它们是否真的需要。psql在我删除lib路径后继续工作,但在我删除bin路径后停止工作。当我返回bin时,它仍然不起作用,与lib相同。我在两次尝试之间关闭并重新打开命令行,并检查了路径。即使路径与工作时的路径相同,问题仍然存在。我重新粘贴了。

I uninstalled and reinstalled postgres. The problem lingered. It finally worked after I deleted the spaces between the "; C:..." in the paths and re-saved.

我卸载并重新安装了 postgres。问题一直存在。在我删除路径中“; C:...”之间的空格并重新保存后,它终于起作用了。

Not sure if it was really the spaces that were the culprit. Maybe the environment variables just needed to be altered and refreshed after the install.

不确定是否真的是罪魁祸首的空间。也许安装后只需要更改和刷新环境变量即可。

I'm also still not sure if both lib and bin paths are needed since there seems to be some kind of lingering memory for old path configurations. I don't want to test it again though.

我也不确定是否需要 lib 和 bin 路径,因为旧路径配置似乎有某种挥之不去的记忆。不过我不想再测试了。

回答by Unnit Metaliya

If you tried all the answers and still spinning your heads, don't forget to change the version with your one which you downloaded.

如果您尝试了所有答案,但仍然头晕目眩,请不要忘记使用您下载的版本更改版本。

For example, don't simply copy paste

例如,不要简单地复制粘贴

;C:\Program Files\PostgreSQL.5\bin ;C:\Program Files\PostgreSQL.5\lib

More clearly,

更清楚,

;C:\Program Files\PostgreSQL\[Your Version]\bin ;C:\Program Files\PostgreSQL\[Your Version]\lib

I was spinning my heads. Hope this helps.

我头晕目眩。希望这可以帮助。

回答by Abdel-Raouf

Windows 10

视窗 10

It could be that your server doesn't start automatically on windows 10 and you need to start it yourself after setting your Postgresql path using the following command in cmd:

可能是您的服务器没有在 Windows 10 上自动启动,您需要在 cmd 中使用以下命令设置 Postgresql 路径后自己启动它:

pg_ctl -D "C:\Program Files\PostgreSQL.4\data" start

You need to be inside "C:\Program Files\PostgreSQL\11.4\bin" directory to execute the above command.

你需要在“C:\Program Files\PostgreSQL\11.4\bin”目录下才能执行上面的命令。

EX:

前任:

enter image description here

在此处输入图片说明

You still need to be inside the bin directory to work with psql

您仍然需要在 bin 目录中才能使用 psql

回答by derRichter

Even if it is a little bit late, i solved the PATH problem by removing every space.

即使有点晚了,我还是通过删除每个空格来解决 PATH 问题。

;C:\Program Files\PostgreSQL.5\bin;C:\Program Files\PostgreSQL.5\lib

works for me now.

现在对我来说有效。

回答by Divine Hycenth

Enter this path in your System environment variable.

在您的系统环境变量中输入此路径

C:\Program Files\PostgreSQL\[YOUR PG VERSION]\bin

In this case i'm using version 10. If you check the postgres folder you are going to see your current versions.

在这种情况下,我使用的是版本 10。如果您检查 postgres 文件夹,您将看到您当前的版本。

In my own case i used the following on separate lines:

在我自己的情况下,我在单独的行中使用了以下内容:

C:\Program Files\PostgreSQL\bin
C:\Program Files\PostgreSQL\lib

回答by Michael Jay

Simple solution that hasn't been mentioned on this question: restart your computer after you declare the path variable.

此问题未提及的简单解决方案:声明路径变量后重新启动计算机。

I always have to restart - the path never updates until I do. And when I do restart, the path always is updated.

我总是必须重新启动 - 路径永远不会更新,直到我这样做。当我重新启动时,路径总是会更新。

回答by Anupam Maurya

Find your binaries file where it is saved. get the path in terminal mine is

找到保存它的二进制文件。获取终端矿的路径是

C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin

then find your local user data path, it is in mostly

然后找到您的本地用户数据路径,它主要在

C:\usr\local\pgsql\data

now all we have to hit the following command in the binary terminal path:

现在我们只需要在二进制终端路径中点击以下命令:

C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin>pg_ctl -D "C:\usr\local\pgsql\data" start

done!

完毕!