2

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>"
5
  • is your username actually <username_placeholder> ? Commented Nov 11, 2021 at 20:25
  • no it's my name - aryan Commented Nov 11, 2021 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 postgresql.org/docs/current/auth-trust.html Commented Nov 11, 2021 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. Commented Nov 11, 2021 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. Commented Nov 12, 2021 at 6:41

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

5 Comments

You could also have used createdb -U postgres dbname.
@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.
Hm. I just read the documentation, so I find it hard to recommend other books... Perhaps packtpub.com/product/mastering-postgresql-13-fourth-edition/…
Thank You for your suggestion, I will look into it.
@LaurenzAlbe pls post as answer. Thank you both for the discussion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.