How do I fix stale postmaster.pid file on Postgres?
Mar 18
I went to view a postgres schema on my local (MacOS 11) database, and was not able to view my schemas. Connection Refused in PGSQL Editor! (DBeaver specifically)
So I opened my Postgres desktop application, and got the warning message, "Stale postmaster.pid file"
How can I fix this?
(This example is Postgres 12, but i'm sure this fix will work on later versions)
1 answer
Accepted answer · original discussion
Mar 18
The problem is that the postmaster.pid file needs to be removed manually and then regenerated by Postgres. These are the steps to do remove it. (for MacOs, linux also probably pretty close to this)
Keep in mind the version might changed, (var-12, could be var-13,var-14,var-15 etc). But the general theory remains the same for now. Just swap the 12 for your version. We will use 12 as the example as that was i was working with at the time.
- Open your terminal, and cd into the postgres directory:
cd /Users/$USER/Library/Application\ Support/Postgres - Make sure you're in the right place, run
ls, you should see a directory likevar-12 - Verify the PID file is inside that "
var-12" directory usingls: e.g.ls var-12/
Library/Application Support/Postgres
➜ ls var-12
PG_VERSION pg_hba.conf
pg_replslot pg_subtrans
postgresql.auto.conf base
pg_ident.conf pg_serial
pg_tblspc postgresql.conf
global pg_logical
pg_snapshots pg_twophase
postgresql.log pg_commit_ts
pg_multixact pg_stat
pg_wal postmaster.opts
pg_dynshmem pg_notify
pg_stat_tmp pg_xact
postmaster.pid <--- (This is what you're looking for!)
- Before you remove the file, verify the Postgres server is not running by viewing desktop app or CLI. Terminate Postgres server if needed
- Then remove
postmaster.pid, e.g.rm var-12/postmaster.pid - Go back to your console, start your Postgres server, and it should regenerate the PID, and it should start successfully and you will have full access to your schemas.
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.