Today I ran into another strange issue with PostgreSQL installation on Windows. It turned out not to be a problem with the installer; instead it was a form of broken Windows installation that I hadn’t seen before, so I thought I’d write it up.
The installer already contains checks for several kinds of broken Windows install. For example, it tests to make sure that
%TEMP% is writeable, and to makes sure the vbscript interpreter actually works. These were both the cause of frequent problem reports to the mailing lists in the past.
This is a less common issue, though it’s clearly turned up in the wild before, as shown by this report and this one. It turns out that some – probably rare – Windows installs have an incorrect
%COMSPEC% environment variable. This causes
popen to fail with the wonderfully useful error message:
"No error" when
initdb tries to execute the PostgreSQL backend. The message displayed to the user is:
Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed.
… which can be caused by several different issues, of which this is only one.
If this is your issue, when you examine the installer log file,
%TEMP%\postgresql-installer.log, you’ll find that it contains:
Executing cscript //NoLogo "C:\Program Files\PostgreSQL\9.2/installer/server/initcluster.vbs" "NT AUTHORITY\NetworkService" "postgres" "****" "C:\Program Files\PostgreSQL\9.2" "C:\Program Files\PostgreSQL\9.2\data" 5432 "DEFAULT" Script exit code: 1
then a bit further down in the log you’ll see:
creating template1 database in C:/Program Files/PostgreSQL/9.2/data/base/1 ... initdb: could not execute command ""C:/Program Files/PostgreSQL/9.2/bin/postgres.exe" --boot -x1 -F ": No error
If so, check to make sure your
ComSpec environment variable is valid. Open a command prompt and run:
"%COMSPEC%" /C "echo test ok"
If it prints “test ok” then it’s likely fine and the issue is probably something else. If it fails, you’ve found the problem. Either way, check the value with:
It should print something like:
C:\Windows is the location of your Windows install as shown by
echo %WINDIR% or
In the case of the issue I was investigating it was instead:
It’s valid, though not standard, to have
%SYSTEMROOT% instead of
C:\Windows, so that wasn’t the issue. The problem is the trailing semicolon (‘;’). This single extra character was causing
initdb to fail to launch
postgres.exe during database cluster creation because the
popen(...) call was failing. The
popen call requires that
ComSpec point to a valid shell.
The error was fixed by correcting the
COMSPEC environment variable. We opened the System control panel, opened Advanced system settings, and in the Environment Variables section under System variables edited
ComSpec to remove the trailing semicolon.