【问题标题】:Trouble installing postgresql on osx using homebrew使用自制软件在 osx 上安装 postgresql 时遇到问题
【发布时间】:2015-12-04 13:40:10
【问题描述】:

我当时正在尝试在新机器上安装 postgres。我最初运行了thoughtbot 的laptop 脚本来安装rails 开发所需的大部分内容,其中应该包括postgres 安装。然而,当我为新的 rails 应用程序运行 rake db:create 时,出现以下错误:

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "pool"=>5, "timeout"=>5000, "username"=>"riskpool", "password"=>nil, "database"=>"riskpool_development"}
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"?

我尝试像这样通过自制软件卸载并重新安装 postgres,结果如下:

$ brew remove postgres                                                                                                                       
Uninstalling /usr/local/Cellar/postgresql/9.4.5_2... (3021 files, 40M)

并重新安装 postgres

$ brew install postgres
==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.4.5_2.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.4.5_2.yosemite.bottle.tar.gz
==> Pouring postgresql-9.4.5_2.yosemite.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall postgresql`
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.4/static/upgrading.html

To load postgresql:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
  postgres -D /usr/local/var/postgres

WARNING: launchctl will fail when run under tmux.
==> Summary
????  /usr/local/Cellar/postgresql/9.4.5_2: 3021 files, 40M

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist                                                                      
/usr/local/Cellar/postgresql/9.4.5_2/homebrew.mxcl.postgresql.plist: Operation not permitted

如果我运行第二个命令

$ postgres -D /usr/local/var/postgres
FATAL:  could not open directory "pg_tblspc": No such file or directory

如果我试图找出 postgres 的安装位置:

$ which postgres
/usr/local/bin/postgres

有人建议我终止可能会干扰的现有进程 ID:

$ rm /usr/local/var/postgres/postmaster.pid                                                                                                   
rm: /usr/local/var/postgres/postmaster.pid: No such file or directory

但我得到了同样的错误

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"?

【问题讨论】:

  • 当你在 Mac OSX 上时,确保你的 config 文件夹中的 database.yml 文件没有更多的行,所以不要指定用户名和密码。默认情况下,它将是您系统中的用户。请参阅Important Note About Authentication for postgres on mac 部分中的此页面
  • @JuanM。为什么因为在 Mac OSX 上? linux上的postgres是否有不同的用户名和密码默认值?
  • 我没有在 linux 上尝试过,但如果你在 windows 上,你会在配置地狱中运行 postgres。在windows中你必须做一些其他的配置,比如使用postgres提供的软件来创建用户和权限等等。在 mac 中,它就像使用 ... -d postgresql 选项创建应用程序一样简单,并且可以毫无问题地工作。您的问题不是我认为的安装,而是为您的项目创建数据库。

标签: ruby-on-rails macos postgresql


【解决方案1】:

您是否尝试过使用此命令:

rm /usr/local/var/postgres/postmaster.pid

此文件似乎阻止 postgres 启动,这就是您收到以下错误的原因:

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"?

【讨论】:

  • 编辑了帖子以反映我的尝试。好像没用。
【解决方案2】:

您是否尝试过以 root 权限启动服务器?即

sudo postgres -D /usr/local/var/postgres

似乎由于文件权限特权而导致服务器未启动。 brew postinstall 脚本似乎也失败了,因此您可能需要初始化 db 集群。 您可以使用 initdb 创建一个新集群。

sudo initdb /usr/local/var/postgres9.4

或者,如果这是用于开发机器,我建议只使用适用于 macosx 的 postgres 应用程序(只需单击并运行): http://postgresapp.com/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 2012-10-29
    相关资源
    最近更新 更多