Posting this because no other posted solutions on this forum worked for me. Might help some others
Relevent specs:
- Win 7 Pro x64 SP1, Avira Antivir, Windows Firewall
Problem:
- Cannot install PostgreSQL via HM2 bundle
Code:
Connection to DB failed: --> could not connect to server: Connection refused "
- Cannot install PostgreSQL 8.3/8.4/9.0/9.1 via official website:
Code:
Ensuring we can write to the data directory (using icacls) to w0ng:
Executing batch file 'rad612AE.bat'...
processed file: C:\PostgreSQL\data
Successfully processed 1 files; Failed processing 0 files
Failed to ensure the data directory is accessible (C:\PostgreSQL\data)
Executing batch file 'rad612AE.bat'...
The files belonging to this database system will be owned by user "w0ng".
This user must also own the server process.
The database cluster will be initialized with locale English_Australia.1252.
The default text search configuration will be set to "english".
fixing permissions on existing directory C:/PostgreSQL/data ... ok
creating subdirectories ... ok
selecting default max_connections ... The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
10
selecting default shared_buffers ... The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
400kB
creating configuration files ... ok
creating template1 database in C:/PostgreSQL/data/base/1 ... The system cannot find the path specified.
child process exited with exit code 1
initdb: removing contents of data directory "C:/PostgreSQL/data"
Called Die(Failed to initialise the database cluster with initdb)...
Failed to initialise the database cluster with initdb
Script stderr:
Program ended with an error exit code
Error running cscript //NoLogo "C:\PostgreSQL/installer/server/initcluster.vbs" "postgres" "postgres" "****" "C:\PostgreSQL" "C:\PostgreSQL\data" 5432 "DEFAULT" : Program ended with an error exit code
Problem running post-install step. Installation may not complete correctly
The database cluster initialisation failed.
Troubleshooting:
- Run install as admin -> same problem
- Disable AV + Firewall + Windows Defender -> same problem
- Edit C:\Windows\System32\drivers\etc\hosts -> reboot -> same problem
- Uninstalled AV -> same problem
- Disabled UAC -> same problem
- services.msc -> restart Secondary Logon Service -> same problem
- Installed to c:\postgresql and c:\pgdata for data directory -> same problem
- create folder C:\pgdata -> Properties -> Security -> Edit... -> Add... -> "postgres" -> OK -> Full Control -> same problem
- manually running initdb -D C:\pgdata -> same problem
- runas /user:postgres cmd.exe -> initdb -D C:\pgdata -> initdb successful, but when trying to "Start Server" -> "The system cannot find the path specified." -> checked services.msc -> no postgresql service was created during installation
Solution:
- Uninstall PostgreSQL
- net user postgres /delete
- Control Panel -> User Accounts -> Configure advanced user profile properties -> delete all "Unknown User" instances that seem to be left from postgres
- compmgmt.msc -> Local Users and Groups -> Users -> New User... -> User name: postgres, Password: postgrespass -> Create
- compmgmt.msc -> Local Users and Groups -> Users -> postgres -> Member of -> Add... -> Administrators -> OK
- copy postgresql-8.4.9-1-windows.exe to C:\
- runas /user:postgres cmd.exe -> cd \ -> postgresql-8.4.9-1-windows.exe -> installed successfully without errors. Checked data folder and confirmed files created successfully.
- compmgmt.msc -> Local Users and Groups -> Users -> postgres -> Member of -> Administrators -> Remove
- compmgmt.msc -> Local Users and Groups -> Users -> postgres -> Member of -> Add... -> Power Users -> OK
- Installed HM2 -> created db successfully
- Restarted computer -> HM2 runs properly (i.e. just to check postgresql service starts automatically)
Kind of annoying that no one else seems to have had this specific problem with postgresql on the HM forums.
Oh, related troubleshooting step that might help others. I had an earlier problem of *.vbs files being associated with vim instead of Windows Scripting Host when trying to install another program. So if youre getting Visual C++ errors even though you've got Visual C++ 2005/2008/2010 redistributables installed, try registering vbscript.dll:
- regsvr32 %systemroot%\system32\vbscript.dll