如何解决问题:PSQL无法连接到Ubuntu中的服务器?

发布于 2025-01-23 03:45:39 字数 877 浏览 0 评论 0原文

在使用PostgreSQL在VPS上托管我的Django Web应用程序时。但是,配置似乎很好,但是每当我想访问Postgres Shell时,我都会出现错误。

root@vmi851374:~# sudo su -l postgres
        postgres@vmi851374:~$ 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.5432"?
        postgres@vmi851374:~$


我已经检查了Postgres服务状态,一切似乎都很好,但我不知道此错误来自哪里。请注意,在我的Localhost(笔记本电脑)中,我没有面对这个问题。只有在VPS服务器中,我才会遇到此问题。

请帮助我解决这个问题。

In hosting my Django web application on VPS using PostgreSQl. However, the configuration seems to be fine but whenever I want to access the Postgres Shell, I ma getting the error bellow.

root@vmi851374:~# sudo su -l postgres
        postgres@vmi851374:~$ 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.5432"?
        postgres@vmi851374:~$

enter image description here
I have checked the Postgres service status and everything seems fine but I don't know where this error comes from. Notice that in my localhost (laptop), I am not facing this issue. Only in the VPS server, I am getting this issue.

Please assist me to solve this issue.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思念满溢 2025-01-30 03:45:39

执行:

sudo Systemctl状态Postgresql.Service

仅显示Bootstrap Process的状态PostgreSql.Service ran的状态。此过程用于启动实际的Postgres服务器或服务器。

要查看实际服务器是否正在运行:

pg_lsclusters

这将显示服务器的状态。

另一个选项是使用:

sudo systemctl状态PostgreSql@< -main.service

在其中您替换< version>,用Postgres Server的版本编号。

Doing:

sudo systemctl status postgresql.service

just shows whether the status of the bootstrap process postgresql.service ran. This process is used to start the actual Postgres server or servers.

To see whether the actual servers are running do:

pg_lsclusters

This will show the status of the server(s).

Another option is to to use:

sudo systemctl status postgresql@<version>-main.service

where you replace <version> with the version number of the Postgres server.

离去的眼神 2025-01-30 03:45:39

我通过编辑文件Postgresql.conf,位于/etc/postgresql/14/main/postgresql.conf中来解决问题。
然后,我没有按下并编辑lister_addresses属性以开始收听以开始收听所有可用的IP地址:ercy_addresses ='*'*'

此外,我还编辑了PostgreSQL访问策略配置文件,如下所示:

vim /etc/postgresql/14/main/pg_hba.conf. 

然后我修改了文件。如下:

host all all 0.0.0.0/0 md5

现在正常工作。非常感谢@adrianklaver

I solve the problem by editing the file postgresql.conf located in /etc/postgresql/14/main/postgresql.conf
Then I uncommented and edit the listen_addresses attribute to start listening to start listening to all available IP addresses: listen_addresses = '*'

In addition I edited the PostgreSQL access policy configuration file as follow:

vim /etc/postgresql/14/main/pg_hba.conf. 

Then I modified the file as follow:

host all all 0.0.0.0/0 md5

And now it is working fine. Thanks a lot @AdrianKlaver

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文