无法连接到服务器:Linux 的 Windows 子系统中 ubuntu 上的 postgresql

Sha*_*wat 8 linux windows postgresql ubuntu windows-subsystem-for-linux

我在 ubuntu 18.04 发行版中使用 WSL,在我点击的 bash 中,sudo -u postgres 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/run/postgresql/.s.PGSQL.5433"?
Run Code Online (Sandbox Code Playgroud)

然后我尝试了其他 postgres 操作,例如:sudo -u createdb mydb 只得到相同的错误。

请指教。

ben*_*nvc 10

在 Linux 的 Windows 子系统中的 Ubuntu 上运行 PostgreSQL 时,您可能必须手动启动数据库服务器才能连接。使用下面的命令启动你的数据库服务器,然后尝试连接。

sudo service postgresql start

或者

sudo /etc/init.d/postgresql start

您还可以使用以下命令检查数据库服务器的状态:

sudo service postgresql status