PostgreSQL连接被拒绝

din*_*239 6 postgresql connection localhost server connection-refused

我已经安装了PostgreSQL。但是,每次我尝试通过PGAdmin或通过psql连接时,都会出现以下错误。

could not connect to server: Connection refused (0x0000274D/10061) 
      Is  the server running on host "localhost" (::1) and 
      accepting TCP/IP  connections on port 5432? 
could not connect to server: Connection  refused (0x0000274D/10061) 
      Is the server running on host "localhost" (127.0.0.1) and 
      accepting TCP/IP connections on port 5432?
Run Code Online (Sandbox Code Playgroud)

我检查了postgresql.conf文件和行:listen_addresses = '*'未注释掉。

这也是我的pg_hba.conf文件设置方式:

# IPv4 local connections:
  host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
  host    all             all             ::1/128                 trust
Run Code Online (Sandbox Code Playgroud)

谁能建议我如何解决此问题?

谢谢!

tay*_*lıç 6

使用服务“开始 -> 运行 -> services.msc”并查找 postgresql-[vers] 服务。

如果它没有运行,请尝试启动它,如果它不会启动,请打开事件查看器(开始 -> 运行 -> eventvwr)并查找与 PostgreSQL 服务相关的错误消息。


Gab*_*Gab 0

pg_hba.conf.txt必须调用pg_hba.conf

除此之外,当您遇到身份验证错误时,您将收到类似以下内容的消息:

psql -U nonexistent
psql: FATAL:  Peer authentication failed for user "nonexistent"
Run Code Online (Sandbox Code Playgroud)

您收到的错误很可能意味着 PostgreSQL 未在此服务器上启动。

您可以使用以下命令启动 PostgreSQL:

service postgresql start
service postgresql status
Run Code Online (Sandbox Code Playgroud)