如何解决问题:PSQL无法连接到Ubuntu中的服务器?
在使用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:~$
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行:
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.我通过编辑文件
Postgresql.conf
,位于/etc/postgresql/14/main/postgresql.conf
中来解决问题。然后,我没有按下并编辑lister_addresses属性以开始收听以开始收听所有可用的IP地址:
ercy_addresses ='*'*'
此外,我还编辑了PostgreSQL访问策略配置文件,如下所示:
然后我修改了文件。如下:
现在正常工作。非常感谢@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:
Then I modified the file as follow:
And now it is working fine. Thanks a lot @AdrianKlaver