Reputation: 405
I recently updated my machine (MacBook Pro running Mountain Lion) and ever since then, whenever I set up a rails project, my machine craps out and cannot connect to PG. Currently, this is the error I am getting when I try to go to localhost;
PG::ERROR could not connect to server: Connection refused Is the server running on host "localhost"
(::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection
refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432?
Here is a checklist, and list of things I have tried;
host: localhost
in my database.yml filebrew uninstall postgresql
then brew install postgresql
Ran locate pg_hba.conf
and terminal shot this out;
WARNING: The locate database (/var/db/locate.database) does not exist.
I have also tried using rails 4.0 but I still get the problem
I can still work on other projects on my machine that were started/finished before I updated my computer.
When I run psql
from my terminal I get
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I am really lost here, and am not sure what else to do. Any help would be much appreciated.
UPDATE:
Thanks to this question, all was resolved by simply downloading Postgres.app for Mac. Everything works great now.
Upvotes: 19
Views: 53559
Reputation: 1198
This is easier than you think because if you update your Mac then the process will run, but the postmaster.pid
file is missing from /usr/local/var/postgres/
. So you need to start process for postgres which creates postmaster.pid.
If postgres is running then:
Stop manually:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
Start manually:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Now all should be working.
Upvotes: 24
Reputation: 403
if you have installed through brew
$ brew services stop postgresql
#adjust below path accordingly to your machine
$ rm /usr/local/var/postgres/postmaster.pid
$ brew services start postgresql
Upvotes: 13
Reputation: 639
For M1 systems, /usr/local/ files are moved to /opt. Hence, homebrew installs postgres at /opt/homebrew/var/postgres.
Trying to start the server manually by,
pg_ctl -D /opt/homebrew/var/postgres -l /opt/homebrew/var/postgres/log start
Then try to check if server is running,
pgrep -l postgres
If above cmd outputs, server is running fine. Try to find the server connection,
sudo find /tmp/ -name .s.PGSQL.5432
Then connect to db by,
psql -h /tmp/ databaseName
Upvotes: 2
Reputation: 1126
Run in your command line
postgres -D /usr/local/var/postgres
If the result is like the next one
LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 10, which is not compatible with this version 11.
Run
brew postgresql-upgrade-database
Based in this post
Upvotes: 24