小编Bot*_*ázs的帖子

如何从 WSL2 内部连接到 Windows 主机上运行的 Postgres?

我的 Windows 机器上运行着 Postgres,我需要从 WSL2 内部连接到它。

  • postgres windows 服务正在运行
  • 我可以使用 Windows 命令行连接到它 psql
  • WSL2 虚拟机的 IP 是172.31.210.120,网络掩码255.255.240.0(使用 确定ipfconfig)。
  • vm 内部的 windows 主机的 IP 是172.31.208.1(使用 确定cat /etc/resolv.conf
  • 我可以使用curl http://172.31.208.1:8080. 如果我记录传入请求的 IP,我会得到172.31.210.120这验证两个 IP 是否正确。
  • 我将以下行添加到pg_hba.confhost all all 172.31.210.120/20 scram-sha-256
  • 我重新启动了 postgres windows 服务

如果我尝试使用以下命令从 WSL 连接到它:

$ psql --host=172.31.208.1 --port=5432 --user=postgres
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

psql: error: could not connect to server: could not connect to server: Connection …
Run Code Online (Sandbox Code Playgroud)

postgresql linux windows windows-subsystem-for-linux

5
推荐指数
1
解决办法
3865
查看次数