PostgreSQL 无法连接到本地主机 (Windows 10)

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

PostgreSQL unable to connect to localhost (Windows 10)

postgresqlpgadmin

提问by yoyani

I'am trying to connect to localHost on PG Admin but after entering all my server connection information, the window opened again and says : "Connection to DataBase failed"

我试图连接到 PG Admin 上的 localHost 但在输入我所有的服务器连接信息后,窗口再次打开并显示:“连接到数据库失败”

I already reinstall postgreSQL 6 times with differents versions. I checked that the user postgres exist, i modified pg_hba.conf by putting trust to the postgres user. But it's still not working

我已经用不同的版本重新安装了 6 次 postgreSQL。我检查了用户 postgres 是否存在,我通过信任 postgres 用户修改了 pg_hba.conf。但它仍然无法正常工作

I'am on Windows 10 Using the version 9.4.5 here are

我在 Windows 10 上使用 9.4.5 版,这里是

回答by Daniel

Debug this like this:

像这样调试:

  1. Is PostgreSQL running? Check the Services! If not, start it. If there is no service, reinstall Postgres and check the appropriate options. If it is still not there, the installer is not Windows 10 ready. Create the service manually after reading the docs. Update:If you get a permission error when starting the service, a reason might be that the user created for the PostgreSQL service doesn't have the "Log on as a service" permission. You can grant it like described in this Microsoft Technet article.

  2. Is the PostgreSQL port (default = 5432) open (Use netstat to check)? If not, check the postgresql.conf for the port. By default PostgreSQL listens only on localhost, not your external IP. Use "*" as the listen-IP in the PostgreSQL config, restart PostgreSQL.

  3. If the port is open the error message should not appear. If it still does, check the logfiles. Use "trust" everywhere in your pg_hba temporarilyto ensure this file is not the root of your problems.

  4. Come back and provide more info or accept this answer :)

  1. PostgreSQL 在运行吗?检查服务!如果没有,请启动它。如果没有服务,请重新安装 Postgres 并检查相应的选项。如果它仍然不存在,则安装程序尚未准备好 Windows 10。阅读文档后手动创建服务。更新:如果在启动服务时出现权限错误,原因可能是为 PostgreSQL 服务创建的用户没有“作为服务登录”权限。您可以按照Microsoft Technet 文章中的描述授予它。

  2. PostgreSQL 端口(默认 = 5432)是否打开(使用 netstat 检查)?如果没有,请检查 postgresql.conf 以获取端口。默认情况下,PostgreSQL 只在 localhost 上侦听,而不是你的外部 IP。在 PostgreSQL 配置中使用“*”作为监听 IP,重启 PostgreSQL。

  3. 如果端口已打开,则不应出现错误消息。如果仍然如此,请检查日志文件。暂时在 pg_hba 的任何地方使用“信任”以确保此文件不是问题的根源。

  4. 回来提供更多信息或接受这个答案:)

回答by Narayana

SET path in environment variables [postgres bin]

在环境变量中设置路径 [postgres bin]

set environment variable PGDATA <path_of_pgdata_folder> <== create it in postgres main folder

initdb.exe -D "C:\Users\<username>\Softwares\postgresql-9.6.14-1-windows-x64-binaries\pgsql\pgdata"

"pg_ctl" -D "C:\Users\<username>\Softwares\postgresql-9.6.14-1-windows-x64-binaries\pgsql\pgdata" -l logfile start

createuser -r postgres

now Open pgAdmin and connect to your database see image

现在打开 pgAdmin 并连接到您的数据库 查看图像