【问题标题】:I can't connect to the postgresql database我无法连接到 postgresql 数据库
【发布时间】:2021-11-14 05:55:51
【问题描述】:

项目正在运行,使用 Java 并在服务器上旋转。 我正在尝试连接到 postgresql 数据库并收到此错误:

FATAL: password authentication failed for user "postgres"

这里是来自文件 application.xml 的设置

spring:
  profiles:
    active: @spring.profiles.active@
  jpa:
    hibernate:
      ddl-auto: none
  datasource:
    initialization-mode: always
    platform: convert
    driver-class-name: org.postgresql.Driver
    username: postgres
    password: postgres
    url: jdbc:postgresql://localhost:5432/mark_convert
    jdbc-url: jdbc:postgresql://localhost:5432/mark_convert
  liquibase:
    change-log: classpath:db/changelog.xml

这里是 Docker-compose 文件

  postgres-converter:
    container_name: postgres-converter
    image: postgres:13.2-alpine
    restart: unless-stopped
    ports:
      - "5435:5432"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=converter
      - POSTGRES_PASSWORD=postgres
    volumes:
      - ./postgres_converter_data:/var/lib/postgresql/data

这里是连接设置

如果有人更改了数据库中的密码,那么 Java 应用程序将无法使用此数据库?

我会给你另一个关于 liquibase 的文件,但它更让我困惑,显示的名称完全不同。

    <createTable  tableName="converter_history" schemaName="history">
        <column  name="id"  type="BIGINT"  autoIncrement="true">
            <constraints  primaryKey="true"  nullable="false"/>
        </column>
        <column  name="type"  type="varchar(20)"/>
        <column  name="pic_number"  type="varchar(4)"/>
        <column  name="part_number_oem"  type="varchar(50)"/>
        <column name="date_added" type="timestamp" defaultValueComputed="current_timestamp">
            <constraints nullable="false"/>
        </column>
        <column name="result" type="varchar(50)">
            <constraints nullable="false"/>
        </column>
    </createTable>

【问题讨论】:

  • 看起来您的数据库名称是converter,但在application.xml 的连接字符串中,数据库名称是mark_convert
  • 这也误导了我。但是这个项目的开发者已经消失了,也没有人问。我试图在连接中指定数据库名称 mark_convert。同样的错误。

标签: java spring postgresql


【解决方案1】:

也许您不允许使用密码进行连接。 确认pg_hba.conf文件是否有以下内容。

/var/lib/pgsql/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-27
    • 2014-03-30
    • 2013-04-19
    • 2022-12-03
    • 2022-12-05
    • 2021-02-09
    • 2012-05-03
    • 1970-01-01
    相关资源
    最近更新 更多