问题
I recently upgraded to ubuntu 11.10 and whenever I run my rails server I keep getting this error:
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"?
Prior to the upgrade the database was working fine with rails 3.0. How can I fix this?
回答1:
Fixed it. The problem was that postgresql was listening on 5433 instead of 5432. Just changed the port in the database.yml file.
回答2:
This is the standard error message, when the server cannot be found. Mostly this simply means that you haven't started the server (with your database cluster at the standard port 5432).
On Ubuntu with postgres 9.1, if you installed correctly, you would:
pg_ctl start
You will have to be user root
or postgres
for that. Or the general way to do it:
sudo /etc/init.d/postgresql-9.1 start
If Ubuntu installs the Debian wrapper by Martin Pitt (that's standard in Debian, not sure about Ubuntu):
pg_ctlcluster 9.1 main start
More info
- Ubuntu help site for PostgreSQL
- Ubuntu manual on PostgreSQL
- PostgreSQL manual here or here
- Or, of course:
man pg_ctl
回答3:
It seems that some linux distributions supply a postgresql server with the unix domain socket in a different place than usual ( /tmp ). For psql you can supply the path_to_the_socket via the -h parameter, e.g:
psql -h /tmp/ mydatabasename
(you could use this to test if it actually works) Maybe ruby has a way to supply the same setting in one of its connector settings.
来源:https://stackoverflow.com/questions/7861867/why-is-postgresql-9-1-not-working-with-rails-3-0