PostgreSQL适配器(PG):无法连接到服务器 [英] Postgresql adapter (pg): could not connect to server

查看:207
本文介绍了PostgreSQL适配器(PG):无法连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每运行一次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' :
无法连接到服务器:没有这样的文件或目录(PG :: Error)
服务器是否在本地运行并且在Unix域套接字 /var/pgsql_socket/.s上接受
连接.PGSQL.5432?

我正在使用)


I get this error every this I run my Rails app (It cannot connect to my local 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"?

I'm using Postgres.app that it's correctly running.

If I run

$ psql

I can login properly to Postgresql console.

$ 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 (Console)

$ psql
leonardo=# \l

解决方案

Try adding host: localhost to your database.yml. (Based on: https://stackoverflow.com/a/10793186/919641)

这篇关于PostgreSQL适配器(PG):无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆