1

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.

4 Answers 4

1

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 )

1

The question does not mention the Linux distribution, but the /usr/pgsql-10/bin path suggests RHEL-based. Because it is possible to have multiple versions of PostgreSQL installed on a single system, the alternatives program is used in RHEL-based distros for managing symbolic links from /usr/bin to utilities of a particular PostgreSQL version in /usr/pgsql-*/bin. Debian-based distros use the similar update-alternatives program.

List all installed alternatives:

$ alternatives --list
pgsql-pg_config         auto    /usr/pgsql-14/bin/pg_config
pgsql-createdb          auto    /usr/pgsql-14/bin/createdb
...
pgsql-psql              auto    /usr/pgsql-14/bin/psql
...

List alternatives for a specific program:

$ alternatives --display pgsql-psql
pgsql-psql - status is auto.
 link currently points to /usr/pgsql-14/bin/psql
/usr/pgsql-14/bin/psql - priority 1400
Current `best' version is /usr/pgsql-14/bin/psql.

Select a different alternative:

$ sudo alternatives --config pgsql-psql

There is 1 program that provides 'pgsql-psql'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/pgsql-14/bin/psql

Enter to keep the current selection[+], or type selection number:
2
  • For debian based it is update-alternatives Commented Jul 26, 2024 at 9:25
  • 1
    True. It was already mentioned in the answer. Commented Jul 28, 2024 at 15:31
0

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):

PATH=/usr/psql-10/bin:$PATH

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.

0

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.