无法使用自制程序在osx上安装postgresql

时间:2015-12-04 13:40:11

标签: ruby-on-rails macos postgresql

我试图在新机器上安装postgres。我最初运行了思想机器人的laptop脚本来安装大部分我需要的rails开发,这应该包括postgres安装。然而,当我为新的rails app运行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"?

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

您是否尝试使用root权限启动服务器?即

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

由于文件权限特权,服务器似乎没有启动。 似乎brew postinstall脚本失败,因此您可能需要初始化数据库集群。 您可以使用initdb创建新集群。

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

或者,如果这是用于开发机器,我建议只使用postgres app for macosx(简单点击并运行): http://postgresapp.com/