HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMinor

postgresql Cannot login with created users

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlcannotwithcreatedloginusers

Problem

I am very new to postgreSQL, but quite familiar with SQL.

I have recently installed postgreSQL on Windows 10. I ran through the startup tutorials and made a few DBs to mess around with. I can login just fine with the postgres account with the command

psql -U postgres -d DatabaseName


However, I have thus far been unable to create a new user to log in with.

I tried the command

CREATE USER myUser WITH SUPERUSER PASSWORD 'password';


When I do this, it creates the user. I can see this with the \du command:

Role name  |   List of Attributes                      | Member of
postgres   | Superuser, Create Role, Create DB, yada...| {}
myuser     | Superuser                                 | {}


I then try \q and logging in with my new user and get the following:

psql -U myUser -d Database
Password for myUser: password
psql: FATAL: password authentication failed for "myUser"


I have also tried createuser from cmd, this user showed up in the list of users as well, but I was again unable to login as these users.

Thank you for any help you can offer.

Solution

It's just a case folding problem. You're trying to connect with myUser but due to case folding rules, you created myuser in lowercase, as the \du output shows. Per documentation:


Quoting an identifier also makes it case-sensitive, whereas unquoted
names are always folded to lower case.

To create myUser with this exact case, enclose it in double quotes, as in:

CREATE USER "myUser" WITH SUPERUSER PASSWORD 'password';


Then the invocation psql -U myUser ... will work.

Or alternatively, don't recreate the user but always refer to it in lowercase.

Code Snippets

CREATE USER "myUser" WITH SUPERUSER PASSWORD 'password';

Context

StackExchange Database Administrators Q#146087, answer score: 7

Revisions (0)

No revisions yet.