我正在尝试使用Java应用程序连接到与我的计算机在同一网络中的Postgresql数据库。 当我使用localhost(或127.0.0.1)时,一切正常,但当我用我的计算机的本地IP替换它时,发生连接拒绝错误。 我编辑了pg_hba.conf文件:
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 192.168.0.0/16 trust
host all all 127.0.0.1/24 trust
# IPv6 local connections:
host all all ::1/128 trust
host all all fe80::/10 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 192.168.1.15/24 trust
host replication all ::1/128 trust
host duplicate all fe80::/10 trust
postgresql.conf中的listen_addresses:
#listen_addresses = ‘*’ # what IP address(es) to listen on;
所以我仍然无法连接到数据库。 当我从pg_hba.conf中删除它时
local all all trust
当我使用localhost / 127.0.0.1进行连接时发生连接拒绝错误。 谢谢你的帮助。
答案 0 :(得分:0)
这是评论
#listen_addresses = ‘*’ # what IP address(es) to listen on;
将其更改为
listen_addresses = ‘*’ # what IP address(es) to listen on;
重新启动postgres服务器,其他一切都很好。
希望这有帮助!