When I try to access postgres via a webapp, or open the postgres shell with psql -d template1, I get an error.
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've read a number of SO threads about this error, but recommended solutions did not fix this for me)
Start postgres as a service:
brew services restart postgresql
Stopping
postgresql... (might take a while) ==> Successfully stoppedpostgresql(label: homebrew.mxcl.postgresql) ==> Successfully startedpostgresql(label: homebrew.mxcl.postgresql)
Manually run postgres in a terminal:
I can get everything to work by running below in a terminal window, but I would prefer to run it in the background.
postgres -D /usr/local/var/postgres9.6.3
Clusters:
I have 3 db clusters in /usr/local/var, but I would like to use postgres9.6.3/
postgres
postgres9.5/
postgres9.6.3/
Which:
which psql returns /usr/local/bin/psql
Path:
echo $PATH returns /usr/local/bin and /usr/local/var (added)
Other recommended solutions:
A lot of people where able to fix this by removing a /postgres/postmaster.pid, but this file doesn't exist for me.
UPDATE
Running ps -ef | grep postgres, outputs only,
501 2135 1530 0 12:08pm ttys002 0:00.00 grep postgres
After restarting postgres with brew servies, postgres.log in /usr/local/var/log contains,
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 9.6.3.