Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql -bash: psql: command not found

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?

like image 509
Peter Avatar asked Jul 22 '11 12:07

Peter


People also ask

Why is psql not working?

If, after installing PostgreSQL, you face “psql not recognized as an internal or external command” error when you try to run psql from the command prompt, then most probably all you need to do to solve this problem is to add Postgres's bin directory to the PATH system variable (the PATH is a system variable which ...

Where can I find psql?

On Windows, you can find psql in the Program Files, and you should be able to launch it in a command prompt simply by clicking on it.

Does psql come with PostgreSQL?

Connecting to a Databasepsql is a regular PostgreSQL client application.


2 Answers

export PATH=/usr/pgsql-9.2/bin:$PATH 

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 find psql. 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.

like image 113
Pavel Avatar answered Sep 24 '22 07:09

Pavel


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 the PATH for the postgres user.

like image 24
marto Avatar answered Sep 22 '22 07:09

marto