How to fix FATAL: role "postgres" does not exist in PostgreSQL

PostgreSQLINTERMEDIATEHIGHUpdated May 28, 2026· 377 views

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"
  1. Verify existing roles
  2. Create the missing role
  3. For Docker environments, check initialization
  4. For database migrations and restores
postgresql — error
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

  1. The role was never created during database initialization
  2. The role was dropped using DROP ROLE without creating a replacement
  3. During PostgreSQL installation, a different OS username was used, so the postgres role was created under that username instead
  4. Database migrations or dumps reference roles that don't exist on the target system
  5. Typo or case sensitivity issue in the role name (postgres vs postgres vs 'Postgres')
  6. Restoring a database backup without first creating the required roles on the new system

How to fix "FATAL: role "postgres" does not exist"

1Verify existing roles

First, check what roles currently exist in your PostgreSQL installation. Connect as a superuser and list all roles:

bash
sudo -u postgres psql -c "\\du"

Or using SQL:

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.

2Create the missing role

If the role doesn't exist, create it using the createuser utility (recommended) or SQL.

Using createuser (from your system terminal):

bash
sudo -u postgres createuser -s postgres

The -s flag makes it a superuser. If you need a password:

bash
sudo -u postgres createuser -s -P postgres

Using SQL (if already connected as a superuser):

sql
CREATE ROLE postgres WITH SUPERUSER CREATEDB CREATEROLE LOGIN;

Or with a password:

sql
CREATE ROLE postgres WITH SUPERUSER CREATEDB CREATEROLE LOGIN PASSWORD 'your_password';
3For Docker environments, check initialization

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:

bash
docker ps | grep postgres

2. Check if the container is running and initialized:

bash
docker logs <container_name>

3. If the container postgres is correct but the role is missing, exec into it and create the role:

bash
docker exec -u postgres <container_name> createuser -s postgres
4For database migrations and restores

When 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:

bash
pg_dump --no-owner --no-acl source_db > dump.sql

3. Then restore:

bash
psql -U postgres -d target_db -f dump.sql

Alternatively, edit the dump file to replace role references with existing roles before restoring.

5Verify the role can authenticate

Once created, test that the role works:

bash
# Using peer authentication (OS username matches role name)
sudo -u postgres psql

# Using password authentication (if password is set)
psql -U postgres -h localhost -W

Both 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.

Official resources & further reading