Last updated: Apr 4, 2024
Reading time·4 min

The error "'psql' is not recognized as an internal or external command, operable program or batch file" occurs for multiple reasons:
psql executable in your system's PATH
environment variable.
If you already have PostgreSQL installed, scroll down to the "Add the path to
psql.exe to your system's PATH environment variable" subheading.
To install and configure PostgreSQL on Windows:
You can click on the download button under "Windows x86-64" for the latest version.








postgres user and make sure to make a note of it.
5432 selected and click "Next".



Wait for the installation to complete.
On the last screen, uncheck the "Stack builder may be used to install additional tools" checkbox and click "Finish".

The next step is to add the path to the psql executable (psql.exe) to your
system's PATH environment variable.
psql.exe to your system's PATH environment variableTo add the path to the psql executable to your system's PATH environment
variable:



bin directory or paste it directly.
For me, the path is the following.
# 👇️ this is my path C:\Program Files\PostgreSQL\15\bin # 👇️ might also be something like this C:\Program Files (x86)\PostgreSQL\15\bin
Note that the path contains your PostgreSQL version, so it will likely be different in your case.

psql.exe file because this is the file that is run when you issue psql commands.psql executable, add it and click on the
"OK" button twice to confirm.
You might also have to restart your PC, but that's not always necessary.
Open a new CMD shell and issue the psql --version command to make sure the
psql executable is accessible.
psql --version

You can use the psql -U postgres command to log in using the default
postgres user.
psql -U postgres

Once you're logged in, you can use the CREATE DATABASE command to create a
database.
CREATE DATABASE employee WITH encoding='UTF8';

Use the \c employee command to switch to the employee database.
\c employee

You can use the CREATE TABLE command to create a table.
CREATE TABLE tasks(task_id serial PRIMARY KEY, task VARCHAR (255) UNIQUE NOT NULL);

Use the INSERT INTO command to insert a record into the table.
INSERT INTO tasks(task) VALUES('walk the dog');

Use the SELECT FROM command to list the records in the tasks table.
SELECT * FROM tasks;

You can also use the SQL Shell (psql) application to issue Postgres commands:

localhostpostgres5432postgres
Once you enter your credentials, you will be logged in as the postgres user,
which is the same as issuing the psql -U postgres command in CMD and entering
your password.
psql -U postgres

To solve the error "'psql' is not recognized as an internal or external command, operable program or batch file", make sure:
psql executable in your system's PATH environment
variable.