PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 1, 2022

[FIXED] How can I solve the issue: psql cannot connect to the server in Ubuntu?

 August 01, 2022     django, postgresql, vps     No comments   

Issue

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


Solution

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



Answered By - Mohamed Abdillah
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing