Showing results for 
Search instead for 
Did you mean: 

Installing PostgreSQL 12 on Windows fails when initialising the database cluster


Installing PostgreSQL 12 on Windows fails when initialising the database cluster

Kia ora, Postgres Rocks community from New Zealand.


I have come across a problem when installing PostgreSQL 12 on one of my Windows machines, using the EnterpriseDB installers available fom here:


The symptom I am seeing is a report that the database cluster initialisation failed:








This seems to be similar to the problem reported elsewhere; for example, here:


The pertinent section of the "bitrock" log file appears to be:


[12:06:01] Running the post-installation/upgrade actions:
[12:06:01] Write the base directory to the ini file...
[12:06:01] Write the version number to the ini file...
Initialising the database cluster (this may take a few minutes)...
Executing cscript //NoLogo "C:\Program Files\PostgreSQL\12/installer/server/initcluster.vbs" "NT AUTHORITY\NetworkService" "postgres" "****" "C:\Temp\PostgreSQLTemp/postgresql_installer_72bcf72533" "C:\Program Files\PostgreSQL\12" "C:\Program Files\PostgreSQL\12\data" 5432 "DEFAULT" 0
Script exit code: 1

Script output:
 WScript.Shell Initialized...
Scripting.FileSystemObject initialized...

Called CreateDirectory(C:\Program Files\PostgreSQL\12\data)...
Called CreateDirectory(C:\Program Files\PostgreSQL\12)...
Called ClearAcl (C:\Program Files\PostgreSQL\12\data)...
    Executing batch file 'rad23BC2.bat'...
Called Die(Failed to reset the ACL (C:\Program Files\PostgreSQL\12\data))...
Failed to reset the ACL (C:\Program Files\PostgreSQL\12\data)

Script stderr:
 Program ended with an error exit code

Error running cscript //NoLogo "C:\Program Files\PostgreSQL\12/installer/server/initcluster.vbs" "NT AUTHORITY\NetworkService" "postgres" "****" "C:\Temp\PostgreSQLTemp/postgresql_installer_72bcf72533" "C:\Program Files\PostgreSQL\12" "C:\Program Files\PostgreSQL\12\data" 5432 "DEFAULT" 0: Program ended with an error exit code
Problem running post-install step. Installation may not complete correctly
 The database cluster initialisation failed.

I have checked the following:

  • permissions on the %TEMP% directory, including temporarily setting this to a "known good" location, such as C:\Temp\PostgreSQLTemp -- no improvement
  • checking the %COMSPEC%, to ensure there is no trailing semicolon -- there isn't
  • tried using a "simpler" password during the setup -- no improvement

I therefore think there are some bugs in the initcluster.vbs file:


Bug 1: Incorrectly quote-delimited path in generated batch file

In the function ClearAcl, at line 148, the quoting of double-quotes is incorrect, which leads to there being incorrectly quote path names in the temporary batch file generated to get the current list of ACLs for the "data" directory. I think this line should actaully read:
iRet = DoCmd("icacls """ & DirectoryPath & """")
This then corrects the generated batch file, so it's content is

CHCP 1252
icacls "C:\Program Files\PostgreSQL\12\data" > "C:\Users\Jon_WCS\AppData\Local\Temp\rad3F730.tmp" 2>&1

However, the installer still fails.


Bug 2: Invoking batch files from within the VBScripts inexplicably fails

In several of the VBScripts that are used to set up and configure PostgreSQL, additional, supporting batch files are generated and executed. However, so some reason which I have not been able to work out, these batch scripts invariably fail (silently) on my laptop. In comparison, these worked perfectly on my desktop machine.


In the following VBScript files, a function named DoCmd is used to execute additional commands, as and when needed:

  • C:\Program Files\PostgreSQL\12\installer\server\initcluster.vbs
  • C:\Program Files\PostgreSQL\12\installer\server\loadmodules.vbs
  • C:\Program Files\PostgreSQL\12\installer\server\startupcfg.vbs

Contained in the DoCmd functions are calls made to the shell object's .Run() method. It is this .Run() method which fails on my laptop:

DoCmd = objShell.Run(objTempFolder.Path & "\" & strBatchFile, 0, True)

The syntax of this line seems to mask the underlying problem on my laptop, and that has left me stumped. 


Solution - rewritten version of DoCmd() function

Rewriting the DoCmd function in each of the three VBScript files above to the following, and replacing these files with edited versions during the "unpacking" phase of the installation finally got things working for me.

' Execute a command
Function DoCmd(strCmd)
    WScript.Echo "Executing command: " & strCmd
    Set objCmd = objShell.Exec(strCmd)

    Do While objCmd.Status = 0 And objCmd.ExitCode 
        WScript.Echo "objCmd.Status = " & objCmd.Status & ", objCmd.ExitCode = " & objCmd.ExitCode
        WScript.Sleep 100
    WScript.Echo "Command returned with exit code " & objCmd.ExitCode & "."
    WScript.Echo objCmd.StdOut.ReadAll & objCmd.StdErr.ReadAll
    ExecuteCommand = objCmd.ExitCode
End Function

Note: I also had to tweak the invocation of psql.exe in the loadmodules.vbs script to the following, so that the password could be passed in explicitly, without needing to rely on an environment variable:

' iRet = DoCmd("""" & strInstallDir & "\bin\psql.exe"" -p " & iPort & " -U " & strUsername & " -c ""CREATE EXTENSION adminpack;"" postgres")
iRet = DoCmd("""" & strInstallDir & "\bin\psql.exe"" postgresql://" & strUsername & ":" & strFormattedPassword & "@localhost:" & iPort & " -c ""CREATE EXTENSION adminpack;"" postgres")

As I mentioned, I have no idea why the invocation of the objShell.Run(...) was silently failing... but at last I've got PostgreSQL installed correctly on my laptop!

Nga mihi,



EDB Team Member

Re: Installing PostgreSQL 12 on Windows fails when initialising the database cluster

Hi JonWCS,


I was trying to replicate your first problem of the database cluster, not initializing. However, I was not able to replicate the issue.

I installed the PostgreSQL-12 on the Windows-10 server and was successfully able to install and start the database cluster.

For more details kindly refer to the below a screenshot of the installation.

Screen Shot 2019-10-31 at 7.52.53 PM.png

Screen Shot 2019-10-31 at 7.57.03 PM.png

Screen Shot 2019-10-31 at 7.58.42 PM.png


For this installation, I have followed the below steps with all default settings.:


Hence, request you to go through these steps and if you still face this issue. Kindly let us know your environmental details and steps to reproduce this issue.