当前位置: 动力学知识库 > 问答 > 编程问答 >

postgresql - How to connect to postgres with two terminals?

问题描述:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: