Postgres - 无法创建任何 TCP/IP 套接字

Jac*_*cka 14 postgresql

我正在使用 postgresql 9.3 运行一个正在开发的 rails 应用程序。当我今天尝试启动乘客服务器时,我得到:

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

我觉得没什么大不了的,以前发生过。重启 postgres 总能解决问题。所以我跑了sudo service postgresql restart,得到:

 * 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
...fail!
Run Code Online (Sandbox Code Playgroud)

Mypostgresql.conf指向 defaults:localhost和 port 5432。我尝试更改端口,但错误消息相同(端口更改除外)。

无论ps aux | grep postgresqlps aux | grep postmaster任何回报。

编辑:

postgresql.conf我换listen_addresses127.0.0.1,而不是localhost和它的伎俩,服务器重新启动。我还必须编辑我的应用程序的数据库配置并指向127.0.0.1而不是localhost. 然而,现在的问题是,为什么 localhost 被认为是217.74.65.145而不是127.0.0.1

那是我的/etc/hosts

127.0.0.1   local
127.0.1.1   jacek-X501A1
127.0.0.1   something.name.non.example.com
127.0.0.1   company.something.name.non.example.com
Run Code Online (Sandbox Code Playgroud)

Jen*_*y D 13

/etc/hosts的坏了。第一行应该是

127.0.0.1   localhost something.name.non.example.com company.something.name.non.example.com
Run Code Online (Sandbox Code Playgroud)