PostgreSQL 默认超级用户不存在。

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

Postgres default superuser doesn't exist

问题

所以,我一直在尝试通过进入 Docker 镜像的 shell 并输入 psql -U postgres 来访问我的 PostgreSQL 数据库,但它返回了一个错误 psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "postgres" does not exist。以前可以正常工作,但突然间不工作了...
如果有助于更好地理解问题,我可以提供 Docker Compose 文件。

我可能做错了什么?

感谢您的时间。

编辑 1:docker-compose.yml

  1. version: "3"
  2. services:
  3. app:
  4. build: .
  5. ports:
  6. - "80:80"
  7. networks:
  8. - app-net
  9. depends_on:
  10. db:
  11. condition: service_healthy
  12. db:
  13. image: "postgres:14"
  14. hostname: "postgres"
  15. user: "postgres"
  16. container_name: postgres
  17. environment:
  18. POSTGRES_DB: dei_acolhimento_v1
  19. POSTGRES_USER: dei_acolhimento_root
  20. POSTGRES_PASSWORD: 6h7jf8kg3d
  21. PGPASSWORD: 6h7jf8kg3d
  22. healthcheck:
  23. test: ["CMD-SHELL", "pg_isready"]
  24. interval: 30s
  25. timeout: 5s
  26. retries: 5
  27. ports:
  28. - "5432:5432"
  29. volumes:
  30. - pgdata:/var/lib/postgresql/data
  31. - ./init-database.sh:/docker-entrypoint-initdb.d/init-database.sh
  32. networks:
  33. - app-net
  34. volumes:
  35. pgdata:
  36. networks:
  37. app-net:
英文:

so I've been trying to enter my Postgres database in a Docker image by going to the image's shell and typing psql -U postgres but it returns an error psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "postgres" does not exist. It used to work, and out of nowhere it stopped working...
I'm free to provide the docker-compose file if it helps you better understand the problem.

What could I have done wrong?

Thanks alot for your time.

Edit 1: docker-compose.yml

  1. version: "3"
  2. services:
  3. app:
  4. build: .
  5. ports:
  6. - "80:80"
  7. networks:
  8. - app-net
  9. depends_on:
  10. db:
  11. condition: service_healthy
  12. db:
  13. image: "postgres:14"
  14. hostname: "postgres"
  15. user: "postgres"
  16. container_name: postgres
  17. environment:
  18. POSTGRES_DB: dei_acolhimento_v1
  19. POSTGRES_USER: dei_acolhimento_root
  20. POSTGRES_PASSWORD: 6h7jf8kg3d
  21. PGPASSWORD: 6h7jf8kg3d
  22. healthcheck:
  23. test: ["CMD-SHELL", "pg_isready"]
  24. interval: 30s
  25. timeout: 5s
  26. retries: 5
  27. ports:
  28. - "5432:5432"
  29. volumes:
  30. - pgdata:/var/lib/postgresql/data
  31. - ./init-database.sh:/docker-entrypoint-initdb.d/init-database.sh
  32. networks:
  33. - app-net
  34. volumes:
  35. pgdata:
  36. networks:
  37. app-net:

答案1

得分: 1

您的设置设置了POSTGRES_USER环境变量,因此不使用默认的postgres用户,而是在您的情况下使用dei_acolhimento_root用户。请参阅文档以扩展/修改Postgres Docker容器。

请注意,数据库的名称与用户的名称再次不同,因为POSTGRES_DB被设置为dei_acolhimento_v1

英文:

Your setup sets the POSTGRES_USER environment variable and therefore does not use the default postgres user but in your case dei_acolhimento_root. See the documentation for extending/modifying the Postgres docker container.

Note that the name of the database again differs from the name of the user because POSTGRES_DB is set to dei_acolhimento_v1.

huangapple
  • 本文由 发表于 2023年7月11日 05:27:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76657448.html
匿名

发表评论

匿名网友

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

确定