英文:
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
version: "3"
services:
app:
build: .
ports:
- "80:80"
networks:
- app-net
depends_on:
db:
condition: service_healthy
db:
image: "postgres:14"
hostname: "postgres"
user: "postgres"
container_name: postgres
environment:
POSTGRES_DB: dei_acolhimento_v1
POSTGRES_USER: dei_acolhimento_root
POSTGRES_PASSWORD: 6h7jf8kg3d
PGPASSWORD: 6h7jf8kg3d
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 30s
timeout: 5s
retries: 5
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./init-database.sh:/docker-entrypoint-initdb.d/init-database.sh
networks:
- app-net
volumes:
pgdata:
networks:
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
version: "3"
services:
app:
build: .
ports:
- "80:80"
networks:
- app-net
depends_on:
db:
condition: service_healthy
db:
image: "postgres:14"
hostname: "postgres"
user: "postgres"
container_name: postgres
environment:
POSTGRES_DB: dei_acolhimento_v1
POSTGRES_USER: dei_acolhimento_root
POSTGRES_PASSWORD: 6h7jf8kg3d
PGPASSWORD: 6h7jf8kg3d
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 30s
timeout: 5s
retries: 5
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./init-database.sh:/docker-entrypoint-initdb.d/init-database.sh
networks:
- app-net
volumes:
pgdata:
networks:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论