如何解决psql错误:无法连接到服务器?

时间:2020-01-21 12:15:24

标签: postgresql psql

我正在尝试为我的网站安装GeoDjango。为此,我首先需要创建一个PostgreSQL数据库。在this tutorial之后,我尝试先使用sudo su - postgres然后使用psql连接到PostgreSQL。问题是我得到了这个错误: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"?

我进行了一些研究,发现this post解释了如何解决此问题。但是,当我运行sudo service postgresql start时,我必须输入postgres的密码,但是我不知道它是什么,所以我从未为postgres创建密码。我已经对此进行了研究,但找不到解决方案,因为所有解决方案都需要先连接到psql才能更改现有用户。但是我首先需要找到密码才能解决与psql的连接问题。

我该怎么办?

提前谢谢!

PS:我在Ubuntu终端上使用Windows 10。

PS2:我发现了一些主题,它们说使用Docker安装PostgreSQL和PostGIS更容易。但是,由于我使用的是Windows 10,因此Docker存在很多兼容性问题。您认为我应该使用Docker吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案!

因此,对于那些有兴趣的人,我必须更改密码才能登录并解决psql error: could not connect to server。要更改密码,只需键入sudo passwd postgres并设置一个新密码。我希望这会对其他人有所帮助!