This is my first technical blog post detailing how I successfully troubleshoot the installation of PostgreSQL version 9.1.5 on my Windows Vista last week. Took me over 2 nights to figure out why installing the PostgreSQL pre-built binary package for 32-bit Windows did not work as expected.

Long story short, the main problem I encountered was due to the PostgreSQL installer not automatically setting the Environment Variable Path.

The first step in the PostgreSQL documentation after installation is to create a database using the command “createdb mydb” on the Windows Command Prompt.

I was immediately thrown an error message:

‘createdb’ is not recognized as an internal or external command, operable program or batch file.

The first thing to know the next time such a message appears on the Windows shell is that the program has not been installed properly or the PATH has not been set. I skimmed through the PostgreSQL documentation page and did not read properly the part where its written “createdb: command not found”

This is the part of the guide that is supposed to mean the same thing with the Windows error message and it did say that the path is not set properly.

To solve this on Windows Vista:

1. Click on the Windows Start button
2. Search for System in the Search bar
3. Click on System on the Search result
4. Click on Advanced System Settings on the left column
5. Go to the Advanced tab
6. Click on Environment Variables
7. Look for PATH and then click Edit
8. ¬†Add the following: “C:\Program Files\PostgreSQL\9.1\bin;C:\Program Files\PostgreSQL\9.1\lib” – Change the path to the location for your PostgreSQL installation on Windows and use the semicolon – ; to append the new PostgreSQL PATH to your other installations like Python etc.
9. Click OK and ‘createdb’ should now work on your shell

The next problem comes up when you want to run commands on psql. psql will prompt for a password when you run ‘psql’ on the shell. Since I created a PostgreSQL superuser account during installation, I would expect the password to be my superuser password and typed it in. Instead what I got was this error message:

psql: FATAL: password authentication for user ‘Bobby’

Now this is awkward no matter how many times I tried typing in my password and I’m very sure I typed in the right password. And what is ever weirder is that password authentication failed for username Bobby. I didn’t specify a username Bobby and the default username during installation is postgres.

Searching on Google told me that PostgreSQL uses the Windows user account system and hence it prompted me for the password for my Windows user account ‘Bobby’. But keying in the password for my Windows user account still gave the same error message.

The solution is to add a new environment variable for PGUSER with the value postgres. These are the steps to add PGUSER on Windows Vista:

1. Click on the Windows Start button
2. Search for System in the Search bar
3. Click on System on the Search result
4. Click on Advanced System Settings on the left column
5. Go to the Advanced tab
6. Click on Environment Variables
7. Click New
8. Fill in PGUSER as Variable Name and fill in postgres as Variable Value
9. Click OK and your superuser password should work.

You may need to restart your computer after setting the Environment Variable and Environment Path above for the changes to take effect.

I hope this post will help you install PostgreSQL on your Windows machine.