Postgresql 如何用两个终端连接postgres?

Postgresql 如何用两个终端连接postgres?,postgresql,Postgresql,我有一个终端可以连接到postgres psql testdb 但是,当我打开一个新选项卡或一个新终端并尝试连接到psql时,返回了一个错误 此错误返回 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"

我有一个终端可以连接到postgres

psql testdb
但是,当我打开一个新选项卡或一个新终端并尝试连接到psql时,返回了一个错误

此错误返回

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"?
我尝试创建另一个用户并使用另一个端口

createuser testing_multiple

psql -p 5433

出现相同的错误。

您的问题可能是您在
virtualenv
中工作。它不是
chroot
,但它设置了一组环境变量来伪造本地环境,很可能包括
路径
和其他设置

unix套接字很可能位于与编译到您正在使用的
psql
二进制文件中的位置不同的位置。我想说,您的PostgreSQL server套接字实际上可能位于
/tmp/.s.PGSQL.5433
,在这种情况下,
export-PGHOST=/tmp/
将起作用。由于您可以从virtualenv终端内进行连接,因此您可以在
psql
内进行检查,运行
SHOW unix\u socket\u目录。此处显示的位置是您可以在
PGHOST
中提供的连接到该PostgreSQL服务器的位置


export PGHOST=localhost
起作用的原因是您正在强制
psql
(以及使用
libpq
的其他客户端)通过TCP/IP连接,而不是默认的unix套接字连接。

可能有两个不同的psql二进制文件(IOS?)尝试定位psql二进制文件(在两个终端中)键入
哪个psql
我认为两者都返回
/usr/bin/psql
也许您在两台不同的机器上?(或VMs)或在chroot框架中…嗯,我使用的是
virtualenv
,但即使我尝试在同一个virtualenv文件夹中工作,新选项卡仍会返回错误为什么使用不同的端口号(默认5432),是否安装并运行了多个postgres实例?