[Solved] psql is not recognized as an internal or external command

[Solved] 'psql' is not recognized as an internal or external command

In this tutorial, we will learn about how to fix the error psql is not recognized as an internal or external command. If you are a Windows Operating System User, you must have come across this error while using the PostgreSQL database. This is most common error that occurs whenever there is some issue with the PostgreSQL database in your Windows system. It can also occur if there is no PostgreSQL database installed yet you try to connect to it. We will cover some of the common cause and solution to fix this error in the upcoming section of this tutorial. So, let us begin the learning.

 

[Solved] psql is not recognized as an internal or external command

Also read: How to Find Wi-Fi Password in Windows: [2 Easy Methods]

First thing first, we will reproduce the error to make sure we are addressing the correct situation. Let us follow some step to reproduce this error in our Windows machine. Open the cmd (Command Prompt) by searching the word “cmd” in the search bar. Next, from the cmd prompt, try to connect to PostgreSQL database as default user (postgres) using below command. Enter the postgres user’s  password. If you see the error as shown below, then we need to fix this by following the solutions provided in this tutorial.

C:\Users\linuxnasa> psql -U postgres
'psql' is not recognized as an internal or external command,
operable program or batch file.

 

NOTE:

Use “Win + r” key  and type cmd to open the Windows command prompt

 

Solution-1: Check if PostgreSQL is installed 

There are multiple ways to address this error. We will start with basics. The first thing we need to check is that if PostgreSQL database is installed in our machine. To check this follow below steps in sequence.

Step-1: Check if PostgreSQL binaries are Present

In this step, to make sure that the PostgreSQL database is installed in the machine, open file explorer and go to the path where you had installed the database. I have installed in C drive so for me path would be ,  “C:\Program Files“. Next,  check if all the default configuration files and folders are present as shown below.

 

Step-2: Open SQL Shell

In this step, search SQL shell from search bar and open it. Enter all the detail and connect to the database. If login is successful that means PostgreSQL is installed properly in your system as shown below.

 

NOTE:

If PostgrelSQL databse is not installed, you can follow the guide How to Install PostgreSQL on Windows [Step by Step Guide] to install.

 

 

Solution-2: Check if PostgreSQL is added in PATH variable

After verifying that the PostgreSQL database is installed in the machine, let us do some configuration to access the PostgreSQL database from Windows cmd.  We will add the PostgreSQL binary path in the system’s PATH variable. To do so, follow the steps below in sequential order.

Step-1: Search Environment Variable

In this step, search for “environment variable” from the search bar and click on the first search result as shown below.

 

Step-2: Copy the PostgreSQL Binary Path

In this step, copy the PostgreSQL  binary  path from your system. I have installed in “C drive” so for me the binary path is as shown below.

 

Step-3: Add the PostgreSQL Binary Path in PATH Variable

In this step, click on Environment Variables option as shown below.

 

Next, select Path variable and click on Edit button as shown below.

 

Next, click on “New” button to add the PostgreSQL binary path as shown below.

 

Next, add the PostgreSQL binary Path which you had copied earlier. After adding the Path, click on Ok button as shown below.

 

Next, click on Ok button to apply the current changes in the machine as shown below.

 

Next, open the command prompt again and type the command psql -U postgres to connect to the database. If there is no error, it will ask for the password. Enter the password, it will connect to the database as shown below.

C:\Users\linuxnasa>psql -U postgres
Password for user postgres:
psql (15.5)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.

postgres=#

 

Solution-3: Re-install PostgreSQL 

If above two solution does not fix the error, uninstall the PostgreSQL from your system and re-install.  After, reinstalling, follow above two solutions. It will resolve the error.

 

Summary

I hope the solution provided in this tutorial has helped you to resolve the error. In Window’s system, whenever you install any software using the installer, chances are you will see this king of error if try to access the application from cmd. So i follow these common techniques and it helps me every time .

Leave a Comment