I have installed PostgreSQL and it is working ok. However, when I went to restore a backup I got the error -bash: psql: command not found
:
[root@server1 ~]# su postgres
[postgres@server1 root]$ psql -f all.sql
bash: psql: command not found
[postgres@server1 root]$
What have I done wrong?
It can be due to psql is not in PATH
Then create a link in /usr/bin
Then try to execute psql it shoould work.
perhaps psql isn't in the
PATH
of the postgres user. Use the locate command to find where psql is and ensure that it's path is in thePATH
for the postgres user.The question is for linux but I had the same issue with git bash on my Windows machine.
My pqsql is installed here:
C:\Program Files\PostgreSQL\10\bin\psql.exe
You can add the location of
psql.exe
to your Path environment variable as shown in this screenshot:If you are using the Postgres Mac app (by Heroku) and Bundler, you can add the pg_config directly inside the app, to your bundle.
...then run bundle again.
Note: check the version first using the following.
The program executable
psql
is in the directory/usr/pgsql-9.2/bin
, and that directory is not included in the path by default, so we have to tell our shell (terminal) program where to findpsql
. When most packages are installed, they are added to an existing path, such as/usr/local/bin
, but not this program.So we have to add the program's path to the shell PATH variable if we do not want to have to type the complete path to the program every time we execute it.
This line should typically be added to theshell startup script, which for the bash shell will be in the file
~/.bashrc
.In case you are running it on Fedora or CentOS, this is what worked for me (PostgreSQL 9.6):
In terminal:
modify the following text from:
to
exit, then:
To exit postgreSQL terminal, you need to digit:
Source: https://serverfault.com/questions/541847/why-doesnt-sudo-know-where-psql-is#comment623883_541880