psql: FATAL: role '...' does not exist
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\duIf the role is missing, proceed to create it.
2. Create a role interactively
sudo -u postgres createuser --interactiveYou 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 peer5. Grant database access
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO myuser;FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro