postgres with docker compose gives FATAL: role “root” does not exist error

If you don’t specify the PGUSER environment variable, then psql will assume you want to use the current OS user as your database user name. In this case, you are using root as your OS user, and you will attempt to log in as root, but that user doesn’t exist in the database.

You’ll need to either call psql -U postgres, or su - Postgres first

See also the postgresql documentation

UPDATE: Someone suggested changing PGUSER to POSTGRES_USER — this is actually incorrect. Postgres looks for PGUSER in the environment, but if you’re using Docker, you’ll tell Docker the correct user by using POSTGRES_USER, which gets assigned to PGUSER — see the entrypoint source code

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)