Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 5499  / 3 Years ago, fri, july 16, 2021, 7:44:02

As a developer, I often ssh right into my local database, just to test my application before pushing my code.



However, I find that every time I want to access Postgres, I have to type in



postgres@ubuntu:~$ /usr/local/pgsql/bin/psql test


whereas on my work machine, all I have to do is type



postgres@ubuntu:~$ psql --dbname=test --username=user


I tried creating a symlink, which was successful, but whenever I try connecting to it through this shortcut, I get the following error message:



psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


How do I get this to work? In case it makes any difference, I'm using a self-compiled version of the 9.1.x series.



EDIT: I now know that this isn't really symlinking, but I'm not sure what it's called, or I'm sure I would have found it on Google already. Basically, I want it to run from the shell by typing in psql [OPTIONS] like rvm [OPTIONS] or ruby [OPTIONS].



I know there's a package named postgresql-client-common & a bunch of other Postgres packages through apt-get, but I would prefer not using the apt-get version so I can update Postgres on the fly.


More From » 12.04

 Answers
7

If it's just a matter of calling on psql directly you need to make sure the path "/usr/local/pgsql/bin" is included in $PATH when you are logging in. Oftentimes this has to do with setting the PATH variable appropriately in in /etc/profile (or ~/.profile) or if you are using bash, then this would be /etc/bashrc or ~/.bashrc.



e.g.



export PATH="$PATH:/usr/local/psql/bin"



Additionally.. the psql command expects the args as follow; psql <dbname> <username> (you can use --flags to specify the same).



If you supply "psql test"- then it will assume the username of the current user (as seen by whoami command).



Hope this helps.


[#39309] Friday, July 16, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aradxalte

Total Points: 70
Total Questions: 116
Total Answers: 116

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
;