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

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

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:

  1. 2023-05-07 10:30:48 2023-05-07T07:30:48.725Z INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
  2. 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.
  3. 2023-05-07 10:30:49
  4. 2023-05-07 10:30:49 org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
  5. ...

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

  1. 2023-05-07 10:30:51 2023-05-07 07:30:51.287 UTC [41] DETAIL: Role "postgres" does not exist.
  2. 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

  1. postgres-order:
  2. container_name: postgres-order
  3. image: postgres
  4. environment:
  5. POSTGRES_DB: order_service
  6. POSTGRES_USER: postgres
  7. POSTGRES_PASSWORD: password
  8. PGDATA: /data/postgres
  9. volumes:
  10. - ./postgres-order:/data/postgres
  11. ports:
  12. - "5431:5431"
  13. command: -p 5431
  14. expose:
  15. - "5431"
  16. restart: always
  17. order-service:
  18. container_name: order-service
  19. image: registry.hub.docker.com/jirafus400/order-service:latest
  20. environment:
  21. - SPRING_PROFILES_ACTIVE=docker
  22. - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres-order:5431/order_service
  23. depends_on:
  24. - postgres-order
  25. - broker
  26. - eureka-server
  27. - api-gateway

application-docker.properties file

  1. spring.datasource.url=jdbc:postgresql://postgres-order:5431/order_service
  2. spring.datasource.username=postgres
  3. spring.datasource.password=password
  4. spring.datasource.driver-class-name=org.postgresql.Driver
  5. server.port=8080
  6. eureka.client.serviceUrl.defaultZone=http://eureka:password@eureka-server:8761/eureka
  7. 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:

  1. 2023-05-07 10:30:48 2023-05-07T07:30:48.725Z INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
  2. 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.
  3. 2023-05-07 10:30:49
  4. 2023-05-07 10:30:49 org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
  5. ...

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

  1. 2023-05-07 10:30:51 2023-05-07 07:30:51.287 UTC [41] DETAIL: Role "postgres" does not exist.
  2. 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

  1. postgres-order:
  2. container_name: postgres-order
  3. image: postgres
  4. environment:
  5. POSTGRES_DB: order_service
  6. POSTGRES_USER: postgres
  7. POSTGRES_PASSWORD: password
  8. PGDATA: /data/postgres
  9. volumes:
  10. - ./postgres-order:/data/postgres
  11. ports:
  12. - "5431:5431"
  13. command: -p 5431
  14. expose:
  15. - "5431"
  16. restart: always
  17. order-service:
  18. container_name: order-service
  19. image: registry.hub.docker.com/jirafus400/order-service:latest
  20. environment:
  21. - SPRING_PROFILES_ACTIVE=docker
  22. - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres-order:5431/order_service
  23. depends_on:
  24. - postgres-order
  25. - broker
  26. - eureka-server
  27. - api-gateway

application-docker.properties file

  1. spring.datasource.url=jdbc:postgresql://postgres-order:5431/order_service
  2. spring.datasource.username=postgres
  3. spring.datasource.password=password
  4. spring.datasource.driver-class-name=org.postgresql.Driver
  5. server.port=8080
  6. eureka.client.serviceUrl.defaultZone=http://eureka:password@eureka-server:8761/eureka
  7. 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:

确定