My system is looking at usr/bin/psql and I need to use /usr/pgsql-10/bin/psql but I'm not sure how to change it. I don't feel like I should be deleting or renaming the first one. How can I get my system to use the other one with minimal change on my filesystem? Do I use an alias in my .bash_profile?

BTW first version is 9.2.24 and second one is 10.6.


Using an alias is fine. You can just create an alias that includes all of the connection info for the database something like.

alias mydb='/usr/pgsql-10/bin/psql -h localhost -p 5433 -U myuser mydatabase'

That way you don't have to retype everything. And you still have access to 9.2 version of psql in your shell if you need it. (note that the above assumes that the postgresql-10 database server is listening on 5433 rather than 5432 which is the standard port )


Make sure that /usr/pgsql-10/bin comes before /usr/bin in your $PATH. You can do this by adding the following to the end of your shell's initialisation file (e.g. ~/.bashrc if you're using bash):


The same could be done in any script that needs to use psql from /usr/psql-10/bin rather than from the default path (modifying the PATH in a script should happen early in the script).

Modifying PATH is the most common way to change the "personality" of a script or shell session on systems with alternative implementations of various utilities.


Turns out I had a postgresql.x64_86 or similar installed. I took that out and the correct psql was automatically chosen as $PATH was already correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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