【问题标题】:Postgres cannot connect to server on Unix domain socket 5432Postgres 无法连接到 Unix 域套接字 5432 上的服务器
【发布时间】:2013-01-20 18:08:23
【问题描述】:

使用 Postgres 9.2.2,当我尝试启动 rails 服务器或运行 psql 时,我不断收到此错误消息

could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

这个命令,当运行时:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

说服务器正在启动,但是当我去检查进程时,没有 postgres 进程正在运行

我的路径是正确的

$ which psql
/usr/local/bin/psql
$ which pg_ctl
/usr/local/bin/pg_ctl

如果我运行这个命令:

initdb /usr/local/var/postgres -E utf8

它将连接到套接字....但它也需要我删除我的数据库,这非常令人沮丧。每次重新启动时似乎都会发生这种情况。

使用

  • Postgres 9.2.2
  • 酿造
  • OSX 山狮

我在堆栈溢出时发现了类似的线程,但似乎没有一个解决方案有效。

【问题讨论】:

  • 这似乎是 OSX 上的常见问题,与升级和打包有关。看这里可能会回答:stackoverflow.com/a/8482546/905902BTW:如果服务器没有启动,它在日志中说什么? BTW2:你改变了位置/目录吗?
  • 你可能想试试postgresapp.com

标签: ruby-on-rails database ruby-on-rails-3 postgresql unix


【解决方案1】:

拧紧它。我刚刚安装了 Heroku 的 Postgres.app。没有更多的混乱问题。

【讨论】:

    【解决方案2】:

    我看到这个问题再次出现在实际安装了 Postgres.app 的人身上。不过,尚不清楚他为什么会抛出此错误,因为我以前从未在 Postgres.app 中看到过此错误。

    解决方案是更改 database.yml 文件:

    development: &default
      adapter: postgresql
      database: myapp_development
      encoding: utf8
      min_messages: warning
      pool: 5
      timeout: 5000
    
    test:
      <<: *default
      database: myapp_test
    

    收件人:

    development: &default
      adapter: postgresql
      database: myapp_development
      encoding: utf8
      min_messages: warning
      pool: 5
      timeout: 5000
      host: localhost
    
    test:
      <<: *default
      database: myapp_test
    

    唯一的区别是“主机”行

    【讨论】:

    • 听起来像是编译到客户端库和编译到服务器的套接字路径不同。放置“host: localhost”会修复它,因为它将使用 TCP/IP 套接字,可能放置“host: /path/to/socketdir”也会修复它,使用来自服务器的 unix_socket_dir。
    • @araqnid 感谢您提供更深入的回答,我总是想知道为什么我的修复确实有效!
    猜你喜欢
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 2015-11-14
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    相关资源
    最近更新 更多