Here is my original error:
$ psql
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"?
and in Rails...
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
I've searched around and found about a dozen answers on this -- The underly issue is that when I shut down my computer /usr/local/var/postgres/postmaster.pid
does not get removed - implying postgres isn't shutdown properly. I've read that you should NOT delete the pid (as is often recommended) but instead kill it, even with kill -9
– but again, this is a temporary solution and suggests an underlying error.
EDIT: I could run cat /usr/local/var/postgres/postmaster.pid
the first line gives me the the process id. I had this wrong originally.
When I run tail -r /usr/local/var/postgres/server.log | less
to see the server log (in reverse) I get:
HINT: Is another postmaster (PID 1167) running in data directory "/usr/local/var/postgres"?
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 1167) running in data directory "/usr/local/var/postgres"?
FATAL: lock file "postmaster.pid" already exists
LOG: database system is shut down
LOG: shutting down
LOG: autovacuum launcher shutting down
LOG: received smart shutdown request
LOG: using stale statistics instead of current ones because stats collector is not responding
LOG: using stale statistics instead of current ones because stats collector is not responding
...
LOG: using stale statistics instead of current ones because stats collector is not responding
LOG: using stale statistics instead of current ones because stats collector is not responding
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: MultiXact member wraparound protections are now enabled
LOG: database system was shut down at 2016-05-25 17:36:26 MDT
LOG: database system is shut down
LOG: shutting down
LOG: autovacuum launcher shutting down
LOG: received smart shutdown request
It looks like the database shuts down correctly, but if it was I believe the postmaster.pid
file would be removed like it is when I run e.g. brew services stop postgres
.