I am trying to create a Rails app that uses PostgreSQL. Here is a description of what I did.
PostgreSQL setup:
I installed PostgreSQL 9.1.3 via the ppa:pitti/postgresql maintained by Martin Pitt. There was PostgreSQL 8.4 installed before; I am not sure if it is still installed or gone.
sudo service postgresql start
.My postgres configuration in pg_hba.conf is as follows (removed comments for readability).
[...]
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
Rails setup:
Now I want to create a Rails application that uses PostgreSQL.
rails new my_test_app -d postgresql
.user
name and password
in config/database.yml for development and test and removed production.host: localhost
and port: 5433
in config/database.yml.Here is the content of my config/database.yml (removed comments for readability).
development:
adapter: postgresql
encoding: unicode
database: my_test_app_development
pool: 5
username: johndoe
password: password
host: localhost
port: 5433
test:
adapter: postgresql
encoding: unicode
database: my_test_app_test
pool: 5
username: johndoe
password: password
Problem:
However, when I run bundle exec rake db:create:all
I receive the following error message.
could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"?
[...]
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode",
"database"=>"my_test_app_test", "pool"=>5, "username"=>"johndoe",
"password"=>"password"}
Question:
Why is the port different to the one I use when I successfully connect via pgadmin3?
@Riateche: Finally, I saw that the database configuration for test environment misses the explicit settings for host and port. After I added the settings to the test environment, I was able to run the command bundle exec rake db:create:all
successfully.
I must say, I do not like that they suggest those settings for the development enviroment, but did not add them for the other environments. That makes it very likely to miss them, as I proofed.
test:
adapter: postgresql
encoding: unicode
database: my_test_app_test
pool: 5
username: johndoe
password: password
host: localhost
port: 5433