Skip to content
psql: FATAL: role '...' does not exist

psql: FATAL: role '...' does not exist

DodaTech 2 min read

The PostgreSQL error “FATAL: role ‘…’ does not exist” means the login role you specified with -U does not exist in the database cluster. PostgreSQL uses roles for authentication and authorization, and the role must be created before connecting.

What It Means

PostgreSQL could not authenticate the connection because the role name is not registered in the pg_roles system catalog. Unlike MySQL, PostgreSQL does not create a role matching your OS user by default.

Why It Happens

  • The role was never created during setup.
  • You used a typo in the username passed to psql -U.
  • The application connection string specifies a role that does not exist.
  • The role was dropped and needs to be recreated.

How to Fix It

1. List existing roles

Connect as the postgres system user:

sudo -u postgres psql
\du

If the role is missing, proceed to create it.

2. Create a role interactively

sudo -u postgres createuser --interactive

You will be prompted for the role name, superuser status, and database creation permissions.

3. Create a role with SQL

CREATE ROLE myuser WITH LOGIN PASSWORD 'StrongPassword123';

To grant superuser or database creation privileges:

CREATE ROLE myuser WITH LOGIN SUPERUSER CREATEDB PASSWORD 'StrongPassword123';

4. Create a role that matches your OS user

If you want passwordless login via Unix socket:

CREATE ROLE your_os_username WITH LOGIN;

Then adjust pg_hba.conf for peer authentication:

local   all             your_os_username                peer

5. Grant database access

GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO myuser;

FAQ

Can I connect to PostgreSQL without specifying a role?
Yes, psql defaults to your current OS username. If no role exists for that username, you get the FATAL error. Create a matching role or use psql -U postgres to connect as the admin role.
How do I delete a role in PostgreSQL?
Use DROP ROLE myuser; in the PostgreSQL shell, or sudo -u postgres dropuser myuser from the command line. You must first drop all owned objects or reassign them.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro