繁体   English   中英

Postgresql在Windows 10和子系统Ubuntu中的多重安装

[英]Multiple Installation of Postgresql in Windows 10 and subsystem Ubuntu

在我使用 windows 和 git bash 之前,已经安装了 ZC26C231D9E6ACBC7FF10118D1EZ2F3。 路径已添加:
在此处输入图像描述
而且效果很好。

后来,我必须使用 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 的添加位置。 而这个错误真的是路径或者其他原因造成的吗?

试过很多种方法。 最后,下面的试验工作:

  1. 以管理员身份运行
  2. 移除旧的 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. 
  1. 更新 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  
  1. 检查版本
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
  1. 再次
sudo service postgresql start

现在它显示:

starting postgresql 12 database (or similar sentence)

但是没有提示 windows
\q 退出

  1. 使用以下重置密码:
sudo passwd postgres

您将收到设置密码的提示

  1. 由于 '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 服务的方法。

这些都是我的考验。 运行时可能会跳过一些步骤。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM