PostgreSQL vs. Windows 2003 Server

Working with Postgres is always fun — it has soul.

I had to fix recently a broken PostgreSQL install on a Windows 2003 Server. I don’t really know how it was installed, but I was told that according the Postges forums, it has know issues:

The install fails with ‘error reading file %path%\postgresql.conf’. It doesn’t write to anything in the postgresql data directory or create the postgresql service. We have made postgres user Administrator, explicitly given it full control permissions to temp directories, ownership to the install directory, installed when logging on as the postgres user. We last tried to create the service manually, and even that fails: service is created but will not run.

When I logged in to the system the first suspicious things was that we had two data directories [Drive:]\PostgreSQL\8.4\data and [Drive:]\PostgreSQL\data — of course one of them wasn’t necessary.

The solution was:

  1. update D:\PostgreSQL\8.4\pg_env.bat with the right data directory (I coosed [Drive:]\PostgreSQL\data, didn’t know what was the default)
  2. update D:\PostgreSQL\8.4\scripts\serverctl.vbs with the right data directory
  3. register the Windows service: [Drive:]\PostgreSQL\8.4\bin>pg_ctl.exe register -N postgresql-8.4 -D [Drive:]\PostgreSQL\data
  4. finally I had to re-init the DB as well: [Drive:]\PostgreSQL\8.4\bin>initdb.exe -D d:\PostgreSQL\data

That’s all folks!

Image credits