Skip to content

How am I supposed to install PostgreSQL server on my Windows 7 without a mental breakdown

01/09/2010

Yesterday I thought that installing PostgreSQL server on Windows 7 is like taking a candy from a baby, but… now I’m sure that it isn’t. Until today postgresql server installation on windows was a two step process:

1 step -> downloading the installer from postgresql.org

2 step -> running the installer and clicking “next” button a few times

Today it got more complicated. The simple solution mentioned above won’t work on Windows 7 (at least not for me). Everything will look OK until you try to actually START the server.

So if you got an error …

The service name is invalid.
More help is available by typing NET HELPMSG 2185.
The start command returned an error (2)
Press <return> to continue…

… then read on, because you’ll find a solution to your problem. The problem occured in version 8.4.2.1 and I don’t even want to check other versions, so please forgive me.

Let’s look at the whole installation process:

1) The first step (after downloading the installer of course) is quite easy – we need to double-click the exe file… oh my! Here’s the picture:

2)  If everything went right then we get the installer welcome window. Everything looks just the same as in the earlier versions of PostgreSQL.

3) The next steps are quite standard:

– setting a password for “postgres” user (you just know it’s going to be “qwerty” don’t you? ;))

– selecting the port for sql server

– selecting a locale

4) Ok… now we’re ready to click the final “NEXT” button and watch the pretty green progress bar moving (growing?) from left to right. That was just soooooo easy, wasn’t it? Well it should, but not this time… because at the end of the whole installation process a strange looking message box appears before our very eyes. It says something like:

“blah blah blah… Warning… Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed”.

Here’s the screenshot:

“But it’s only a Warning” – you may think – “who cares about Warnings, we only care about catastrophic errors ;)”. I thought just the same and the installer reassured me that everything else was fine and the installation was a complete success. You’ll find a proof below:

5) Running the server…

I was so happy that the installation is finally over and I can start my PostgreSQL server. I’ve opened the PostgreSQL folder and double-clicked the “Start Server” icon.

After a few hundreds of miliseconds I was kicked in the face with the following error:

“The service name is invalid” didn’t say much, but the second line looked promising “More help is available by typing NET HELPMSG 2185”. So I used the NET HELPMSG command and got an “unbelievably detailed description” of the problem. Just look at this:

So much for the details 🙂

I’ve decided to browse the Windows Services list (Administrative Tools) and I haven’t found anything with the name “postgresql”. It almost looked like the Warning at the end of the installation process was in fact an ERROR! I was completely shocked but I was still able to hold on and think 🙂

Fortunately the PostgreSQL installer creates a log file (install-postgresql.log) in user’s TEMP directory. At the end of that file I’ve found some interesting info:

Unpacking C:\Program Files (x86)\PostgreSQL\8.4\symbols\zic.pdb
[18:20:49] Running the post-installation/upgrade actions:[18:20:49] Delete the temporary scripts directory…
[18:20:49] Write the base directory to the ini file…
[18:20:49] Write the version number to the ini file…Initialising the database cluster (this may take a few minutes)…
Executing cscript //NoLogo “C:\Program Files (x86)\PostgreSQL\8.4/installer/server/initcluster.vbs” “postgres” “postgres” “here is your password if you forget it” “C:\Program Files (x86)\PostgreSQL\8.4” “C:\Program Files (x86)\PostgreSQL\8.4\data” 5432 “English, United States”
Script exit code: 1
Script output:

Ensuring we can write to the data directory (using icacls):
processed file: C:\Program Files (x86)\PostgreSQL\8.4\data
Successfully processed 1 files; Failed processing 0 files

The database cluster will be initialized with locale English, United States.
initdb: could not find suitable text search configuration for locale English, United States
The default text search configuration will be set to “simple”.

fixing permissions on existing directory C:/Program Files (x86)/PostgreSQL/8.4/data … initdb: could not change permissions of directory “C:/Program Files (x86)/PostgreSQL/8.4/data”: Permission denied

Failed to initialise the database cluster with initdb

Script stderr:
Program ended with an error exit code

The installer wasn’t able to change directory permissions despite the fact that UAC has asked if I want to allow the installer to modify my system settings. Am I the only one who thinks that is quite weird? An installer started with administrative rights cannot change a directory permissions? It turns out that Windows 7 is very secure 🙂

As a nice person I decided to help the poor installer in its quest. I opened the PostgreSQL directory “c:\Program Files (x86)\PostgreSQL\8.4\” and manually set the permissions for the “data” subdirectory. If there is no such subdirectory just create it and set the permissions for Users group to “Full control”. After that you need to uninstall PostgreSQL and install it again. There should be no WARNING 😉 this time and the server should work fine.

… more to come…

Advertisements

From → postgres, windows 7

26 Comments
  1. Agata permalink

    Oh man, can’t wait to read the whole entry. Come on, don’t let us wait 😉

  2. Agata permalink

    Great post!
    Yes, it really saved my day.., well, at least couple of hours 😉

    Looking forward to reading next tips :>

  3. Tom permalink

    Re: the last paragraph of the article:

    I don’t think you need to uninstall. After setting the permission for the data folder, just run in the installer again. That seemed to work for me.

  4. dinna permalink

    i’m had solved my problem. your post realy help me. tQVm 🙂

  5. Fatman permalink

    Thanks! I was almost there with the solution. 😉

    Re: Tom’s reply, I had to uninstall first because the installer thought I wanted to upgrade.

  6. Anonymous permalink

    Thank you so much!!!

  7. Anonymous permalink

    It solved my problem too! Thanks a lot!

  8. Anonymous permalink

    Thanks to you, I can finally go to sleep peacefully! Thanks a lot!!

  9. Anonymous permalink

    Thanks setting the data directory to full control worked for me also, thanks!!!!

  10. Ruben permalink

    Thanks! I hope PostgreSQL’s site pay attention to your post and recomend it to Postgres users that had the same problem as us! I was there and found no explanation or any kind of info that could help me with my problem. Found only questions with no answers, what, for me, is a shame.
    GREAT POST!

  11. Liaqat ali permalink

    Thanks alot. Really a nice article. It solved my problem

  12. Suraj Kumar permalink

    Thanks a lot.This post helped me a lot to install psql successfully.

  13. Anonymous permalink

    Thank you for this, you have helped a soul in need.

  14. eric permalink

    Thank you!!!!

  15. Anonymous permalink

    THX. This work excellent. 🙂

  16. Anonymous permalink

    Thanks from Annecy, France ! You save from the mental breakdown man !

  17. wow permalink

    Thanks a TON. i have almost spent half a day, before i read your solution. Now the installation is successful

  18. Anonymous permalink

    Thanks a lot man. It worked for me

  19. It worked for me changing permission manually … it was postgres 9.1

  20. Awesome. Thanks

  21. Perfect.
    Save my Day.

  22. Worked great! Thanks

  23. rasisti smrdí permalink

    Man You are the best! This little piece of advice was nowhere to be found on the whole internet. Thanks!

  24. Anonymous permalink

    Youre great my friend. :=)

  25. Daniel permalink

    Another method:

    1) i started the commandline as administrator
    view plaincopy to clipboardprint?
    runas /user:administrator cmd

    2) i specified the path to the passwordfile
    view plaincopy to clipboardprint?
    initdb.exe –pwfile %TEMP%\passwordfile –encoding=UTF-8 -A md5 -U postgres -D C:\Programme\PostgreSQL\8.4\data

    From http://forums.enterprisedb.com/posts/list/1802.page

    When I did this two steps I was able to run the postgre-8.4 service for all the files and folders in DATA folder had been created

  26. and then they say world’s most advanced database after having such a world’s most poor installer file….
    BTW way thanks man for saving couple of hours of many beginners like me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: