【问题标题】:Why can't I use postgres even when it is running? [duplicate]为什么即使在运行时我也不能使用 postgres? [复制]
【发布时间】:2012-11-26 23:58:19
【问题描述】:

可能重复:
PostgreSQL Permission denied Error on Unix domain socket “/var/pgsql_socket/.s.PGSQL.5432” - Lion Server 10.7.3 or Lion Server 10.7.4

我使用 postgres 作为 Rails 的后端数据库,但由于配置错误问题已停止工作,但我看不到它是什么。

我的postgres版本是9.1.4,安装在/usr/bin

我正在运行 ruby​​ 版本 1.9.3,但我必须在 rvm 中手动切换到它,因为出现的是默认的 1.8.7。

我正在运行 Rails 3.2.8

我的配置文件 pg_hba.conf 看起来像:

# "local" is for Unix domain socket connections only
local   all         all                               md5
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5

postgres.conf 文件中的大多数行都被注释掉了,除了一些无害的行,例如:

log_destination = 'stderr'
listen_addresses = '*'   
port = 5432                             
max_connections = 100                  

我还为 Mac 安装了“Postgres 应用程序”(参见 postgresapp.com/documentation),它说它正在端口 5432 上运行和侦听。

当我运行 ps -ax |我看到的 grep 帖子:

1088 ??         0:00.08 com.heroku.postgres-service
 1135 ??         0:00.29 /Applications/Postgres.app/Contents/MacOS/bin/postgres -D /Users/rickc/Library/Application Support/Postgres/var -p5432
 1137 ??         0:01.14 postgres: writer process      
 1138 ??         0:00.78 postgres: wal writer process      
 1139 ??         0:00.20 postgres: autovacuum launcher process      
 1140 ??         0:00.26 postgres: stats collector process      

但是当我尝试在 localhost:3000 启动 rails connect 时,我收到以下错误消息: PG::错误

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

我已经尝试在这里检查以前的帖子,当然,postgres 文档看不到这里配置错误的地方;非常感谢任何帮助...

【问题讨论】:

  • 你检查过unix域套接字是否位于var/psql_socket/吗? (这是一个奇怪的地方,顺便说一句)
  • 您是否阅读了问题中提到的postgresapp 页面上的rails 部分?根据错误消息,您没有按照本页的建议将config/database.yml中的db主机设置为localhost
  • 关于/var/pgsql_socket:这是MacOS X 路径。在 MacOS X 上如此常见的问题是程序员使用默认情况下未配置的客户端设置与他们的服务器设置对话,因为其中有几个可供下载。他们认为“安装 postgresql”就足够了,并没有意识到他们负责连接客户端部分和服务器部分之间的点。
  • /var/psql_socket 中没有任何内容。似乎是另一个错误配置。

标签: ruby-on-rails postgresql database-connection


【解决方案1】:

这是一个 postgres 问题,而不是 rails/ruby 问题。

为了证明给自己看,打开一个终端然后做

psql -U username -W db_name

username 是您的用户名,db_name 是数据库的名称。

您应该收到“无法连接到服务器”错误。

这就是你要做的:

  • tail您的 postgres 登录终端窗口
  • 重启 postgres 并观察终端

您将在日志中看到问题。如果您无法找出问题所在,请发布日志的相关部分,我们会查看。

【讨论】:

    猜你喜欢
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2021-10-14
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多