PostgreSQL 12.0 Git Bash on windows struggling with createDB

Viewed 2892

I've installed postgresql onto my pc and am trying to use the "createdb" function through git bash. I was just curious why it is asking me for a password for what i'm intending to be the name of the database i'm trying to create. I can confirm that I've started and restarted postgresql working locally on my PC.

My command:

$ psql createdb foo
Password for user foo: <(not really sure what to put here)>

Error:

psql: error: could not connect to server: FATAL:  password authentication failed for user "foo"
1 Answers

createdb is a command line program just like psql. And the first parameter passed to is, is assumed to be the name of the new database. As all Postgres command line clients assume the current operating system user as the database user, it's better to pass the superuser explicitly to the command line programs. So to create a database named foo, use:

createdb -U postgres foo

Or from inside psql use the SQL command CREATE DATABASE

psql -U postgres -d template1
template1=# create database foo;
Related