windows 如何启动 psql.exe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47606648/
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
How to start psql.exe
提问by pgny
I'm new to postgresql (pg). I understand that in order to interact with pg, I must use psql.exe.
我是 postgresql (pg) 的新手。据我所知,为了与 pg 交互,我必须使用 psql.exe。
In my system, I find psql.exe not once, but twice, why? (C:\Program Files (x86)\pgAdmin 4\v2\runtime\psql.exe
and C:\Program Files\PostgreSQL\10\bin\psql.exe
). I tried both, with identical (negative) results.
在我的系统中,我发现 psql.exe 不是一次,而是两次,为什么?(C:\Program Files (x86)\pgAdmin 4\v2\runtime\psql.exe
和C:\Program Files\PostgreSQL\10\bin\psql.exe
)。我尝试了两者,结果相同(否定)。
In line with Q/A In PostgreSQL why does command line window disappear when I press Enter after entering my password?, I now, instead of running psql.exe directly, I first opened a generic (Windows) command window and then ran psql.exe from within this generic command window; I then entered the password and Enter.
符合 Q/A在 PostgreSQL 中为什么输入密码后按 Enter 时命令行窗口消失?,我现在不是直接运行 psql.exe,而是首先打开一个通用(Windows)命令窗口,然后从这个通用命令窗口中运行 psql.exe;然后我输入密码并回车。
In the generic (Windows) command window, I now got the message:
在通用 (Windows) 命令窗口中,我现在收到消息:
psql: could not connect to server: Permission denied (0x0000271D/10013)
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? FATAL: password authentication failed for user "User"
psql: 无法连接到服务器:权限被拒绝 (0x0000271D/10013)
服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?致命:用户“用户”的密码验证失败
This corresponds to the problem described (but not resolved) in the Q/A cited above. Other threads in this forum re pg password fails concern Linux / outdated passwords / new passwords after password changes.
这对应于上述 Q/A 中描述(但未解决)的问题。此论坛中的其他线程重新设置密码失败关注 Linux / 过时的密码 / 密码更改后的新密码。
It's said in other threads here re this question that in Windows, there is a file pgpass.conf
. I find a help file libpq-pgpass.html which also says that, while on my system, there is no such file pgpass.conf (or anything else with "pgpass" except for the aforementioned html file).
在这里的其他线程中提到这个问题,在 Windows 中,有一个文件pgpass.conf
. 我找到了一个帮助文件 libpq-pgpass.html ,它也说,虽然在我的系统上,没有这样的文件 pgpass.conf (或除了上述 html 文件之外的任何其他带有“pgpass”的文件)。
(W10 Prof 64 bit English)
(W10 Prof 64 位英文)
Second strategy:
第二个策略:
Within the StartMenu, there is an entry "PostgreSQL"; under that - available by Enter - there is a sub-entry "SQL Shell (psql)"; so I tried that.
在开始菜单中,有一个条目“PostgreSQL”;在那个 - 通过 Enter 可用 - 有一个子条目“SQL Shell(psql)”;所以我试过了。
From there only, I get the Windows cmd window, with "psql 10.1" and with (in [] it's obviously the default values):
仅从那里,我得到了带有“psql 10.1”和(在 [] 中显然是默认值)的 Windows cmd 窗口:
Server [localhost]: I enter localhost; Database [postgres]: I enter postgres; Port [5432]: I enter 5432; Username [postgres]: I enter postgres; Password for user postgres: I enter the password which is "a".
Server [localhost]: I enter localhost; Database [postgres]: I enter postgres; Port [5432]: I enter 5432; Username [postgres]: I enter postgres; Password for user postgres: I enter the password which is "a".
From there, I get a warning re the Console code page which differs from Windows code page, but I then get the psql prompt
从那里,我收到与 Windows 代码页不同的控制台代码页的警告,但随后我得到了 psql 提示
postgres=#
and which works.
哪个有效。
On the other hand, with the first strategy above, I only get "Password:" and then, after entry of the real password (which is "a"), the "FATAL" error "password authentication failed for user "A"".
另一方面,使用上面的第一个策略,我只得到“密码:”,然后在输入真实密码(即“a”)后,出现“致命”错误“用户“A”的密码验证失败” .
Upon installation, I had created a superuser "postgres" with password "a", not a user "A"; on the other hand, I am user "A" which is my Windows admin (!) account (no other users than myself on my pc) and the cmd prompt I usually get ("C:\Users\A>"); (but as expected,) no different result if I enter the whole path to psql.exe from the prompt "C:>".
安装时,我创建了一个密码为“a”的超级用户“postgres”,而不是用户“A”;另一方面,我是用户“A”,它是我的 Windows 管理员(!)帐户(除了我自己在我的电脑上没有其他用户)和我通常得到的 cmd 提示(“C:\Users\A>”);(但正如预期的那样)如果我从提示“C:>”输入 psql.exe 的整个路径,则没有不同的结果。
So my problem comes now down to this: When triggered from within the start menu, psql.exe works correctly since it asks me all the questions I can then answer correctly (as stated above), while when started with its full path from the cmd window (both full paths tried and enclosed in "" of course), it just asks for the "password" and then tells me that for some "user A", that password is wrong.
所以我的问题现在归结为:当从开始菜单中触发时,psql.exe 可以正常工作,因为它会问我所有我可以正确回答的问题(如上所述),而当从 cmd 的完整路径开始时窗口(尝试并包含在“”中的完整路径当然),它只是要求输入“密码”,然后告诉我对于某些“用户 A”,该密码是错误的。
Also, the full path to the (functioning) psql.exe from within the start menu is C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PostgreSQL 10\psql.exe
, and if I try to run that from with the cmd window, I get "(path) is not recognized as an internal or external command, operable program or batch file.", since in there, it's "SQL Shell (psql).lnk", of which the properties are: "Target: "C:\Program Files\PostgreSQL\10\scripts\runpsql.bat"".
此外,从开始菜单中到(正常运行的)psql.exe 的完整路径C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PostgreSQL 10\psql.exe
是程序或批处理文件。”,因为在那里,它是“SQL Shell (psql).lnk”,其属性是:“目标:“C:\Program Files\PostgreSQL\10\scripts\runpsql.bat””。
So this is the solution, see my answer below.
所以这是解决方案,请参阅下面的答案。
回答by pgny
You don't run some psql.exe file, but the file C:\Program Files\PostgreSQL\10\scripts\runpsql.bat , for example programmatically, e.g. from AHK:
您不运行某些 psql.exe 文件,而是运行文件 C:\Program Files\PostgreSQL\10\scripts\runpsql.bat ,例如以编程方式,例如来自 AHK:
run, "C:\Program Files\PostgreSQL\10\scripts\runpsql.bat"
运行,“C:\Program Files\PostgreSQL\10\scripts\runpsql.bat”
Then you get a generic Windows command window which asks you the right questions (see above) and, when answered correctly, gives you the psql command prompt.
然后你会得到一个通用的 Windows 命令窗口,它会问你正确的问题(见上文),当回答正确时,会给你 psql 命令提示符。
回答by Vao Tsun
open command prompt first (Winkey+R
), then type C:\Program Files\PostgreSQL\10\bin\psql.exe
, then press enter and type in password. This is different from what you did by not closing psql.exe
after you get error.
首先打开命令提示符 ( Winkey+R
),然后键入C:\Program Files\PostgreSQL\10\bin\psql.exe
,然后按 Enter 并键入密码。这与您psql.exe
在收到错误后不关闭所做的不同。
After you see the error, please read it carefully and lookfor solution in SO or google (or even manual documentation). If you still fail - post another question.
看到错误后,请仔细阅读并在SO或google(甚至手动文档)中寻找解决方案。如果您仍然失败 - 发布另一个问题。
3rd party edit
第三方编辑
To use psql.exe under windows you may need to start it with the postgres
user
要在 windows 下使用 psql.exe,你可能需要用postgres
用户启动它
REM at the console of cmd.exe type
C:\PostgreSQL\bin>psql.exe -U postgres
REM this should result in this output
Password for user postgres: