Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I just installed Postgresql on my Windows laptop. I am now trying to create my first database. I launched the Windows PowerShell and tried the following:

PS C:\Users\Chris\Documents\test> & 'C:\Program Files\PostgreSQL\9.2\bin\createdb.exe' mydb
Password:
Password:
createdb: could not connect to database template1: FATAL:  password authentication failed for user "Chris"

From what I can gather, the password that you give PostgreSQL during installation is for a different user type? After some poking around on the internet, I modified my pg_hba.conf file by appending the following:

local   all all trust

Now I get the following error message:

PS C:\Users\Chris\Documents\test> & 'C:\Program Files\PostgreSQL\9.2\bin\createdb.exe' mydb
createdb: could not connect to database template1: FATAL:  could not load pg_hba.conf

Not sure what I am doing wrong. Any suggestions?


Well, this is interesting. I went back to the pg_hab.conf file and added a newline after that line of code I added earlier. I got a new error message:

PS C:\Users\Chris\Documents\test> & 'C:\Program Files\PostgreSQL\9.2\bin\createdb.exe' mydb
createdb: could not connect to database template1: could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

When I installed postgreSQL on my laptop, I set the port to 5432. Looks like postgreSQL is expecting the server to be running. Going to look into this...

share

migration rejected from stackoverflow.com Sep 12 '13 at 7:42

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by dezso, bluefeet, Paul White, Michael - sqlbot, Marian Sep 12 '13 at 7:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – dezso, bluefeet, Paul White, Michael - sqlbot, Marian
If this question can be reworded to fit the rules in the help center, please edit the question.

    
You should check the postgresql error log since the source of your error is not clear: it may be that you created/changed the pg_hba.conf file with a different user and now the server cannot eve access it; or it may be in a wrong format (like: did you insert a new line after the text you typed into it?) –  eppesuig Jun 20 '13 at 8:51

3 Answers 3

The Postgres commandline tools assume you want to connect to the server using the same username as your OS (Windows) user. But to create a database you need to connect as a superuser (typically postgres) and not with your current windows user.

If you use:

createdb.exe -U postgres mydb

then you connect as the database user postgres and you will be prompted for that user's password.

share

The problem here seems to be that you are trying to execute with the wrong permissions. As joze mentioned, the user might not exist in the database.

However, this is not the immediate problem. The problem you face after having updating the pg_hba.conf file is changed user permissions.

I am not sure how this works in Windows, but you should check that the file is owned and readable by the postgres user (or the user that is being used to start the database)

After that you should append -U postgres (or the username of the user that you created during installation) to the createdb command

share

Looks like I finally have success. After appending the line of text to the pg_hba.conf file, I needed to create a database cluster and then start the server.

PS C:\Users\Chris\Documents\test> & 'C:\Program Files\PostgreSQL\9.2\bin\pg_ctl.exe' initdb
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
PS C:\Users\Chris\Documents\test> & 'C:\Program Files\PostgreSQL\9.2\bin\pg_ctl.exe' -D 'C:\Users\Chris\Documents\postgresql' initdb

I thought it was odd that I had to give pg_ctl a path even though the PGDATA variable can be found in C:\Program Files\PostgreSQL\9.2\pg_env.bat. Oh well.

PS C:\Users\Chris\Documents\test> & 'C:\Program Files\PostgreSQL\9.2\bin\pg_ctl.exe' -D "C:\Users\Chris\Documents\postgresql" -l logfile start
server starting
PS C:\Users\Chris\Documents\test> & 'C:\Program Files\PostgreSQL\9.2\bin\createdb.exe' mydb
PS C:\Users\Chris\Documents\test> dir


Directory: C:\Users\Chris\Documents\test


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         6/20/2013  11:42 AM        151 logfile

My only other comment is that I expected postgreSQL to create an actual file in my 'test' directory like SQLite does. Thanks for everyone's help!

share

Not the answer you're looking for? Browse other questions tagged or ask your own question.