Postgresql Postgres连接问题

Postgresql Postgres连接问题,postgresql,macos,hosts,Postgresql,Macos,Hosts,我用brew(在Mac上)安装并启动了我的Postgres数据库。我还在我的/etc/hosts文件中定义了一个条目(我尝试了127.0.0.1 postgres和postgres) 然而,当我尝试 psql-h postgres-U postgres-p5432 我无法连接 psql:无法连接到服务器:连接被拒绝 然而,当我尝试使用 psql-h localhost-U postgres-p5432 我可以连接。连接所需的内容:psql-h postgres-U postgres-p 54

我用brew(在Mac上)安装并启动了我的Postgres数据库。我还在我的
/etc/hosts
文件中定义了一个条目(我尝试了
127.0.0.1 postgres
postgres

然而,当我尝试

psql-h postgres-U postgres-p5432
我无法连接

psql:无法连接到服务器:连接被拒绝

然而,当我尝试使用

psql-h localhost-U postgres-p5432

我可以连接。连接所需的内容:
psql-h postgres-U postgres-p 5432

确保您的PostgreSQL服务器愿意接受端口5432上的tcp/ip连接

在PostgreSQL配置文件中检查这些值

listen_addresses = '*'
port = 5432

看起来你的主机文件是错误的。你能ping到postgres吗?我想这是一个与操作系统相关的问题,而不是与PSQL相关的问题。如果您的系统将地址
postgres
解析为
localhost
,您应该能够以这种方式进行连接。如果您运行
ping postgres
,会发生什么情况?谢谢-这使我能够以postgres或localhost作为主机名进行连接。