【发布时间】: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