java - 连接本地网络中的 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 连接时发生连接被拒绝错误事件。感谢您的任何帮助。
解决方案
这是评论
#listen_addresses = ‘*’ # what IP address(es) to listen on;
将其更改为
listen_addresses = ‘*’ # what IP address(es) to listen on;
重新启动 postgres 服务器,其他一切都很好。
希望这可以帮助 !
推荐阅读
- css - 仅在选中/取消选中复选框时转换
- python - 无法解决零星的拆分记录问题
- javascript - Discord.js 是否可以仅使用“关闭”(没有 channeID)删除频道?
- angular - 带有 Angular 的 amazon-ivs-player
- kotlin - 访问可选的 kotlin.Result
- pytorch - 如何将常量列表附加到张量板中的运行?
- python - ImportError:“测试”模块不正确
- .htaccess - .htaccess 重写以重定向到带有变量的子目录
- node.js - 当我重新加载太多次时网站崩溃
- python - 如何在父类的 __init__ 调用的方法中使用子类的属性