I have to write this post as I have encountered the situation fews times in the recent past. So goes to some of my colleagues as well. The reason could be anything from improper shutdown, PIDs (process ids) issue, incompatible database files (after an upgrade) etc.
I have listed down step by step instructions solve some of these problems assuming that you have installed PostgreSQL using homebrew. If not you have to substitute the path with your custom installation path.
Step 1: The first step to solve any problem is looking at the logs first.
tail -f /usr/local/var/postgres/server.log
or the path to the log file if you have installed it in a different path.
The error could be anything but I have listed down some common problems and solution.
FATAL: lock file “postmaster.pid” already exists
HINT: Is another postmaster (PID 34263) running in data directory “/usr/local/var/postgres”
You can choose to kill the process using the command,
FATAL: database files are incompatible with server
HINT: The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.5.3
The problem could be because of your recent postgresql server.
- If you are not worried about your existing data then you can do the following,
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
- To migrate existing data from a pervious major version, please read this upgrading guide from PostgreSQL which will help you to back your data using
pg_dumpall > data_dump
which is quite useful.
Now its time to sart the server,
Run the following command from your terminal to start the server manually,
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log.start
and make sure its running by running
ps aux | grep postgres
pg_ctl -D /usr/local/var/postgres status