【问题标题】:Connected to Postgresql error连接到 Postgresql 错误
【发布时间】:2013-10-26 23:00:51
【问题描述】:

我正在尝试连接到 Postgres,这是我收到的错误消息:

[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5433/postgres
[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=postgres, password=****}
[main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

我已在 hibernate.conf 中验证用户名/密码正确

    <!-- Database connection settings -->
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.url">jdbc:postgresql://localhost/postgres</property>
    <property name="connection.username">postgres</property>
    <property name="connection.password">*******</property>

这是我的 pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
# host   postgres,replication    localhost   127.0.0.1/32    md5
# host   postgres,replication    localhost   ::1/128     md5
host     all     all     0.0.0.0/0   md5

我在 Windows(不是 UNIX)上工作。所以请建议我如何解决这个问题。

谢谢!

【问题讨论】:

  • 嗨 Postgres 默认在端口 5432 上运行。检查您的 postgres 进程是否正在运行,如果是,则在哪个端口上运行。
  • postgres 在 5432 上运行。我确实检查过,但仍然是同样的问题。如果我需要进行任何更改,请检查我的 pg_hba.conf。
  • NFO org.hibernate.connection.DriverManagerConnectionProvider - 使用驱动程序:org.postgresql.Driver 在 URL:jdbc:postgresql://localhost:5433/postgres ..根据您尝试制作的日志5433 上的连接,您的 postgres 正在 5432 上运行
  • 感谢您指出!

标签: java database hibernate postgresql tcp


【解决方案1】:

连接 url 中的端口号在哪里。 jdbc:postgresql://localhost:portno/postgres

所以最终的 url 应该根据我的电脑上的数据库服务器端口

jdbc:postgresql://localhost:5432/postgres

【讨论】:

    猜你喜欢
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 2015-11-18
    • 2016-03-28
    相关资源
    最近更新 更多