7

(Note: This question has been compeltely rewritten from its original form, so it reflects the actual problem and will help others find a solution to the same issue).


I still haven't been able to successfully install PostgreSQL on my Windows 7 Ultimate x64 computer. See this prior question for some history.

I did a fresh instillation of 9.2 and the only error I got was this one:

error installing

It reads:

"Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed".

This occurs even after I do a complete manual uninstall of PostgreSQL and pgAmdin-III:

  • Ran the PostgreSQL uninstaller, which failed with the error Error stopping service postgresql-x64-9.2.
  • Removed all the PostgreSQL-related registry entries for PostgreSQL under HKEY_LOCAL_MACHINE\SOFTWARE and HKEY_CURRENT_USER\SOFTWARE
  • Removed the postgres user account using net user postgres /delete in an Administrator command prompt (shift-right clicked on "Command Prompt" in start menu, chose "Run as administrator")
  • Removed the postgres user profile
  • Deleted the C:\Program Files\PostgreSQL\ directory, including the data directory within %appdata%
  • Removed some PgAdmin-III registry entries that pointed to PostgreSQL
  • Removed the service account for postgres from services.msc

When I reboot and try the installer again it fails with the same message.

The install-postgresql.log file from %TEMP% 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 another error a bit later:

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

See full installer log file download here.

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Paul White
    Aug 29, 2017 at 10:55

5 Answers 5

6

It appears that the root cause of this issue may have been that @Celeritas's computer had an incorrect value for the COMSPEC environment variable. It had a trailing semicolon, so instead of the normal:

C:\Windows\system32\cmd.exe

it was:

C:\Windows\system32\cmd.exe;

This one-character difference is enough. The above isn't a valid command prompt path, so popen() calls were failing. Unfortunately, instead of something useful like:

'"C:\Windows\system32\cmd.exe;"' is not recognized as an internal or external command, operable program or batch file

it instead reports the delightfully useful error No error:

initdb: could not execute command ""C:/Program Files/PostgreSQL/9.2/bin/postgres.exe" --boot -x1 -F ": No error

See related:

I've reported this to the installer team and written a wiki entry to describe it. See blog post.

The issue was eventually resolved by:

  • Editing the COMSPEC environment variable
  • Uninstalling PostgreSQL
  • Rebooting
  • Reinstalling PostgreSQL

though there was a lot more before that which shouldn't actually be necessary to resolve this, including doing a total manual clean uninstall of PostgreSQL by hand.

Now I just want to find the people who wrote the program that modified this environment variable.

1
  • did not work for me
    – H. Aqjn
    Dec 20, 2020 at 8:15
0

from this answer https://dba.stackexchange.com/a/248584/185153

If you're on Windows 10 with codepage UTF-8 in regional settings (picture in link above), the root cause is that :

  1. Cluster initialization in setup calls initdb
  2. initdb checks version as if calling postgres -V
  3. postgres -V doesn't recognise CPutf8 yet then returns an unmatched result.

Until it is properly fixed, you may just uncheck UTF-8 codepage box and restart, it will be okey.

This can reproduced in PostgreSQL 12 also.

Kudos to @simon for this finding.

0

Struggling with this problem for days.Finally got help from the EDB team My problem got solved by doing the following steps :

1) Open the command prompt and go to the following directory.

cd "C:\Program Files\PostgreSQL\10\bin"

2) Once you are inside the "C:\Program Files\PostgreSQL\10\bin" directory execute the following command.

.\initdb.exe -D "C:\Program Files\PostgreSQL\10\data"

3) At the end of this command you will be promoted to execute a pg_ctl command to start the Postgres cluster. Please execute the command and once you get a message as the server started you are all set to use the Postgres database.

Note : Instead of 10 user whatever version you have installed .If the pg_ctl command in the third step gives an error after running it in \bin directory , then try running it in \data directory.After the above process re-run the installer.

6
  • 1
    It's a really bad idea to put the data directory into C:\Program Files` that directory has restricted access for a reason. It's much better to put the data directory e.g. to %ProgramData%`
    – user1822
    May 27, 2020 at 21:09
  • 1
    In order to complete a_horse_with_no_name answer, I suggest locating your PostgreSQL's data folder to a dedicated folder like C:\data.
    – tdaget
    May 27, 2020 at 22:00
  • Maybe postgresql for windows uses these default directories?
    – peterh
    May 27, 2020 at 22:26
  • @a_horse_with_no_name u can later grant access i.e full control to the data directory and bin directory . That works. May 28, 2020 at 8:17
  • Yes, postgresql uses C:\Program Files as the default directory May 28, 2020 at 8:18
0

Problem:

Installing 13.1.1 on Windows Server 2019 failed with the message

"Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed".

  • My COMSPEC environment variable was configured correctly.

  • My UTF-8 codepage setting was disabled.

  • Manually envoking initdb failed with the following:

     PS C:\Program Files\PostgreSQL\13\bin> .\initdb.exe -D "D:\PostgreSQL"
     The files belonging to this database system will be owned by user "myUser".
     This user must also own the server process.
    
     The database cluster will be initialized with locale "English_United States.1252".
     The default database encoding has accordingly been set to "WIN1252".
     The default text search configuration will be set to "english".
    
     Data page checksums are disabled.
    
     fixing permissions on existing directory D:/PostgreSQL ... ok
     creating subdirectories ... ok
     selecting dynamic shared memory implementation ... windows
     selecting default max_connections ... 100
     selecting default shared_buffers ... 128MB
     selecting default time zone ... US/Eastern
     creating configuration files ... ok
     running bootstrap script ... 2021-01-25 09:55:49.793 EST [51184] LOG:  unrecognized win32 error code: 50
     2021-01-25 09:55:49.804 EST [51184] LOG:  could not link file "pg_wal/xlogtemp.51184" to "pg_wal/000000010000000000000001": Invalid argument
     2021-01-25 09:55:49.808 EST [51184] FATAL:  could not open file "pg_wal/000000010000000000000001": No such file or directory
     child process exited with exit code 1
     initdb: removing contents of data directory "D:/PostgreSQL"
    

Probable cause:

Drive D: is formatted using ReFS. Initializing on an NTFS drive worked without issue.

Solution:

Initialize the database on drive C:\PostgreSQL and then copy folder to D:\PostgreSQL.

Open terminal as normal user (not admin) and run:

C:\Users\myUser>"C:\Program Files\PostgreSQL\13\bin\pg_ctl.exe" -D "D:\PostgreSQL" -l logfile start
waiting for server to start.... done
server started

Launch a psql shell and login with user myUser. You can then create a postgres user if desired:

CREATE ROLE postgres LOGIN PASSWORD 'password' NOINHERIT CREATEDB;
CREATE SCHEMA postgres AUTHORIZATION postgres;
GRANT USAGE ON SCHEMA postgres TO PUBLIC;
0

For people still struggleing with this in 2022. The only thing that worked for me on Windows 10 is selecting English America as the local rather then my own latin locale.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.