首页 > 解决方案 > psql -h IP/localhost -U postgres -W/-w 不工作

问题描述

我正在尝试使用以下 2 个命令连接到 postgres DB,但无法连接到 DB:

输出:

-bash-4.2$ psql -h 10.x.x.x -U postgres -W
Password: 
psql: could not connect to server: Connection refused
Is the server running on host "10.54.48.59" and accepting
TCP/IP connections on port 5432?
-bash-4.2$ 
-bash-4.2$ psql -h localhost -U postgres -W
Password: 
psql: FATAL:  Ident authentication failed for user "postgres"
-bash-4.2$

但是当我尝试使用没有 IP 的命令连接到数据库时,它可以工作:

-bash-4.2$ psql -U postgres -W
Password: 
psql (11.3)
Type "help" for help.

postgres=# 

我也尝试在我的 pg_hba.conf 中包含以下列表:

host    all             all             127.0.0.1/32            ident
host    all             all             127.0.0.1/32            md5
host    all             all             127.0.0.1/32            password

标签: postgresql

解决方案


你可以试试...

host    all             all             127.0.0.1/32            trust

接着

psql -h localhost -U postgres DB

推荐阅读