spa*_*kle 65 postgresql ruby-on-rails pg rails-postgresql
每次运行我的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"?
Run Code Online (Sandbox Code Playgroud)
我正在使用Postgres.app,它正确运行.
如果我跑
$ psql
Run Code Online (Sandbox Code Playgroud)
我可以正确登录到Postgresql控制台.
$ which psql
/Applications/Postgres.app/Contents/MacOS/bin/psql
Run Code Online (Sandbox Code Playgroud)
的Gemfile
source 'https://rubygems.org'
ruby "1.9.3"
gem 'rails', '3.2.11'
gem "pg"
Run Code Online (Sandbox Code Playgroud)
database.yml的
development:
adapter: postgresql
encoding: unicode
username: leonardo
password:
database: zapping
port: 5432
Run Code Online (Sandbox Code Playgroud)
Postgresql(控制台)
$ psql
leonardo=# \l
Run Code Online (Sandbox Code Playgroud)
Cra*_*ger 25
您的Pg
gem是针对预装在Mac OS X中的PostgreSQL libpq编译的,并且您使用的psql
是在较新版本中安装的,反之亦然.
这可以通过添加localhost
到指定TCP/IP连接来解决database.yml
,但最好是Pg
针对libpq
您实际运行的服务器编译gem .为此,您应该能够在编译之前将PATH
环境变量设置为正确的文件夹pg_config
.在你的情况下,它将在某个地方Postgres.app
.
小智 24
如果添加后仍无效host: localhost
,请将其删除postmaster.pid
rm /usr/local/var/postgres/postmaster.pid
我在Mac上遇到了同样的问题.事实证明我在我的路径上的psql无法正常工作.尝试键入以下命令启动psql:
~/projects/some_project/project-rails$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)
如果您看到这一点,则表示路径上的psql二进制文件正在尝试使用套接字进行连接而无法执行此操作(无论出于何种原因).由于我已经下载了pgadmin并且连接正常,我知道这不是服务器的问题.
通过向我的PATH添加正确版本的pgsql来修复它:
export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
现在psql(和rails)很高兴!
小智 6
我有同样的问题.你必须实际运行/启动postgres.Postgres最近必须停止在我的计算机上运行,所以我必须通过启动postgres服务器来确保它正在运行
postgres -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)
然后以下命令(导致我有同样的错误)全部起作用:
bundle exec rake db:create db:migrate
bundle exec rspec
Run Code Online (Sandbox Code Playgroud)
我有这个问题。这里的评论之一帮助我解决了这个问题。
谢谢,这个答案帮助我解决了它。我采取的步骤很简单:1)gem install pg,2)捆绑安装,完成。– haslo 2013年12月3日20:27
gem uninstall pg
bundle install
Run Code Online (Sandbox Code Playgroud)
由于这是我的搜索结果中出现的第一篇帖子,因此我决定发布更新后的修复程序.由于以上建议都不适合我.
brew postgresql-upgrade-database
Run Code Online (Sandbox Code Playgroud)
它升级了postgresql数据并移动了我的旧版本.我在9.6而不是10.4
在这里找到解决方案
找到/ -name'postgresql.conf'
netstat -an | grep 5432 #=> /tmp/.s.PGSQL.5432
vi /用户/管理员/库/应用程序\支持/Postgres93/var/postgresql.conf
FROM: unix_socket_directories ='/ tmp'
到: unix_socket_directories ='/ var / pgsql_socket'
须藤mkdir / var / pgsql_socket
须藤chmod 777 / var / pgsql_socket
归档时间: |
|
查看次数: |
68353 次 |
最近记录: |