psql: FATAL: role “username” does not exist

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
PostgreSQL role does not exist

psql: FATAL: role “username” does not exist

Error
psql: FATAL: role "username" does not exist
Solution
🚨 PostgreSQL Role Does Not Exist – Error Explained

If you are working with PostgreSQL, you might have encountered the error:

psql: FATAL: role "username" does not exist

This error indicates that PostgreSQL is trying to authenticate a user that does not exist in the system catalog of roles. Unlike the password error, this means the user itself is missing from the database.

Why Does This Happen?

The PostgreSQL role does not exist error usually occurs because:

  • The role (user) was never created.

  • The role was dropped accidentally.

  • You are connecting with the wrong username.

  • A script or application is configured with a non-existing role.

How to Fix the Error

1.Check existing roles

Login with a superuser (like postgres):

\du

This lists all existing roles.

2. Create the missing role

If the role is not found, create it:

CREATE ROLE username LOGIN PASSWORD 'your_password';

3 . Grant privileges (if needed)

To give database access:

GRANT CONNECT ON DATABASE dbname TO username;
GRANT USAGE ON SCHEMA public TO username;

4 . Assign role as database owner (optional)

ALTER DATABASE dbname OWNER TO username;

Conclusion

 At Learnomate Technologies, we’re here to support you every step of the way with top-notch training in PostgreSQL DBA and more.

For more detailed insights and tutorials, do check out our YouTube channelwww.youtube.com/@learnomate, where we regularly share practical tips and deep dives into essential database topics. And if you’re serious about mastering PostgreSQL DBA, head over to our website for our full training program: learnomate.org/training/postgresql-training/.

I’d love to connect with you, so don’t forget to follow my LinkedInhttps://www.linkedin.com/in/ankushthavali/. If you’re eager to read more about various technologies, explore our blog page here: https://learnomate.org/blogs/. Happy learning, and remember—tuning and training go hand-in-hand for database success!