Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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?

share|improve this question
2  
This can happen on CentOS when you accidentally install PostgreSQL 8.4 (package postgresql-server) after installing PostgreSQL 9.2 (package postgresql-server92) on the same machine. If you erase PostgreSQL 8.4, yum also removes the postgres bin directory from the path. – Iain Elder Sep 24 '13 at 11:15
    
^^ THIS! Thanks Iain – Joe Czucha Nov 27 '14 at 15:06
up vote 10 down vote accepted

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.

share|improve this answer
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.

share|improve this answer
1  
Would you be willing to expand this comment? It seems popular, but it could be much more useful with additional information (for example, where do the above lines go, and what do they do?) – rainbowsorbet Apr 28 '15 at 23:38

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.

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

...then run bundle again.

Note: check the version first using the following.

ls /Applications/Postgres.app/Contents/Versions/
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.