英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论