How to fix FATAL: role "postgres" does not exist in PostgreSQL
Postgres can't find the named role/user. Fix: create it with CREATE ROLE/createuser, or connect as an existing superuser role.
Quick fix
Fixes FATAL: role "postgres" does not exist
sudo -u postgres psql -c "\\du"- Verify existing roles
- Create the missing role
- For Docker environments, check initialization
- For database migrations and restores
sudo -u postgres psql -c "\\du"FATAL: role "postgres" does not exist
What this error means
PostgreSQL manages access control through roles, which are database entities that can own objects and have privileges. When you try to connect to the database or reference a role in a query, PostgreSQL looks up that role in its system catalog. If the role doesn't exist, you get this error. This is different from a password error—the role itself is missing, not just the credentials.
Typical symptoms
- Connection attempts fail with 'FATAL: role X does not exist'
- Database initialization or migration scripts fail when trying to use a specific role
- Docker PostgreSQL containers fail to start with role errors
- After fresh PostgreSQL installation, the default postgres superuser cannot be accessed
- Connections work for some roles but not others
Common causes
- The role was never created during database initialization
- The role was dropped using DROP ROLE without creating a replacement
- During PostgreSQL installation, a different OS username was used, so the postgres role was created under that username instead
- Database migrations or dumps reference roles that don't exist on the target system
- Typo or case sensitivity issue in the role name (postgres vs postgres vs 'Postgres')
- Restoring a database backup without first creating the required roles on the new system
How to fix "FATAL: role "postgres" does not exist"
First, check what roles currently exist in your PostgreSQL installation. Connect as a superuser and list all roles:
sudo -u postgres psql -c "\\du"Or using SQL:
SELECT rolname FROM pg_roles ORDER BY rolname;This shows all roles and their attributes. If the postgres role is missing, you'll need to create it.
If the role doesn't exist, create it using the createuser utility (recommended) or SQL.
Using createuser (from your system terminal):
sudo -u postgres createuser -s postgresThe -s flag makes it a superuser. If you need a password:
sudo -u postgres createuser -s -P postgresUsing SQL (if already connected as a superuser):
CREATE ROLE postgres WITH SUPERUSER CREATEDB CREATEROLE LOGIN;Or with a password:
CREATE ROLE postgres WITH SUPERUSER CREATEDB CREATEROLE LOGIN PASSWORD 'your_password';If you're using PostgreSQL in Docker, the postgres role should be created automatically. If it's missing:
1. Ensure you're not connecting to a local PostgreSQL installation instead of the container:
docker ps | grep postgres2. Check if the container is running and initialized:
docker logs <container_name>3. If the container postgres is correct but the role is missing, exec into it and create the role:
docker exec -u postgres <container_name> createuser -s postgresWhen moving a database between systems, roles don't migrate automatically. Before restoring a dump:
1. Create all required roles on the destination system first
2. Or, dump without role ownership information:
pg_dump --no-owner --no-acl source_db > dump.sql3. Then restore:
psql -U postgres -d target_db -f dump.sqlAlternatively, edit the dump file to replace role references with existing roles before restoring.
Once created, test that the role works:
# Using peer authentication (OS username matches role name)
sudo -u postgres psql
# Using password authentication (if password is set)
psql -U postgres -h localhost -WBoth should connect successfully without the 'role does not exist' error.
Advanced notes
Case Sensitivity: PostgreSQL role names are case-insensitive by default. However, if you quote the role name when creating it (e.g., CREATE ROLE "MyRole"), it becomes case-sensitive. Always reference it with the exact same quoting.
Peer vs Password Authentication: PostgreSQL defaults to peer authentication on local connections, which requires the OS username to match the PostgreSQL role name exactly. Remote connections typically use password authentication. If your OS username is 'john' but you try to create only a 'postgres' role, peer auth will fail.
Superuser Roles: The postgres superuser role is special—it can create other roles and databases. If it's missing, you may need to reinitialize your PostgreSQL cluster using initdb with appropriate flags.
CREATEUSER Shorthand: createuser username is equivalent to CREATE ROLE username WITH LOGIN. Use createuser -s username to make a superuser.
Frequently asked questions
- What does "FATAL: role "postgres" does not exist" mean?
- PostgreSQL manages access control through roles, which are database entities that can own objects and have privileges. When you try to connect to the database or reference a role in a query, PostgreSQL looks up that role in its system catalog. If the role doesn't exist, you get this error.
- How do I fix "FATAL: role "postgres" does not exist"?
- Postgres can't find the named role/user. Fix: create it with CREATE ROLE/createuser, or connect as an existing superuser role.
- What causes "FATAL: role "postgres" does not exist"?
- The role was never created during database initialization The role was dropped using DROP ROLE without creating a replacement During PostgreSQL installation, a different OS username was used, so the postgres role was created under that username instead
- Is the "FATAL: role "postgres" does not exist" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.