postgresql - 在 Windows 10 和子系统 Ubuntu 中多次安装 Postgresql
问题描述
在我使用 windows 和 git bash 之前,已经安装了 Postgresql (13.1)。路径已添加:
并且效果很好。
后来,我必须使用 Ubuntu(Windows 子系统),然后我使用下面的命令在 Ubuntu 中安装 postgrel
sudo apt-get install postgresql
似乎已安装以下版本:
psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)
但是在 Ubuntu 中运行时:
psql
显示错误:
psql: error: 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"?
使用 echo $PATH 检查,添加了以下两个路径:
/mnt/c/Program Files/PostgreSQL/13/lib:/mnt/c/Program Files/PostgreSQL/13/bin
我看到的是Ubuntu已经安装了Postgrel 12.6,这个路径是不是也要加到系统路径中?事实上,我无法弄清楚 Postgrel 12.6 的添加位置。而这个错误真的是路径或者其他原因造成的吗?
解决方案
试过很多种方法。最后,下面的试验工作:
- 以管理员身份运行
- 删除旧的 postgresql
sudo apt-get remove postgresql
结果:
[sudo] password for user:
Reading package lists... Done Building dependency tree
Reading state information... Done
Package 'postgresql' is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
- 更新 spt
sudo apt update
结果:
Building dependency tree
Reading state information... Done
21 packages can be upgraded. Run 'apt list --upgradable' to see them.
sudo apt install postgresql postgrsel-contrib
结果:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package postgrsel-contrib
- 检查版本
psql --version
psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)
sudo service postgrel start
postgrel: unrecognized service
sudo apt-get install postgresql postgresql-client
结果:
Success. You can now start the database server using:
pg_ctlcluster 12 main start
- 再次
sudo service postgresql start
现在它显示:
starting postgresql 12 database (or similar sentence)
但没有提示 windows
\q 退出
- 使用以下重置密码:
sudo passwd postgres
您将收到设置密码的提示
- 由于 'sudo service postgresql start' 不起作用,请尝试以下启动 postgresql 服务:
su - postgres
现在它起作用了:
Password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 4.4.0-18362-Microsoft x86_64)
postgres=#
似乎
第 7 步有助于让服务器运行,
第 8 步将密码设置为 postgrel,
第 9 步提供了另一种在 sudo 命令不起作用时启动 postgres 服务的方法。
这些都是我的考验。运行时可能会跳过一些步骤。