1

When I run

sudo -u postgres psql

I get the

sudo: psql: command not found

error. I can't get it to work.

# locate psql
/etc/alternatives/psql.1.gz
/usr/bin/psql
/usr/lib/postgresql/9.5/bin/psql
/usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
/var/lib/dpkg/alternatives/psql.1.gz
/var/lib/postgresql/.psql_history

and

# ln -s /usr/lib/postgresql/9.5/bin/psql /usr/bin/psql
ln: failed to create symbolic link '/usr/bin/psql': File exists

Didn't work. Postgresql is running and doing fine, though.

6
  • What does sudo -u postgres /usr/bin/psql return? Is the environment for user postgres defined? – ajgringo619 Dec 6 '19 at 22:42
  • @ajgringo619 It returns sudo: /usr/bin/psql: command not found – parsecer Dec 6 '19 at 23:03
  • This might help: unix.stackexchange.com/questions/176997/… – ajgringo619 Dec 6 '19 at 23:07
  • "command not found" can sometimes happen if the program has the wrong binary architecture for your system - check with file /usr/bin/psql and uname -m – steeldriver Dec 6 '19 at 23:39
  • @steekdriver the first one gives /# file /usr/bin/psql /etc/magic, 4: Warning: using regular magic file /usr/share/misc/magic' /usr/bin/psql: broken symbolic link to ../share/postgresql-common/pg_wrapper , the second one uname -m x86_64` – parsecer Dec 6 '19 at 23:43
3

On Ubuntu, /usr/bin/psql is a symbolic link to a Perl script that figures out how to locate the default PostgreSQL instance to connect to, and then launches the real psql binary corresponding to that instance with the necessary connection parameters.

$ ls -l /usr/bin/perl
lrwxrwxrwx 1 root root 37 nov.  14 13:23 /usr/bin/psql -> ../share/postgresql-common/pg_wrapper

See the manual page of pg_wrapper for more details.

Based on the comments, the target of the link is broken somehow. Reinstalling the postgresql-client-common package might help.

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.