首页 > 解决方案 > 无法连接到在 Windows 10 虚拟机中运行的 postgresql 服务器

问题描述

我正在我的 pop-os 笔记本电脑上的 Windows 10 虚拟机中运行 postgres 服务器。我正在尝试从我的主机操作系统(linux)连接到它。在虚拟框中,我创建了一个端口转发规则:

在此处输入图像描述

我还将 postgres 配置中的侦听端口更改为等于“*”。

我尝试连接的错误消息是这样的:

postgres@pop-os:/home/peyton$ psql -p 5432
psql: error: could not connect to server: 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"?

我不太了解这一点,所以我真的可以使用一些帮助。

谢谢。

标签: linuxwindowspostgresqlvirtualboxconnect

解决方案


问题是:

psql -p 5432

是说连接到Linux机器上的本地套接字。根据错误消息:

Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

您需要执行以下操作:

psql -p 5432 -h 127.0.0.1


推荐阅读