PostgreSQL error: role does not exist

FATAL:  role "ubuntu" does not exist

The user name the connection presented has no matching role on this cluster. Like its twin (database does not exist), this is usually a defaulting surprise: run psql without -U and it presents your operating-system username, which on a fresh install matches no role.

What this error means

Roles (users and groups are the same thing in PostgreSQL) live at the cluster level, shared by all databases on that server. A fresh installation has essentially one login role: postgres, the superuser. Nothing named after your OS account exists until someone creates it.

On Linux packages, local connections as the postgres OS user typically use peer authentication — the OS identity is the credential. That's why sudo -u postgres psql is the standard bootstrap path.

Common causes

How to diagnose it

# Entra come superuser locale (peer auth) e guarda i ruoli reali:
sudo -u postgres psql -c '\du'

If you can't get in that way, whoever administers the instance can run SELECT rolname FROM pg_roles;. Then compare against the exact name (and case) in the error message — and double-check you're on the cluster you meant.

How to fix it

-- Il ruolo applicativo tipico:
CREATE ROLE app_user LOGIN PASSWORD '...';

-- Oppure, per lavorare comodo in locale: un ruolo col tuo nome OS
CREATE ROLE gianluca LOGIN SUPERUSER;  -- solo su macchine di sviluppo
🔍 The twin error: database does not exist — the same surprise on the database-name side.