1

I am a new user of PostgreSQL, and I am learning it so that I can use it with Django, so I am trying to use the createdb command to create a new database, but even though I am entering the correct password for my account, I am getting this error. I reinstalled everything and checked everything I could think of but I was not able to solve this error. So, if I can get some help regarding this issue it would be nice.

Even using the command psql, and submitting the correct password, gives the same error.

I am using Windows 10.

As far as I checked, I needed to enter the password I used while installing PostgreSQL.

By the way, I am using the latest version of PostgreSQL 14.1

The command I used:

createdb testdatabase 

createdb: error: connection to server at "localhost" (::1), port 5432 failed:
FATAL:  password authentication failed for user "<username_placeholder>"
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • is your username actually `` ? – aberkb Nov 11 '21 at 20:25
  • no it's my name - aryan – Aryan Shandilya Nov 11 '21 at 20:31
  • Should you not connect with `postgres` as user and password to the `postgres` database (which is always installed so you have something to connect to)? You need to provide a bit more info. You can also install postgres using trust authentication, which is fine for local development. No password is needed then https://www.postgresql.org/docs/current/auth-trust.html – Limecat Nov 11 '21 at 22:05
  • @Limecat , do you mean opening pgAdmin 4 and entering the password when I was asked to. If so, I have done that. Though I didn't know about trust authentication. I will try that now and would see what happens. – Aryan Shandilya Nov 11 '21 at 23:19
  • 1
    @aryan-shandilya I didn't realise you used pgAdmin. When Postgres installs, it automatically creates a postgres DB and a user `postgres`. From your own answer below, that's the `-U postgres` when you connect. Anyway, glad you have it working now. – Limecat Nov 12 '21 at 06:41

1 Answers1

5

So, basically, I figured the solution myself. I am just posting it here because mostly answers are available for Linux and not Windows. So, if a windows user has a similar problem, maybe this answer could help them.

So, the first thing is, if you need to open psql, use the command:

psql -U postgres

and then enter the password you used while installing PostgreSQL. Now, if you wish to do something similar to what I tried, what I mean is to use createdb command in the terminal itself, then you will have to create a new user using the same username as you do for your PC, like in my case, it is aryan.

(For example: C:\Users\aryan\).

I followed instructions from this website.

I personally used pgAdmin 4 to do it, you could also use the SQL commands themselves.

After doing everything, when I used the createdb command directly from the terminal/powershell, it asked my the password which I had used to create the other user( with the same username as my system/pc) using pgAdmin 4. That's it. This helped me out.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • 1
    You could also have used `createdb -U postgres dbname`. – Laurenz Albe Nov 12 '21 at 06:45
  • @LaurenzAlbe Thanks for letting me know something like that can also be done. I didn't know that. Also, you seem to be a specialist in PostgreSQL, can you suggest to me some books that can help me go from beginner to a very advanced user of postgres. – Aryan Shandilya Nov 12 '21 at 12:57
  • Hm. I just read the documentation, so I find it hard to recommend other books... Perhaps https://www.packtpub.com/product/mastering-postgresql-13-fourth-edition/9781800567498 – Laurenz Albe Nov 12 '21 at 13:55
  • Thank You for your suggestion, I will look into it. – Aryan Shandilya Nov 12 '21 at 14:27
  • @LaurenzAlbe pls post as answer. Thank you both for the discussion – anhoppe Sep 20 '22 at 13:27