Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a rails app in development with postgresql 9.3. When I tried to start passenger server today, I got:

PG::ConnectionBad - could not connect to server: Connection refused
    Is the server running on host "localhost" ( and accepting
    TCP/IP connections on port 5432?

No big deal I thought, that happened before. Restarting postgres always solved the problem. So I ran sudo service postgresql restart and got:

 * Restarting PostgreSQL 9.3 database server
 * The PostgreSQL server failed to start. Please check the log output:
2014-06-11 10:32:41 CEST LOG:  could not bind IPv4 socket: Cannot assign requested address
2014-06-11 10:32:41 CEST HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2014-06-11 10:32:41 CEST WARNING:  could not create listen socket for "localhost"
2014-06-11 10:32:41 CEST FATAL:  could not create any TCP/IP sockets!

My postgresql.conf points to the defaults: localhost and port 5432. I tried changing the port but the error message is the same (except the port change).

Both ps aux | grep postgresql and ps aux | grep postmaster return nothing.


In postgresql.conf I changed listen_addresses to instead of localhost and it did the trick, server restarted. I also had to edit my applications' db config and point to instead of localhost. However, the question is now, why is localhost considered to be and not

That's my /etc/hosts:   local   jacek-X501A1
share|improve this question
Does your postgresql.conf define listen_addresses? – Flup Jun 11 '14 at 8:38
See the edited question please. – Jacka Jun 11 '14 at 8:44
any output from sudo netstat -anlp | grep 5432? – Flup Jun 11 '14 at 8:45
If you're going to obfuscate your data, please do so responsibly and use as the domain name. – Jenny D Jun 11 '14 at 9:06
up vote 5 down vote accepted

Your /etc/hosts is broken. The first line should read   localhost
share|improve this answer
Thanks, it solved the problem :) – Jacka Jun 11 '14 at 9:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.