32

I'm a Windows user - it took me a couple of hours of constant installs and uninstalls before I could get this working, with the first 10 or so times coming to see the error message in the title.

I place this here as a self-answered question to prevent others who might run into the same problem while installing, and include some basic usage methods for those like me who are first comers in using PostgreSql.

2
  • 4
    In my case it was a registry key issue, stackoverflow.com/a/68737037/16638409 Commented Aug 11, 2021 at 6:36
  • Please check whether Microsoft Visual C++ 2015-2022 redistributable is installed or not, if that is not installed then you would surely face post install issue. This helped me fixing this issue. Hope it helps others. Commented Nov 14 at 13:42

9 Answers 9

43

You have to mannualy run initdb which is present : "C:\Software\PostgreSql\12\bin"

Now make sure u associate "postgres" as user alongwith the initdb cmd since "postgres" is the superuser that got created during installation.

initdb -E UTF8 --locale=en_US.utf8 -U postgres -D "D:\PostgreSql\12\data"

Now once database cluster is initialized then you can start the server by using pg_ctl utility present inside bin folder of PostgreSql\12

pg_ctl start -D "D:\PostgreSql\12\data"

Or you can also register it as a windows service and you can set it to automatic as administrator (you need to restart your PC after that):

pg_ctl register -N PostgreSql-12.3.1 -D "D:\PostgreSql\12\data"

Now you are all set to use the postgresql database. Either use it through cmd line (psql) or pgAdmin4

Sign up to request clarification or add additional context in comments.

2 Comments

to run the pg_ctl register command, you will need to be using cmd prompt as an admin.
Add the initdb command can only be run as as a non-admin.
26

I faced some major issues with this myself when trying to install PostgreSQL 9.6 and couldn't get it working despite the above answers. What solved it for me was either

In the installer

When prompted for locale, do not check 'default locale'. Instead, choose something like 'United States English'. For some reason, the default doesn't work.

After the installer

If you went ahead and checked 'default locale' anyways, you can still fix the installation errors without reinstalling the whole thing. What you need to do is similar to above answers, but with slight changes:

  1. Go to your postgres /bin directory (default location: "C:\Program Files\PostgreSQL\9.6\bin") and execute the following query:

initdb -D "C:\Program Files\PostgreSQL\9.6\data" -U postgres --locale="English_United States.1252"

As you can see, locale is not an intuitive string such as "en_US.UTF8", so this can get quite nasty if you don't know what is going on. Anyways, the above code should result in a "Success" message.

  1. Next, execute the following command:

pg_ctl register -N PostgreSQL -D "C:\Program Files\PostgreSQL\9.6\data"

This should result in a windows service called PostgreSQL.

  1. Lastly, to start your newly created service, enter:

net start PostgreSQL

That's it. everything should be up and running now.

4 Comments

I did the step by step with version 14 and it worked.
Windows 11 (64bit), Postgres 15. I had an error on step 1): fixing permissions on existing directory c:/Program Files/PostgreSQL/15/data ... initdb: error: could not change permissions of directory "c:/Program Files/PostgreSQL/15/data": Permission denied To resolve this I had to give "Everyone" access to the data folder first, then the command succeeded. The rest of the steps also worked as expected.
Worked on PostgreSQL 16.1
gibash as admin also works
3

Uninstall the Microsoft Visual C++ 2015-2022 redistributable and the PostgreSQL with installation failed and try install again.

Has worked for me to upgrade PostgreSQL 17 to 18.

2 Comments

I had to install it before a fresh install of PostgreSQL18 to avoid this specific error. Thank you.
2

Installation)

  • Download the appropriate install file for your system.

  • Make sure to install to the default path:

C:\Program Files (x86)\PostgreSQL\9.3\ was the default on my system.

Not installing to the default path may give you dll errors and whatnot.

If installation completed with no problem,

PostgreSql would have created a database with the user postgres and the password being the value you inputted during installation.

  • Add the PostgreSQL\9.3\bin folder to your PATH.

PostgreSql usage)

What's important in now using PostgreSql is this:

login is as user postgres for whatever command you want to use.

Ignoring this will give you constant password authentication failed messages, since you'll be attempting to login as your PC's ID.

For example)

  • logging into psql)

psql -U postgres

  • creating a new database)

createdb -U postgres [dbname] [etc...]

  • executing a sql data file (ex. data.sql) within a certain database)

psql -U postgres -f data.sql dbname

Additional Usage

Once logged into psql (through psql -U postgres), you can use the following commands

  • \l list the available databases

  • \c [dbname] 'connect' to a database

  • \d display the description of that database (once connected)

I hope this helps.

I'll add some more examples if I run into any more problems during my first couple of days of usage.

Comments

2

I also faced this issue, Firstly uninstall any instances of postgres.

Afterwards do the following steps,

  1. Open the run command using win + r -> search for compmgmt.msc

  2. Select Local Users and Group.

  3. Add new user as postgres and set password as root

  4. After creating user:postgres click on the users folder , select postgres user.

  5. In the memberOf tab click on the add button in the bottom left corner, A dialog box appears inside the "Enter the object names to select" section type Administrators

  6. Click ok and finish

  7. click on the postgres user again and in the general tab, Uncheck user must change password at next logon box.

  8. copy the postgres installation file to c:/

  9. open cmd run this command "runas /user:postgres cmd.exe".

  10. new cmd opens with user as postgres provide your password.

  11. navigate to cd /

  12. now enter the full name of the installation file in the root folder.

Afterwards , the installation will take place normally without any error.

This worked for me, Try it yourself if it works for you or not.

1 Comment

This response worked for me. I just needed to choose locale as English USA for installation to be successful.
2

I also was getting this message from postgresql and I tried so many things. As a result of, I found solution in this case:

  1. Firstly, remove postgresql via control panel
  2. Delete all files from "C:\Program Files\PostgreSQL", if you didn't change the direction
  3. Run setup exe file as Administrator
  4. Next, next, next... until following step and select "English-United States"

crucial image

Comments

0

I had the same problem during installation. What worked for me was to uninstall Postgres and the run the .exe file as Administrator.

Comments

0

Setting a password during the installation process may be too short. Try changing your password again. It works for me.

Comments

0

It's the mid of 2025 meanwhile, and the problem still exists with version 17.5.3.

In my case, the password that I was asked for during the installation was either too long or did contain characters that the installer was too stupid to handle correctly. I didn't debug the exact reason further.

Anyway, in the fourth installation attempt I changed that password to something very simple and short without special characters, and the the installation then went through.

For the improbable case that somebody wants to research the situation: The password that caused the trouble was

C${85,S`c+}ü~{e)3Üe$&cyTBeMoOYTee´%t§$>x};T}Mpfz

As mentioned above, the installer accepted that password without any complaints at the begin of the installation, but then obviously couldn't handle it correctly at the end. This is ridiculous.

2 Comments

Thanks for sharing! I spent 4 hours trying to fix this, and it turned out that simply changing the password solved the problem.
@Unal Glad that it worked for you, too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.