0
0
PostgresqlDebug / FixBeginner · 3 min read

How to Fix 'psql command not found' Error in PostgreSQL

The psql command not found error happens because your system cannot find the PostgreSQL client program. To fix it, ensure PostgreSQL is installed and add its bin directory to your system's PATH environment variable.
🔍

Why This Happens

This error occurs because the system does not know where to find the psql program. Usually, this means PostgreSQL is either not installed or its bin folder is not included in your system's PATH. The PATH is a list of folders where your computer looks for commands.

bash
psql -U postgres
Output
bash: psql: command not found
🔧

The Fix

First, check if PostgreSQL is installed. If not, install it from the official website or your package manager. Then, add the PostgreSQL bin directory to your PATH. For example, on Linux or macOS, you can add export PATH=$PATH:/usr/pgsql/bin to your shell profile. On Windows, add the PostgreSQL bin folder to the system environment variables.

bash
export PATH=$PATH:/usr/pgsql/bin
psql -U postgres
Output
psql (14.5) Type "help" for help. postgres=#
🛡️

Prevention

To avoid this error in the future, always verify PostgreSQL installation and ensure the bin directory is in your PATH. Use your system's package manager for installation to handle this automatically. Also, restart your terminal or system after changes to environment variables.

⚠️

Related Errors

Other similar errors include psql: FATAL: database does not exist which means the database name is wrong, or psql: could not connect to server which means the PostgreSQL server is not running. Fix these by checking database names and starting the PostgreSQL service.

Key Takeaways

The 'psql command not found' error means your system can't find the PostgreSQL client program.
Install PostgreSQL if missing and add its 'bin' directory to your system PATH environment variable.
Restart your terminal after updating PATH to apply changes.
Use your system's package manager to simplify installation and PATH setup.
Check related errors by verifying database names and PostgreSQL server status.