我每次运行我的Rails应用程序时都会收到这个错误(它不能连接到我本地的Postgresql)
/Users/leonardo/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.11/lib/
active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize':
could not connect to server: No such file or directory (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
我使用的是,它运行正常。
如果我运行
$ psql
我可以正常登录Postgresql控制台。
$ which psql
/Applications/Postgres.app/Contents/MacOS/bin/psql
Gemfile
source 'https://rubygems.org'
ruby "1.9.3"
gem 'rails', '3.2.11'
gem "pg"
database.yml
development:
adapter: postgresql
encoding: unicode
username: leonardo
password:
database: zapping
port: 5432
Postgresql (控制台)
$ psql
leonardo=# \l
发布于 2013-01-09 06:40:02
尝试将host: localhost
添加到您的database.yml。(基于:https://stackoverflow.com/a/10793186/919641)
发布于 2013-01-09 11:12:13
您的Pg
gem是根据Mac中预先安装的PostgreSQL libpq编译的,并且您使用的是在较新版本中安装的psql
,反之亦然。
这可以通过指定一个TCP/IP连接来解决,也可以通过将localhost
添加到database.yml
中来解决,但是最好针对您实际运行的服务器的libpq
编译Pg
gem。为此,您应该能够在编译前将PATH
环境变量设置为其中包含正确pg_config
的文件夹。在您的情况下,这将在Postgres.app
中的某个位置。
发布于 2017-06-25 08:06:09
如果添加host: localhost
后仍不起作用,请删除postmaster.pid
rm /usr/local/var/postgres/postmaster.pid
https://stackoverflow.com/questions/14225038
复制相似问题