The Homebrew package manager includes launchctl plists to start automatically. For more information, run brew info postgres
.
Start manually
pg_ctl -D /usr/local/var/postgres start
Stop manually
pg_ctl -D /usr/local/var/postgres stop
Start automatically
"To have launchd start postgresql now and restart at login:"
brew services start postgresql
What is the result of pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
?
What is the result of pg_ctl -D /usr/local/var/postgres status
?
Are there any error messages in the server.log?
Make sure tcp localhost connections are enabled in pg_hba.conf:
# IPv4 local connections:
host all all 127.0.0.1/32 trust
Check the listen_addresses and port in postgresql.conf:
egrep 'listen|port' /usr/local/var/postgres/postgresql.conf
#listen_addresses = 'localhost' # What IP address(es) to listen on;
#port = 5432 # (change requires restart)
Cleaning up
PostgreSQL was most likely installed via Homebrew, Fink, MacPorts or the EnterpriseDB installer.
Check the output of the following commands to determine which package manager it was installed with:
brew && brew list|grep postgres
fink && fink list|grep postgres
port && port installed|grep postgres
Check there is no postmaster.pid in your postgres directory, probably /usr/local/var/postgres/
remove this and start server.
Check - https://github.com/mperham/lunchy is a great wrapper for launchctl.
Best Answer
WARNING: If you delete postmaster.pid without making sure there are really no
postgres
processes running you, could permanently corrupt your database. (PostgreSQL should delete it automatically if the postmaster has exited.).SOLUTION: This fixed the issue--I deleted this file, and then everything worked!
--
and here is how I figured out why this needed to be deleted.
I used the following command to see if there were any PG processes running. for me there were none, I couldn't even start the PG server:
I searched for the file .s.PGSQL.5432 that was in the error message above. i used the following command:
this didn't show anything after searching my whole computer so the file didn't exist, but obviously
psql
"wanted it to" or "thought it was there".I took a look at my server logs and saw the following error:
at the end of the server log I see the following error:
Following the advice in the error message, I deleted the postmaster.pid file in the same directory as server.log. This resolved the issue and I was able to restart.
So, it seems that my macbook freezing and being hard-rebooted caused Postgres to think that it's processes were still running even after reboot. Deleting this file resolved. Hope this helps others! Lots of people have similar issues but most the answers had to do with file permissions, whereas in my case things were different.