I have a terminal I can connect to postgres
but when I open a new tab or a new terminal and tried to connect to psql an error is returned
This error returns
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5433"?
I tried creating another user and using another port
psql -p 5433
the same error occurs.
Your issue is probably that you're working within
virtualenv. It isn't a
chroot, but it sets a bunch of environment variables to fake the local environment, quite likely including the
PATH and other settings.
Most likely the unix socket is at a different location to that compiled into the
psql binary you're using. I'd say your PostgreSQL server socket is probably actually at
/tmp/.s.PGSQL.5433, in which case
export PGHOST=/tmp/ will work. Since you can connect from within the virtualenv terminal you can check though - within
SHOW unix_socket_directories;. The location shown there is what you can give in
PGHOST to connect to that PostgreSQL server.
The reason that
export PGHOST=localhost works is that you are forcing
psql (and other clients that use
libpq) to connect over TCP/IP, instead of the default unix socket connection.