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
“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.
First, double check that the Postgres process is running where you expect it to be. If you are trying to connect to a Postgres instance on the same host as your terminal, you can run lsof -p :5432 which will show which, if any, processes are listening on that port. The postgres process should be connected there.
When connecting to Postgres you might see this error: psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket <some socket> . This happens most often when Postgres' server daemon process is not running.
Try adding host: localhost
to your database.yml. (Based on: https://stackoverflow.com/a/10793186/919641)
Your Pg
gem was compiled against the PostgreSQL libpq pre-installed in Mac OS X and you're using the psql
that you installed in a newer version, or vice versa.
This can be worked around by specifying a TCP/IP connection, by adding localhost
to database.yml
, but it's better to compile the Pg
gem against the libpq
for the server you're actually running. To do that, you should be able to set the PATH
environment variable to the folder with the correct pg_config
in it before compiling. In your case that'll be somewhere within Postgres.app
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With