繁体   English   中英

Ruby on Rails 4:当键入rails服务器时,得到错误消息PG :: ConnectionBad

[英]Ruby on Rails 4: when type rails server , got error message PG::ConnectionBad

我是Ruby on rails的新手。 我通过示例教程学习创建了基本的演示应用程序。

首先它工作正常,一周后我输入rails s时出错,

错误

PG::ConnectionBad
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"?

我正在使用PostgreSQL数据库。

我在MAC OS X 10.8.5上

我在SO上发现了类似的问题,但是他们正在经历一些提前阶段,因此涉及一些先进的解决方案。

当类型

which psql
/usr/local/bin/psql

似乎升级你的操作系统已经改变了Postgres保存其数据的目录的权限。

sudo chown -R sabir:staff /usr/local/var/postgres

使您的用户帐户成为该目录的所有者。 请求时输入密码; 输入时不会看到字符。

自制的Postgres版本包括自动启动的功能。 要检查您的安装是否存在,请运行

ls -l ~/Library/LaunchAgents/

您应该看到以homebrew.mxcl.postgresql.plist结尾的行。 如果您没有看到此行,请运行

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

为了让它自动启动。

最后,跑

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

确保Postgres现在处于活动状态。 通过键入确认

psql -l

使用自制软件安装postgres时,可能只是在前台手动启动它。 因此关闭终端窗口后,postgres不再运行了。

我建议你做以下的步骤:

  • 通过点击进程列表来检查postgres是否正在运行: ps aux | grep postgres ps aux | grep postgres
  • 如果它正在运行尝试sudo kill -9 {POSTGRES_PID}
  • 如果没有运行,请使用brew info postgres查看如何手动启动(或启动等)
  • 用自制的结果开始postgres - 在我的情况下postgres -D /usr/local/var/postgres

我希望,那会帮助你。 如果您在其他基础上安装了postgres,我可以相应地更改我的答案。

这可能是您的文件权限问题。

看看这个答案: https//stackoverflow.com/a/8481156/2417848

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM