8

i got a new laptop from Dell(XPS 15), with Windows 10 Pro. I have always the same issue During installation of postgres "Problem running post-install step. Installation may not complete correctly. The Database cluster initialisation failed." .

i tried a lot of solutions of past threads: Install postgres not into progam files create a user named postgres with full access to postgress directory, explained here https://www.youtube.com/watch?v=pS_zWDDDSe0 Checked for new win-updates Turned off Firewall and Antivirus of Windows.

Error running cscript //NoLogo "C:\develop\postgres/installer/server/initcluster.vbs" "NT AUTHORITY\NetworkService" "postgres" "****" "C:\develop\postgres" "C:\develop\postgres\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. [14:03:49] Delete the temporary scripts directory... Creating menu shortcuts... Executing cscript //NoLogo "C:\develop\postgres\installer\server\createshortcuts_clt.vbs" "PostgreSQL 11" "C:\develop\postgres" Script exit code: 0

EDIT ERROR LOG

Executing batch file 'radAD31B.bat'...
The program "postgres" was found by "C:/develop/postgres/bin/initdb.exe" but was not the same version as initdb.
Hades85
  • 103
  • 1
  • 1
  • 10

10 Answers10

18

I've just struggled with this for several hours, so I'm posting this for anyone else who winds up here.

Initially, all I could find were two bug reports on the pgsql-bugs mailing list:

BUG #15856: The program "postgres" was found by "initdb" but was not the same version as initdb.

BUG #15970: Db initialization error - initdb.exe and postgres not same version

The specific symptoms are:

The program "postgres" was found by ".../initdb.exe" but was not the same version as initdb.

and although the versions match, you get this:

C:\Program Files\PostgreSQL\11\bin>postgres -V
WARNING:  01000: could not determine encoding for locale
"<some encoding>.utf8": codeset is "CPutf8"

If these are your symptoms, the issue is that you have your region/language settings set to use UTF-8 (beta setting). This causes problems with lots of programs, and PostgreSQL is one of them. Disable this and re-install and you should be fine.

UTF8 Region Settings screenshot

simon
  • 15,344
  • 5
  • 45
  • 67
7

If you ever changed the command line code encoding parameter in the registry

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Autorun

to chcp 65001, chcp 1251 or any other, then that may be the issue.

Returning the value of the command line encoding registry value to default (empty) solved the problem in my case.

Try to change your registry value to empty:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Autorun

  • This is the only solution that worked for me. – Stefanov.sm Sep 24 '21 at 14:54
  • 1
    This solution worked like a magic. But, I am unable to understand how the Autorun field value matters for postgres to do initdb. – Pankaj Nov 12 '21 at 08:36
  • Thanks, I tried everything mentioned online but once I saw this answer I knew it might be the actual answer as I did change the command line encoding before! went back to default and it finally worked. – Sara Sherif Nov 23 '22 at 11:08
  • It's not necessary to delete the entry. You can put `@echo off` line at the beginning of the file specified as a value of the entry. @Pankaj Absence of that line makes every bat file print some extra output which breaks many different tools that call and parse output of a bat file. – Yaroslav Jan 18 '23 at 19:15
3

Follow these steps to avoid this error

  1. Uninstall PostgreSQL
  2. Delete if you have postgres user
  3. Right click on My Computer / This PC and click on Manage goto Local Users and Groups then Users New User enter Username as postgres and Password (whatever you want) and click on Create button.
  4. Now right click on postgres user and click on properties click on Member of tab and then on Add button here click on Advanced and a new dialog box open for Groups click on Find Now and select Administrators click OK button.
  5. Now open Command Prompt / cmd
  6. here type runas /user:postgres cmd.exe and hit enter
  7. cd path to downloaded Postgresql folder enter
  8. postgresql-x.x.x-x-windows.exe enter (here x reflect release, major and minor versions).
  9. Now repeat step 4 and remove group Administrators and add Power Users
Atif Zia
  • 777
  • 2
  • 11
  • 28
  • 1
    Current Postgres versions don't need a dedicated `postgres` Windows user for their installation. –  Jul 15 '20 at 06:04
  • @a_horse_with_no_name If above error occurred than we've to create a postgres user – Atif Zia Jul 16 '20 at 06:14
  • 1
    No, you don't have to –  Jul 16 '20 at 06:15
  • @a_horse_with_no_name This solution works for me if you have any solution than share it here. – Atif Zia Jul 16 '20 at 06:16
  • @a_horse_with_no_name seems not to be the case, I needed to flaff around with this in version 12 (added my steps as an answer although like Atif's still manually creating a user). Would love to know an alternative easier solution! – Andrew Sep 24 '20 at 09:25
  • 2
    @Andrew: I haven't created a `postgres` Windows user since I think Postgres 9.2 or something around that. But then I never use the installer, I use the ZIP packages and run `initdb` manually –  Sep 24 '20 at 09:27
  • @a_horse_with_no_name ah interesting will try that next time, I think with windows you would still need to create a service manually though? – Andrew Sep 24 '20 at 09:29
  • @Andrew: yes, see e.g. here: https://stackoverflow.com/a/26441939/330315 –  Sep 24 '20 at 09:35
1

Just had this issue with postgres 12 my method to solve it is similar to Atif's but uses the command line:

  1. Uninstall PostgreSQL

  2. Delete the postgres user if it still exists :

    net user postgres /delete

  3. Create the postgres user with a password you can remember:

    net user /add postgres [password]

  4. Add the postgres user to the Administrators group:

    net localgroup administrators postgres /add

  5. SKIP this as group no longer exists on win 10 and default users should have necessary permissions - Add the postgres user to the Power Users group

  6. Run a command window as the postgres user: (opens up new command window) :

    runas /user:postgres cmd.exe

  7. copy the install file to a location reachable by that user and run it e.g.:

    C:\Download\postgresql-12.4-1-windows-x64.exe

  8. Remove the postgres user from the Administrators group:

    net localgroup administrators postgres /delete

That's it. Hope this is useful

Andrew
  • 2,598
  • 16
  • 27
0

I have looked at the available solutions but none worked for me so I simply created a new user on my Windows 10 desktop and did the installation there and it was able to complete successfully.

sammyhawkrad
  • 91
  • 1
  • 6
0

Uninstallation may not remove all registry entries. You may type registry in the taskbar search and open Registry Editor.

Navigate to:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE

And remove entries pertaining to postgresql.

Toni
  • 1,555
  • 4
  • 15
  • 23
Satheesh
  • 1
  • 3
0

Installing PostgreSQL on Windows with the EDB installer is begging to get bald(er) faster. You can run PostgreSQL on WSL (Windows Subsystem for Linux) and connect to it on Windows!

Open Windows Terminal/PowerShell as administrator (right click the start-icon on Windows 11 -> Windows Terminal (administrator). Type:

wsl --install

Reboot your computer. After login Ubuntu will automatically be installing, WSL2 and Ubuntu is standard on Windows 11 (check documentation on how to select a different distro, etc.) Follow the instructions to enter your desired username and password.

Update Ubuntu:

sudo apt update && sudo apt upgrade

Install PostgreSQL:

sudo apt install postgresql

Give the 'postgres' user a password:

sudo passwd postgres

Start the service and open psql shell:

sudo service postgresql start && sudo -u postgres psql

Notice that the password you created is not the DB password for postgres, so unless you create a new user you can give postgres one in the psql shell:

ALTER USER postgres PASSWORD 'mypw';

Now you can install pgAdmin or use your own program (in 'normal' Windows) to confirm that you can connect on 127.0.0.1 with port 5432 (may vary) with the user postgres and his password.

0

Just little addition to the answer from Anton Kudryavtsev: Check that there is no Autoran parameter in registry: \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor

Its' deletion solved the error The program "postgres" was found by "C:/Program Files/PostgreSQL/14/bin/initdb.exe" but was not the same version as initdb in my case (checked in Windows 10 x64 and Postgress 14.5 .exe installer)

0

Same problem. Beta UTF-8 was not selected. However this gave me the idea.

I was trying to install using different locale than the default locale of the system I am using. Tried a couple of times.

Installed successfully using the default locale.

YavuzT
  • 11
  • 4
0

You can refer to my method I deleted the pgadmin folder in C:\Users\nameuser\AppData\Roaming and deleted the folder C:\Program Files\PostgreSQL Then I uninstalled postgres and reinstalled.

enter image description here