首页 > 解决方案 > 连接本地网络中的 Postgresql 数据库

问题描述

我正在尝试使用 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 连接时发生连接被拒绝错误事件。感谢您的任何帮助。

标签: javapostgresql

解决方案


这是评论

#listen_addresses = ‘*’ # what IP address(es) to listen on;

将其更改为

listen_addresses = ‘*’ # what IP address(es) to listen on;

重新启动 postgres 服务器,其他一切都很好。

希望这可以帮助 !


推荐阅读