Subject: How to use createdb command with newly created user?

From: 毛毛 <[email-masked]>
Date: Mon, 24 Jun 2024 02:43:06 +0800 (CST)

Hi,

I tried to create a user with CREATEDB permission.
Then I wanted to run command line tool `createdb` with this newly created user.

So I ran SQL first to create a user:

```

CREATE USER Baba WITH PASSWORD 'xxx' CREATEDB;

```

Then I run the following command on PowerShell on Windows 10:

```
 createdb -U Baba -W test_db
```

But no mater how I tried, the password always failed.

If I specify the user as postgres, the defaut user, everything works fine.

```
createdb -U postgres -W test_db_1
```

Do you have any suggestions?

---

From: "David G. Johnston" <[email-masked]>
Date: Sun, 23 Jun 2024 11:47:44 -0700

> Do you have any suggestions?

You named the user "baba" all lower-case but your createdb command uses
Baba and in the OS the case-folding of identifiers does not happen.  Baba
!= baba  is your issue.

David J.

---

From: Tom Lane <[email-masked]>
Date: Sun, 23 Jun 2024 15:00:37 -0400

> Baba and in the OS the case-folding of identifiers does not happen.  Baba

FWIW, I think using -W in interactive commands is a bad habit
that you should drop.  Because it forces a password prompt, it
easily confuses people into thinking that their problem is
password-related whether it actually is or not.

(I notice that with createdb, it actually seems to force *two*
password prompts when there is something wrong.  That's unlike
what happens with psql; maybe we should try to improve that.
But on the other hand, it's hard to get excited about putting
work into improving a behavior that we deprecate using at all.)

			regards, tom lane

---

From: 毛毛 <[email-masked]>
Date: Mon, 24 Jun 2024 03:22:19 +0800 (CST)

Thank you! You are right!

After putting quotes around the username, it works!

在 2024-06-24 02:47:44，"David G. Johnston" <[email-masked]> 写道：

Hi,

```

```

```

```

You named the user "baba" all lower-case but your createdb command uses Baba and in the OS the case-folding of identifiers does not happen.  Baba != baba  is your issue.

David J.

---

From: Ron Johnson <[email-masked]>
Date: Sun, 23 Jun 2024 15:38:21 -0400

Better to run now, and save yourself hassle in the future:
ALTER ROLE "Baba" RENAME TO baba;

Also, use a .pgpass file:
https://www.postgresql.org/docs/14/libpq-pgpass.html