I created a new rails app with rails new app_name -d postgresql
and I am failing to use any rails command (rails s
, rails g controller ControllerName
, etc etc). I am getting these errors:
/Users/sebkomianos/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in ``initialize': could not connect to server: No such file or directory (PG::Error)
This is my database.yml
file:
development:
adapter: postgresql
encoding: unicode
database: project_development
pool: 5
username: project
password:`
test:
adapter: postgresql
encoding: unicode
database: project_test
pool: 5
username: project
password:`
production:
adapter: postgresql
encoding: unicode
database: project_production
pool: 5
username: project
password:`
I am having the exact same problem when I create the rails app with the standard rails new app_name
command and manually change the Gemfile
to use the pg gem
.
A couple of weeks ago I was on ruby2 and the app I created was working fine. Rails version is 3.2.13.
Any ideas?
UPDATE: The funny (at least to me) thing is that I have the application deployed to heroku and it runs fine there. Now, if I run rake db:create
everything seems to be working fine locally as well (no need to change anything in the database.yml
file). Maybe that makes my problem more clear?
You may need to specify the socket
argument in your config/database.yml
to specify the full path to the Postgres UNIX-type socket if that's what you're using. It may be in a non-standard location.
I usually avoid checking config/database.yml
into the project source repository as it causes conflicts with other people working on the same code-base that have different configurations. Include a database.yml.example
as a helpful template to get started instead.
Adding host: localhost
usually has the effect of forcing a TCP/IP connection instead, but this might not be working for you. Sometimes host: 127.0.0.1
works instead, as localhost
might be interpreted as "use default UNIX socket".