0

Maybe this Question repeat but I am not getting any solution I am using centos 7 and Postgres 9.3. While connecting the PostgreSQL server it through error,

Error

Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connection on port 5432

Even I set pg_hba.config file but still I am getting the same error I tried to remove postmaster.pid but I got an error no such file and no pid exist Please tell me the solution

Vivek S.
  • 19,945
  • 7
  • 68
  • 85

2 Answers2

0

I have the same problem and I solved this with the explanation:

"Wild stab in the dark: You're on a machine with an IPv6 resolver where localhost defaults to the IPv6 address ::1, but listen_addresses in postgresql.conf is set to 127.0.0.1 or 0.0.0.0 not * or you're using an older PostgreSQL built with a C library that doesn't have transparent IPv6 support.

Change listen_addresses to localhost and make sure localhost resolves to both the IPv4 and IPv6 addresses, or set it to ::1, 127.0.0.1 to explicitly specify both IPv4 and IPv6. Or just set it to * to listen on all interfaces. Alternately, if you don't care about IPv6, connect to 127.0.0.1 instead of localhost."

Reference link here.

I think this post can help you too.

Community
  • 1
  • 1
Sayuri Mizuguchi
  • 5,250
  • 3
  • 26
  • 53
0

Try checking whether firewall allow connection on that port.
If on Ubuntu command sudo ufw status
the result wil be like this

To                         Action      From
--                         ------      ----
22                         LIMIT       Anywhere                  
443                        ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
8000                       ALLOW       Anywhere                  
Nginx Full                 ALLOW       Anywhere                  

You can see that port 5432 is not allowed.
Now run command sudo ufw allow 5432/tcp and check ufw status
sudo ufw status will now return

22                         LIMIT       Anywhere                  
443                        ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
8000                       ALLOW       Anywhere                  
Nginx Full                 ALLOW       Anywhere                  
5432/tcp                   ALLOW       Anywhere      

If this doesn't work you may probably haven't allowed IP to listen to postgres.
Change listen_address = 'localhost' to listen_address = '*' in postgres.conf file.

Rajan Chauhan
  • 1,378
  • 1
  • 13
  • 32