Setting Windows PATH for Postgres tools

If, after installing PostgreSQL, you face “psql not recognized as an internal or external command” error when you try to run psql from the command prompt, then most probably all you need to do to solve this problem is to add Postgres’s bin directory to the PATH system variable (the PATH is a system variable which allows Windows with the help of the Command prompt or the Terminal window find executables).

In this blog post, we’ll share seven simple steps that describe how to add the folder to the Windows 10 PATH variable.

Step 1. Run Windows Search on your Windows 10 machine by pressing WIN+S. You will see the Search Textbox.

Step 2. Start typing “environ…” in the Windows Search Textbox and choose “Edit the system environment variables” option at the “Best match” list.
Step 3. The “System Properties” window will be opened where the tabs like “Computer Name,” “Hardware,” and other advanced properties can be founded.

Go to the “Advanced” tab and click on the “Environment Variables” button at the bottom. The “Performance,” “User Profiles,” and “Startup and Recovery” options can also be set in this tab.

Step 4. The “Environment Variables” window will be opened. This is divided into two boxes with User variables and System variables – where all variables and their values are displayed.

Find the “Path” variables in the System variables box, as shown in the screenshot above.

Step 5. Double click on the “Path” variable.

The list with all Path variables will be opened, where the Path variables can be edited, added, and deleted.

Step 6. Click on the “New” button and type a new path, like C:\Program Files\PostgreSQL\11\bin\ into a new editable row.
Step 7. Click “OK” to save the new PATH variable. But in order to these changes has an effect on your Command Prompt window you need to reopen it.

42 thoughts on “Setting Windows PATH for Postgres tools

  1. thank you very much! i have been stuck for a long time until I found this. thank you again!

  2. Thanks a lot for this, I was stuck a whole day on it and you solved my problem in less than 20 min.

  3. I’m really hoping you can help me! I did this step with no issue and my command prompt can open the psql when I do psql -U postgres and then enter the postgres password I set.

    I cannot however just enter psql and go. It is showing my normal C drive user acc as the default e.g. C:\Users\Me> and then if I type psql, it asks for my user password which does not work.

    What can I do? On postgres 12. Thank you

    1. Hi @Lebene.
      I am actually seeking for the same solution. But i guess so far, the above may not work as the database superuser is the default postgres. So I guess to interact with any existing database besides postgres (which you may have created), you have to login to postgres first, then connect to the database using \c .

  4. Is this the default system variable in Windows 10? Because I accidentally deleted the value of path, and PATHEXT, and restarted the computer, the computer restore did not open. Now the command window CMD input other commands are not internal or internal commands. What should I do?

  5. Thanks, first of all! All done, I can see the path on my command line when echo %PATH%, but still if I try to type any command using psql the output is the same : ‘psql’ is not recognized as an internal or external command,
    operable program or batch file…..what can I do to solve the issue? Thanks

    1. Hi Cornelia,

      This issue can happen if:
      1. There is no psql.exe utility in the directory that is in the PATH variable
      2. The computer hasn’t been restarted after changing the variable

      1. I swear this is making me go insane. I downloaded the psql but i just never get the psql.exe for some reason same for mongodb i just dont get the right files why is that and how can i get it?

    2. Hi, Cornelia. A had the same problem.

      The real issue was because the output from the command is bigger than a page and the command prompt had a setting pset pager on

      I disabled this setting and the problem was solved.

      The command to disable – \pset pager off

      Try if it’s still actual

  6. I’ve had a problem with pythons pg_config not being on a path. I’ve never worked with this PATH and my whole backend development team of mine has been waiting more than a week to get things fixed for ready for production. I’ve looked everywhere for how to do this and this is one of the only hands-down straight-up examples there for this.

  7. As at the time of writing thic comment, we have Postgres 14 as the current version. So, C:\Program Files\PostgreSQL\11\bin\ will not work, but adding C:\Program Files\PostgreSQL\14\bin\ to your environment variable will.

    It is important for you to note the version of your Postgres installed.

Leave a Reply

Your email address will not be published. Required fields are marked *