psql: error: FATAL: role is not permitted to log in

I have received following error when trying to connect to PostgreSQL server.

psql: error: FATAL: role is not permitted to log in

psql error FATAL role is not permitted to log in

Reason:
The role I have created is not allowed to log in. We have to give the role permission to log in.One way to do this is to log in as the postgres(or other superuser) user and update the role.

Solution:

1. Connect to PostgreSQL with postgres or any other user who is having superuser permission.

sudo su - postgres psql -U postgres

2. Now, verify the role(user) is granted to login or not by running below query.

\du mike

Which means role is not granted to login to PostgreSQL. Solution is, we have to alter the role permissions.

3. Alter the role permissions.

alter role mike login;

4. Now, try to login to the PostgreSQL.

r2schools@PGMaster:~$ psql -U mike -d train Password for user mike: psql (12.6 (Ubuntu 12.6-1.pgdg20.04+1)) Type "help" for help. train=> select current_role; current_role -------------- mike (1 row)

So, Issue is fixed by changing permissions of user.