无法连接到 PostgreSQL

发布于 2024-10-14 23:45:09 字数 951 浏览 0 评论 0原文

我正在尝试访问其他机器上存在的 PostgreSQL 中的表。 我收到以下错误。

Connection refused. Check that the hostname and port are correct and that the
postmaster is accepting TCP/IP connections.

at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:393)
    at org.postgresql.Driver.connect(Driver.java:267)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)

我也在 pg_hba.conf 文件中配置了我的 IP,但存在相同的错误。有什么解决办法吗?

I am trying to access a table from PostgreSQL present in other machine.
I am getting the following error.

Connection refused. Check that the hostname and port are correct and that the
postmaster is accepting TCP/IP connections.

at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:393)
    at org.postgresql.Driver.connect(Driver.java:267)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)

I have configured my ip in pg_hba.conf file as well but the same error exists. What could be the solution for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你与清晨阳光 2024-10-21 23:45:09

您可以远程登录到您认为 PostgreSQL 正在侦听的 IP 地址和端口号吗?

  • 如果没有,问题在于邮局管理员没有运行,或者您的网络中有一些奇怪的东西 - 防火墙阻止了对端口的访问,或者无法找到主机或其他什么。

  • 如果您可以通过 telnet 联系到 postmaster,那么可能是您提供了错误的凭据或其他信息 - 但该错误表明您的客户端代码无法找到远程 PostgreSQL。不过,更有可能的是,Java 代码使用的配置与您在使用 telnet 时成功演示的配置不同。

Can you telnet to the IP address and port number where you think PostgreSQL is listening?

  • If not, the trouble is that the postmaster is not running, or that you have something screwball in your network - firewalls blocking access to the port, or can't locate the host or whatever.

  • If you can get to the postmaster via telnet, then it may be that you've given the wrong credentials or something - but the error suggests that your client code is unable to find the remote PostgreSQL. More likely, though, the configuration being used by the Java code is not the same as the one you successfully demonstrated as working with telnet.

做个ˇ局外人 2024-10-21 23:45:09

我是 PostgreSql 的新手,但我也多次遇到同样的问题,最后我找到了解决方案。

问题在于防火墙阻止端口(例如:5432),一旦通过防火墙授予访问权限,我就能够连接到数据库服务器。

您必须仅将 postgreSql 中使用的端口添加到防火墙。

之后我的 postgreSql 与 Jdbc 一起工作得很好。

I am new to PostgreSql but i also had a same problem so many times, at last i found solution.

The problem was with firewall blocking port (for Ex : 5432) , once this was granted access through the firewall, i was able to connect to the database server.

You have to add only port which you are using in postgreSql to Firewall.

after this my postgreSql works Fine with Jdbc.

甜警司 2024-10-21 23:45:09

postgresql.conf 中“listen_addresses”的设置是什么?

SHOW listen_addresses;

pg_hba.conf 和 postgresql.conf 更改后您是否重新加载了配置文件?

SELECT pg_reload_conf();

What is the setting for "listen_addresses" in postgresql.conf?

SHOW listen_addresses;

And did you reload the configurationfiles after the changes in pg_hba.conf and postgresql.conf?

SELECT pg_reload_conf();
一场信仰旅途 2024-10-21 23:45:09

我有同样的问题。我在 pg_hba.conf 中添加了以下条目并工作了。确保在更改配置文件后重新启动 postgres

host    all         all         0.0.0.0/0         md5

I has same problem. I added following entry in pg_hba.conf and worked. Make sure you restart postgres after changin configuration file

host    all         all         0.0.0.0/0         md5
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文