The data directory contains an unreadable postmaster.pid file on PostgreSQL 12 | Mac OS
Common errors on Postgres.app
The data directory contains an old postmaster.pid file / The data directory contains an unreadable postmaster.pid file
Reason
PostgreSQL puts a file named postmaster.pid
in the data directory to store the process id of the PostgreSQL server process. If PostgreSQL crashes, this file can contain an old pid that confuses PostgreSQL. You can fix this issue by deleting the postmaster.pid
file. However, you must make sure that PostgreSQL is really not running. Open Activity Monitor and make sure that there are no processes named ‘postgres’ or ‘postmaster’.
If you delete the postmaster.pid
file while PostgreSQL is running, bad things will happen. Let’s start fixes it by following step by step
Step 1 : Find Postgres directory with your current version
Open your terminal and make sure you’re in the home directory.
PostgreSQL version 12
$ cd ~/Library/Application\ Support/Postgres/var-12
or PostgreSQL version 11
$ cd ~/Library/Application\ Support/Postgres/var-11
Step 2: Delete the postmater.pid file
The last step is to remove the postmaster.pid file.If PostgreSQL crashes, this file can contain an old pid that confuses PostgreSQL. You can fix this issue by deleting the postmaster.pid
file. However, you must make sure that PostgreSQL is really not running.
$ rm -f postmaster.pid
Final step: Restart services the Postgres
You can right click on icon Postgres.app on toolbar with quit or follow by command line
$ pg_ctl -D /usr/local/var/postgres restartwaiting for server to shut down.... done
server stopped
waiting for server to start.....2020-08-28 11:21:42.654 +07 [21151] LOG: starting PostgreSQL 12.2 on x86_64-apple-darwin18.7.0, compiled by Apple clang version 11.0.0 (clang-1100.0.33.17), 64-bit
2020-08-28 11:21:42.661 +07 [21151] LOG: listening on IPv6 address "::1", port 5432
2020-08-28 11:21:42.661 +07 [21151] LOG: listening on IPv4 address "127.0.0.1", port 5432
2020-08-28 11:21:42.662 +07 [21151] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-08-28 11:21:42.809 +07 [21152] LOG: database system was shut down at 2020-08-28 11:21:40 +07
2020-08-28 11:21:42.830 +07 [21151] LOG: database system is ready to accept connections
done
server started
In conclusion
I’m sure, the information above will be useful for you. But there are hundreds of other creative people whom it might be useful for as well. So Clap! Clap! :)👏🏼