【问题标题】:Ruby on Rails 4: when type rails server , got error message PG::ConnectionBadRuby on Rails 4:输入 rails server 时,收到错误消息 PG::ConnectionBad
【发布时间】:2015-02-17 11:03:20
【问题描述】:

我是 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/postmaster.pid 试试看,你最近有没有升级你的操作系统
  • 您能告诉我们您是如何安装 Postgres 的吗?例如,您使用的是自制软件吗?如果您可以在终端中运行命令 which psql 并将结果添加到您的问题中,那就太好了。
  • 尝试检查这个 Start Postgres: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Stop Postgres: pg_ctl -D /usr/ local/var/postgres stop -s -m fast
  • 是的 Sontya,我升级了操作系统
  • 我用自制软件安装 psql

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


【解决方案1】:

升级你的操作系统似乎改变了 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

【讨论】:

  • 当我输入launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  • launchctl: Dubious permissions on file (skipping): /Users/Sabir/Library/LaunchAgents/homebrew.mxcl.postgresql.plist nothing found to unload
  • 您是否执行了第二条命令launchctl loadpsql -l 有效吗?如果没有,请发布ls -lh ~/Library/LaunchAgents的输出
  • ls -lh ~/Library/LaunchAgentstotal 40 -rw-r--r-- 1 Sabir staff 697B 12 Dec 10:43 com.adobe.AAM.Updater-1.0.plist -rw-r--r-- 1 Sabir staff 425B 5 Jan 22:53 com.apple.FolderActions.enabled.plist -rw-r--r-- 1 Sabir staff 517B 17 Feb 08:22 com.apple.FolderActions.folders.plist -r-xr-xr-x 1 Sabir staff 457B 10 Dec 21:39 com.citrixonline.GoToMeeting.G2MUpdate.plist lrwxr-xr-x 1 Sabir staff 56B 17 Feb 20:11 homebrew.mxcl.postgresql.plist -> /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist的输出
  • launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist out is launchctl: Dubious permissions on file (skipping): /Users/Sabir/Library/LaunchAgents/homebrew.mxcl.postgresql.plist nothing found to load
【解决方案2】:

当您使用自制软件安装 postgres 时,也许您只是在前台手动启动它。所以关闭终端窗口后,postgres 不再运行。

我建议执行以下步骤:

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

希望对你有所帮助。 如果您在另一个基础上安装了 postgres,我可以相应地更改我的答案。

【讨论】:

  • postgres -D /usr/local/var/postgres 致命:数据目录“/usr/local/var/postgres”的所有权错误提示:服务器必须由拥有数据的用户启动目录。
  • @MarySmith 请运行ls -l /usr/local/var/postgres 并告诉我们结果。另外,请运行whoami,它会返回您的 Mac 用户名。
  • 运行ls -l /usr/local/var/postgrestotal 1288 -rwxrwxrwx 1 root wheel 4 28 Aug 15:22 PG_VERSION drwxrwxrwx 51 root wheel 1734 28 Nov 16:42 base drwxrwxrwx 43 root wheel 1462 23 Jan 10:26 global drwxrwxrwx 3 root wheel 102 28 Aug 15:22 pg_clog -rwxrwxrwx 1 root wheel 4467 28 Aug 15:22 pg_hba.conf -rwxrwxrwx 1 root wheel 1636 28 Aug 15:22 pg_ident.conf drwxrwxrwx 4 root wheel 136 28 Aug 15:22 pg_multixact drwxrwxrwx 3 root wheel 102 23 Jan 10:25 pg_notify ---------- -----
  • 运行 whoami 显示我的用户名
  • @MarySmith 我知道,但我需要知道您的用户名 :) 另外,您可以在回答我的 cmets 时写上@janfoeh(不带空格)吗?这样,SO 会通知我您的回复。
猜你喜欢
  • 2017-12-19
  • 1970-01-01
  • 1970-01-01
  • 2014-04-28
  • 2013-01-13
  • 1970-01-01
  • 2015-07-30
  • 2021-08-18
  • 2019-07-06
相关资源
最近更新 更多