If you have installed PostgreSQL database in Windows 11|10 and are using any of its commands such as psql
on cmd or command prompt, and you are getting the error ‘psql’ is not recognized as an internal or external command, operable program or batch file, it means that PostgreSQL Path is not set or set incorrectly on your windows 11|10 system.
Don’t worry, this error can be fixed by setting the correct path of PostgreSQL in the system environment variable on Windows 11|10. Here are two solutions, you can use this to fix error:
Solution 1: Set PostgreSQL Path Using Edit System Environment Variables in Windows 11|10
Steps to set PostgreSQL Path Using Edit System Environment Variables:
Step 1 – Go to Start and type “environment variables”
First of all, Open the Start menu and search for “Environment Variables” and select “Edit the system environment variables.” like following:
Step 2 – Environment Setting
Then, In the System Properties window, click the “Environment Variables” button; as shown below picture:
Step 3 – Edit System Environment Variable Path
Inside the Environment Variables menu, go to the System variables submenu, select Path, then click the Edit button.; as shown below picture:
Step 4 – Add PostgreSQL PATH to System Environment Variable
To set Postgresql path in a system environment variable on Windows, Click on New, add path (e.g., “C:\Program Files\PostgreSQL\15\bin”), and save it; as shown below picture:
Click “OK” to close the “Edit environment variable” dialog, “OK” again to close the “Environment Variables” dialog, and one last “OK” to close the “System Properties” dialog.
Step 5 – Restart Windows CMD
Restart command prompt windows. Now, you should be able to run postgresql commands from any directory within the command prompt.
Step 6 – Test PostgreSQL
After following these steps, you should be able to use postgresql commands without encountering the error message. You can verify that postgresql is correctly installed and configured by running psql --version
in the command prompt or PowerShell, which should display the installed postgresql version.
psql
--verion
If the output displays the postgresql version, then postgreSQL has been successfully added to the PATH variable.
Solution 2: Set PostgreSQL Path in Windows 11|10 Using Command Prompt
Just open your Windows CMD and command prompt and type setx /M path "%PATH%;C:\Program Files\PostgreSQL\15\bin"
command and press enter, this will set the postgreSQL path to system environment variable on your Windows system:
setx /M path "%PATH%;C:\Program Files\PostgreSQL\15\bin"
In this command that is “15”, that is the version of postgresql, check your version of postgresql and then replace it with your installed version.
Conclusion
That’s all, you are done to fix the error ‘PSQL’ is not recognized as an internal or external command, operable program or batch file on Windows 11|10 by setting the correct path of PostgreSQL on the system environment variable.