“postgres” 角色已存在,同时 “postgres” 角色不存在。

huangapple go评论52阅读模式
英文:

Role "postgres" already exists & Role "postgres" does not exist at the same time

问题

I'm trying to launch my spring boot microservices project in docker compose file.

Provided User : postgres
Provided Password : password

When I try to connect service with postgres db, console says this:

2023-05-07 10:30:48 2023-05-07T07:30:48.725Z  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-05-07 10:30:49 2023-05-07T07:30:49.863Z ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
2023-05-07 10:30:49 
2023-05-07 10:30:49 org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
...

But I'm entirely sure that passed credentials are right.

At the same time, the docker container I'm trying to connect to says that

2023-05-07 10:30:51 2023-05-07 07:30:51.287 UTC [41] DETAIL:  Role "postgres" does not exist.
2023-05-07 10:30:51     Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

If I try to create user named 'postgres' postgresql console tells me that it already exists;

docker-compose.yml file

  postgres-order:
    container_name: postgres-order
    image: postgres
    environment:
      POSTGRES_DB: order_service
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      PGDATA: /data/postgres
    volumes:
      - ./postgres-order:/data/postgres
    ports:
      - "5431:5431"
    command: -p 5431
    expose:
      - "5431"
    restart: always

  
  order-service:
    container_name: order-service
    image: registry.hub.docker.com/jirafus400/order-service:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres-order:5431/order_service
    depends_on:
      - postgres-order
      - broker
      - eureka-server
      - api-gateway

application-docker.properties file

spring.datasource.url=jdbc:postgresql://postgres-order:5431/order_service
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.driver-class-name=org.postgresql.Driver
server.port=8080
eureka.client.serviceUrl.defaultZone=http://eureka:password@eureka-server:8761/eureka
spring.kafka.bootstrap-servers=broker:29092
英文:

I'm trying to launch my spring boot microservices project in docker compose file.

Provided User : postgres
Provided Password : password

When I try to connect service with postgres db, console says this:

2023-05-07 10:30:48 2023-05-07T07:30:48.725Z  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-05-07 10:30:49 2023-05-07T07:30:49.863Z ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
2023-05-07 10:30:49 
2023-05-07 10:30:49 org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
...

But I'm entirely sure that passed credentials are right.

At the same time, the docker container I'm trying to connect to says that

2023-05-07 10:30:51 2023-05-07 07:30:51.287 UTC [41] DETAIL:  Role "postgres" does not exist.
2023-05-07 10:30:51     Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

If I try to create user named 'postgres' postgresql console tells me that it already exists;

docker-compose.yml file

  postgres-order:
    container_name: postgres-order
    image: postgres
    environment:
      POSTGRES_DB: order_service
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      PGDATA: /data/postgres
    volumes:
      - ./postgres-order:/data/postgres
    ports:
      - "5431:5431"
    command: -p 5431
    expose:
      - "5431"
    restart: always

  
  order-service:
    container_name: order-service
    image: registry.hub.docker.com/jirafus400/order-service:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres-order:5431/order_service
    depends_on:
      - postgres-order
      - broker
      - eureka-server
      - api-gateway

application-docker.properties file

spring.datasource.url=jdbc:postgresql://postgres-order:5431/order_service
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.driver-class-name=org.postgresql.Driver
server.port=8080
eureka.client.serviceUrl.defaultZone=http://eureka:password@eureka-server:8761/eureka
spring.kafka.bootstrap-servers=broker:29092

答案1

得分: 0

已解决。问题是卷是使用不同的Postgres凭据创建的。在我更改凭据后,它们不匹配。只需删除卷,一切都正常工作。

英文:

Solved. The problem was that the volumes was created with a different postgres credentials. And after I change credentials they're not matched. Just removed volumes and it all worked.

huangapple
  • 本文由 发表于 2023年5月7日 15:48:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定