0

I have a terminal I can connect to postgres

psql testdb

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

createuser testing_multiple

psql -p 5433

the same error occurs.

10
  • 1
    There might be two different psql binaries (IOS?) Try to locate the psql binary (in both terminals) type which psql Commented Oct 5, 2014 at 19:11
  • I think both returns /usr/bin/psql Commented Oct 5, 2014 at 19:12
  • Maybe you are on two different machines? (or VMs) or in a chroot cage ... Commented Oct 5, 2014 at 19:15
  • umm, I am using virtualenv but even when I tried to workon the same virtualenv folder the new tab will still return the error Commented Oct 5, 2014 at 19:16
  • Why do you use a different portnumber (from the default 5432), do you have more than one instance of postgres installed and running? Commented Oct 5, 2014 at 19:17

1 Answer 1

1

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 psql, run 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.