You most probably started the container without the env variables set. The db was then initialized without user or DB info.

You need to delete the volume and try again.

Credit: https://github.com/docker-library/postgres/issues/453#issuecomment-393939412

Answer from howaryoo on Stack Overflow
🌐
GitHub
github.com › docker-library › postgres › issues › 403
FATAL: database does not exist [docker compose] · Issue #403 · docker-library/postgres
January 26, 2018 - version: '2' services: postgres: image: "library/postgres:latest" environment: - POSTGRES_USER=test - POSTGRES_PASSWORD=qwerty - POSTGRES_DB=mydb ... docker run -it -e POSTGRES_USER=test -e POSTGRES_PASSWORD=qwerty -e POSTGRES_DATABSE=mydb postgres docker exec -it <CONTAINER_ID> /bin/bash psql -U test
Author   docker-library
Discussions

Docker does not create the database with the correct name
Hello everyone. I am defining 2 containers, 2 services, with docker composer. One is postgres and the other is pgadmin. The problem is that when I enter the postgrest server credentials in pgadmin, the maintenance database, which I define in the .yml file as “portal”, does not accept the ... More on forums.docker.com
🌐 forums.docker.com
1
0
November 15, 2022
java - postgres database doesn't exist in docker container - Stack Overflow
When I built my app image everything was ok, then I should start my db image and app image. I start db with docker-compose up db and I got: org.postgresql.util.PSQLException: FATAL: database "haircut_studio" does not exist. Is something wrong with my DbConfig? More on stackoverflow.com
🌐 stackoverflow.com
database "postgres" does not exist
I have searched for existing issues search for existing issues, including closed ones. I confirm that I am using English to submit this report (我已阅读并同意 Language Policy). [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) · Please do not modify this template :) and fill in all the required fields. ... docker-db-1 | docker-db-1 | PostgreSQL Database ... More on github.com
🌐 github.com
2
September 9, 2024
spring boot - Database does not exist - Docker/PostgreSQL - Stack Overflow
So I been working around with Springboot and am trying to setup a PostgreSQL database in a docker container. I have the following bash script to create the container: #!/usr/bin/env bash set -euo More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/docker › postgresql in docker: database "admin" does not exist error
r/docker on Reddit: PostgreSQL in docker: database "admin" does not exist error
January 14, 2024 -

Hi,
I'm running the alpine PostgreSQL image in docker using the following docker-compose file below. After building and starting, the container gives the following fatal error message: "FATAL: database "admin" does not exist". After some googling it looks like postgresql needs a database to exist same to the user name that I declared in the docker-compose. Anyone an idea how to solve the error?

version: '3.8'

x-systeminfo: &systeminfo
  # Database
  POSTGRES_ADDRESS: database
  POSTGRES_DB: dev
  POSTGRES_USER: admin
  POSTGRES_PASSWORD: ****************
  POSTGRES_PORT: 5432

services:
  database:
build: ./Database
restart: always
ports:
   - 5432:5432
environment: *systeminfo
volumes:
   - postgresqldata:/var/lib/postgresql/data
healthcheck:
  test: pg_isready -U $$POSTGRES_USER
  interval: 10s
  timeout: 5s
  retries: 20

volumes:
  postgresqldata:

The docker file inside ./Database looks like this:

FROM postgres:alpine
COPY . /docker-entrypoint-initdb.d/
🌐
Docker Community
forums.docker.com › docker engine › compose
Docker does not create the database with the correct name - Compose - Docker Community Forums
November 15, 2022 - Hello everyone. I am defining 2 containers, 2 services, with docker composer. One is postgres and the other is pgadmin. The problem is that when I enter the postgrest server credentials in pgadmin, the maintenance database, which I define in the .yml file as “portal”, does not accept the connection and it does accept it if the maintenance database name is “postgres” as you can see in the following images and if I set in Maintenance database “portal”. it show up that portal database does no...
🌐
GitHub
github.com › langgenius › dify › issues › 8147
database "postgres" does not exist · Issue #8147 · langgenius/dify
September 9, 2024 - docker-db-1 | 2024-09-09 08:39:54.594 UTC [1] LOG: starting PostgreSQL 15.8 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, 64-bit docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv6 address "::", port 5432 docker-db-1 | 2024-09-09 08:39:54.606 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" docker-db-1 | 2024-09-09 08:39:54.721 UTC [37] LOG: database system was shut down at 2024-09-09 08:29:08 UTC docker-db-1 | 2024-09-09 08:39:54.794 UTC [1] LOG: database system is ready to accept connections docker-web-1 | pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)
Author   langgenius
🌐
GitHub
github.com › wallabag › docker › issues › 328
Postgres error database does not exist · Issue #328 · wallabag/docker
April 22, 2023 - I use wallabag in docker. After an recent update the connection to the existing and before used postgresql database can't be established any more. The error message is just "database &quot...
Author   wallabag
Find elsewhere
🌐
DEV Community
dev.to › frio_16 › fixing-fatal-database-does-not-exist-in-postgresql-docker-healthcheck-mistake-3il8
🐳 Fixing “FATAL: database does not exist” in PostgreSQL Docker (Healthcheck Mistake) - DEV Community
February 14, 2026 - services: postgres: image: postgres:16 container_name: train-postgres environment: POSTGRES_DB: train_db POSTGRES_USER: train_user POSTGRES_PASSWORD: train_pass ports: - "5433:5432" volumes: - train_pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U train_user"] interval: 5s timeout: 5s retries: 5 api: build: . container_name: train-api ports: - "8080:8080" depends_on: postgres: condition: service_healthy environment: ConnectionStrings__DefaultConnection: "Host=postgres;Port=5432;Database=train_db;Username=train_user;Password=train_pass" volumes: train_pgdata:
🌐
Stack Overflow
stackoverflow.com › questions › 71059557 › docker-fatal-database-does-not-exist
postgresql - Docker - "FATAL: database does not exist" - Stack Overflow
February 10, 2022 - You're not using an image built from the repository to which you just linked. The official postgres image doesn't support POSTGRES_MULTIPLE_DATABASES so it's not creating any of your databases.
🌐
Medium
medium.com › @chunkang.wong94 › how-to-fix-the-role-postgres-does-not-exist-error-when-deploying-postgresql-docker-container-430e903b97fd
How to Fix the “Role ‘Postgres’ Does Not Exist” Error When Deploying PostgreSQL Docker Container | by ChunKang Wong | Medium
February 27, 2024 - How to Fix the “Role ‘Postgres’ Does Not Exist” Error When Deploying PostgreSQL Docker Container TL; DR: First check port usage on port 5432 using command sudo lsof -i :5432, there should be …
🌐
Docker Community
forums.docker.com › general
PostgreSQL container created with docker compose - databse already exists - General - Docker Community Forums
August 4, 2024 - Hi, One of my containers defined in docker-compose.yml file is PostgreSQL database. I am trying to initialize it with .sql script mounted on /docker-entrypoint-initdb.d/. Docker-compose works fine, but PostgreSQL logs s…
🌐
GitHub
github.com › docker-library › postgres › issues › 537
User and database not created with docker-compose · Issue #537 · docker-library/postgres
December 17, 2018 - The docs explain that you can make the image create a user and database on creation, using environment variables. I can't seem to make that work using docker-compose: # docker-compose.yml services: postgresql: image: postgres:alpine environment: POSTGRES_DB: iotplatform POSTGRES_USER: iotplatform POSTGRES_PASSWORD: iotplatform ... docker-compose up -d --force-recreate postgresql docker-compose exec postgresql psql -U iotplatform # psql: FATAL: role "iotplatform" does not exist
Author   docker-library
🌐
Stack Overflow
stackoverflow.com › questions › 79565657 › the-postgresql-container-is-running-fine-with-no-errors-but-the-app-still-throw
java - The PostgreSQL container is running fine with no errors, but the app still throws a “database does not exist” error - Stack Overflow
can you check if the database name is matching with springboot db name. docker exec -it postgres psql -U postgres -c '\l' ... Save this answer. ... Show activity on this post. I think the DB is connected properly, and the error seems to be caused ...
Top answer
1 of 5
156

The problem was simple enough that my computer was already running an instance of Postgres that I was not aware was still running (not inside Docker) on :5432, checked with:

$ lsof -n -i:5432 | grep LISTEN

So I remembered I installed it via https://gist.github.com/sgnl/609557ebacd3378f3b72, I ran

$ pg-stop

And then I had no problem connecting to the Docker instance.

Edit (2019/07/02)

This question recently passed 10,000 views, so I thought I should elaborate more on why this happened.

Usually running through docker, using python and connecting to a postgres database requires you to install psycopg2, via pip3 install psycopg2, but if you run this command you will get:

Error: pg_config executable not found.

This is because psycopg2 requires an operating system install of the postgres libraries:

yum install postgresql-devel
apt-get install postgresql-client

Now, on a Mac, you will need to do the same with brew:

brew install postgresql

One thing that I didn't realise, is that on Mac, doing the above will not only install required libraries, but also start a database on :5432. Because this was all done in the background, it didn't occur to me that this was the problem as none of the usual errors popped up to inform that the port was being used, etc...

2 of 5
36

In my case, the problem may be due also to the use of a super user who is not postgres. Lhe developers chose the user georchestra in the geOrchestra docker composition. Extract from the dockerfile:

environment:
  - POSTGRES_USER=georchestra

HEALTHCHECK --interval=30s --timeout=30s \
  CMD pg_isready -U $POSTGRES_USER

consequently, you will have to use the option "-U georchestra" to connect to the container.

$ docker exec -it docker_database_1 psql -U georchestra
psql (10.5 (Debian 10.5-1.pgdg90+1))
Type "help" for help.

and of course, trying to connect with the user postgres causes an error:

docker exec -it docker_database_1 psql -U postgres
psql: FATAL:  role "postgres" does not exist
🌐
Connect
connect.hyland.com › t5 › alfresco-forum › fatal-database-quot-alfresco-quot-does-not-exist › td-p › 139738
FATAL: database "alfresco" does not exist - Hyland Connect - 139738
March 22, 2022 - I attached an image of the error in question, there are times when instead of saying "FATAL: database "alfresco" does not exist" it says "FATAL: database "activiti" does not exist". I emphasize that I am doing the "run.bat build_start" of the main repository of the project in which other people are working and everything works correctly, but neither those people nor the team leader know why this happens to me. Just in case, the Postgres part of the "docker-compose.yml" file is as follows:
🌐
GitHub
github.com › docker-library › postgres › issues › 756
with docker-compose.yml "Root or postgres or any role does not exist", postgres, postgrest, swagger connect to db · Issue #756 · docker-library/postgres
August 26, 2020 - version: '3.5' services: server: image: postgrest/postgrest ports: - "3000:3000" links: - db:db environment: PGRST_DB_URI: postgres://app_user:password@db:5432/app_db PGRST_DB_SCHEMA: public PGRST_DB_ANON_ROLE: app_user #In production this role should not be the same as the one used for the connection PGRST_SERVER_PROXY_URI: "http://127.0.0.1:3000" depends_on: - db container_name: server db: image: postgres ports: - "5432:5432" environment: POSTGRES_DB: app_db POSTGRES_USER: app_user POSTGRES_PASSWORD: password # Uncomment this if you want to persist the data.
Author   docker-library