117

For Postgres, I keep getting this error multiple times even though I have already set the location of the bin folder to the path variable in Windows 8. Is there something else I'm missing?

John Smith
  • 7,243
  • 6
  • 49
  • 61
as1216
  • 1,194
  • 2
  • 8
  • 11
  • Please post the output of `set path` on the command line (and no you don't have to be able to post a picture. Copy the ***text*** from the commandline, edit your question and paste the output) –  May 22 '15 at 16:17
  • Run `echo %PATH%` in your command prompt to see if the path you added is indeed there – mike.k May 22 '15 at 16:17
  • so this is the output: `set path "C:\Program Files\Postgres.app\Contents\Versions\9.4\bin"` @a_horse_with_no_name – as1216 May 23 '15 at 18:54
  • @mike.k I ran it but it didn't show the address I set it to...then again I don't know if it set it to the user or the system path variable – as1216 May 23 '15 at 18:56
  • I am facing the same issue. Checked PATH variable and bin and lib paths are properly set. Not sure why psql --version is not working. – IfOnly Oct 05 '16 at 07:30

14 Answers14

220

Just an update because I was trying it on Windows 10 you do need to set the path to the following: ;C:\Program Files\PostgreSQL\14\bin ;C:\Program Files\PostgreSQL\9.5\lib

PS : 14 is the current version, check whatever version you are on. You can do that either through the CMD by using set PATH [the path] or from my

computer => properties => advanced system settings=> Environment Variables => System Variables

Then search for path.

Important: don't replace the PATHs that are already there just add one beside them as follows ;C:\Program Files\PostgreSQL\9.5\bin ;C:\Program Files\PostgreSQL\9.5\lib

Please note: On windows 10, if you follow this: computer => properties => advanced system settings=> Environment Variables => System Variables> select PATH, you actually get the option to add new row. Click Edit, add the /bin and /lib folder locations and save changes.

Then close your command prompt if it's open and then start it again try psql --version If it gives you an answer then you are good to go if not try echo %PATH% and see if the path you set was added or not and if it's added is it added correctly or not.

Important note:

Replace 9.5 with your current version number. As of 2021, that is 13. For 2022 is 14.

Shahin
  • 2,507
  • 1
  • 13
  • 17
  • 8
    Make sure every user update `9.5` with their current version of psql which is installed mine psql version is `12` so final url will look like this `C:\Program Files\PostgreSQL\12\bin ;C:\Program Files\PostgreSQL\12\lib` – Hanzla Habib Oct 11 '20 at 05:47
  • 1
    For me I had to add these two paths: 1. `C:\Program Files\PostgreSQL\15\bin` and 2. `C:\Program Files\PostgreSQL\15\lib` and then restart my terminal. – Rainymood Jan 20 '23 at 08:52
14

Enter this path in your System environment variable.

C:\Program Files\PostgreSQL\[YOUR PG VERSION]\bin

In this case i'm using version 10. If you check the postgres folder you are going to see your current versions.

In my own case i used the following on separate lines:

C:\Program Files\PostgreSQL\10\bin
C:\Program Files\PostgreSQL\10\lib
Divine Hycenth
  • 151
  • 1
  • 3
12

Windows 10

It could be that your server doesn't start automatically on windows 10 and you need to start it yourself after setting your Postgresql path using the following command in cmd:

pg_ctl -D "C:\Program Files\PostgreSQL\11.4\data" start

You need to be inside "C:\Program Files\PostgreSQL\11.4\bin" directory to execute the above command.

EX:

enter image description here

You still need to be inside the bin directory to work with psql

Abdel-Raouf
  • 700
  • 1
  • 8
  • 20
9

You can follow the following steps below.

C:\Program Files\PostgreSQL\yourversion

enter image description here enter image description here

6

I had your issue and got it working again (on windows 7).

My setup had actually worked at first. I installed postgres and then set up the system PATH variables with C:\Program Files\PostgreSQL\9.6\bin; C:\Program Files\PostgreSQL\9.6\lib. The psql keyword in the command line gave no errors.

I deleted the PATH variables above one at a time to test if they were both really needed. Psql continued to work after I deleted the lib path, but stopped working after I deleted the bin path. When I returned bin, it still didn't work, and the same with lib. I closed and reopened the command line between tries, and checked the path. The problem lingered even though the path was identical to how it had been when working. I re-pasted it.

I uninstalled and reinstalled postgres. The problem lingered. It finally worked after I deleted the spaces between the "; C:..." in the paths and re-saved.

Not sure if it was really the spaces that were the culprit. Maybe the environment variables just needed to be altered and refreshed after the install.

I'm also still not sure if both lib and bin paths are needed since there seems to be some kind of lingering memory for old path configurations. I don't want to test it again though.

voluntier
  • 330
  • 4
  • 11
6

If you tried all the answers and still spinning your heads, don't forget to change the version with your one which you downloaded.

For example, don't simply copy paste

;C:\Program Files\PostgreSQL\9.5\bin ;C:\Program Files\PostgreSQL\9.5\lib

More clearly,

;C:\Program Files\PostgreSQL\[Your Version]\bin ;C:\Program Files\PostgreSQL\[Your Version]\lib

I was spinning my heads. Hope this helps.

5

Even if it is a little bit late, i solved the PATH problem by removing every space.

;C:\Program Files\PostgreSQL\<installed version>\bin;C:\Program Files\PostgreSQL\<installed version>\lib

works for me now.

Ali H. Kudeir
  • 756
  • 2
  • 9
  • 19
derRichter
  • 51
  • 1
  • 4
5

Make sure that the path actually leads to the executables. I'm using version 11 and it did not work until this was set as the path:

C:\Program Files\PostgreSQL\11\bin\bin

Maybe this is how version 11 is structured or I somehow botched the installation but I haven't had a problem since.

Nate
  • 51
  • 1
  • 1
3

Simple solution that hasn't been mentioned on this question: restart your computer after you declare the path variable.

I always have to restart - the path never updates until I do. And when I do restart, the path always is updated.

Michael Jay
  • 503
  • 3
  • 15
3

Find your binaries file where it is saved. get the path in terminal mine is

C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin

then find your local user data path, it is in mostly

C:\usr\local\pgsql\data

now all we have to hit the following command in the binary terminal path:

C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin>pg_ctl -D "C:\usr\local\pgsql\data" start

done!

Anupam Maurya
  • 1,927
  • 22
  • 26
3

For Windows 10 and 11 users, here are the steps:

  1. Go to Edit environment variables for your account (search for it on the start menu)
  2. It will open the System Properties form — click the Environment Variables
  3. Under the User variables for <username> (or you can add it in system variables), find the path variables and click edit, and add the path to your Postgres bin file address (in my case it's C:\Program Files\PostgreSQL\15\bin).
  4. And save it and re-open the terminal.
Tri Dawn
  • 540
  • 6
  • 11
1

You can use psql on CMD on Windows 11.

First, search and click Edit the system environment variables as shown below:

enter image description here

Then, click Environment Variables as shown below:

enter image description here

Lastly, set C:\Program Files\PostgreSQL\<version>\bin to Path either in User variables or System variables or both as shown below. *Only the currently logged-in specific user can access User variables while all users can access System variables:

...
C:\Program Files\PostgreSQL\13\bin
C:\Program Files\PostgreSQL\14\bin
C:\Program Files\PostgreSQL\15\bin

enter image description here

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

Always better to install a previous version or in the installation make sure you specify the '/data' in a separate directory folder "C:\data"

0

I kept trying these solutions to no avail, then I realised that my error was that I was adding new environment variables instead of editing the PATH variable. We need to add the

;C:\Program Files\PostgreSQL\9.5\bin;C:\Program Files\PostgreSQL\9.5\lib

to the existing PATH variable, NOT create new variables. Leaving this here in case someone else gets stuck with the same mistake.

Cande
  • 141
  • 2
  • 4