Diagnostic Queries
Symptoms
The server found an existing lock/PID file when starting, suggesting another postmaster may already be using the data directory or socket. PostgreSQL raises SQLSTATE F0001 (lock_file_exists).
- Seen at startup when
postmaster.pidor a socket lock file exists. - Protects against two postmasters sharing one data directory.
- A stale file can remain after an unclean shutdown.
What the server log shows
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 12345) running in data directory "/var/lib/postgresql/18/main"?
Why PostgreSQL raises this — what the manual says
As Section 18.5 Shutting Down the Server explains:
A stale postmaster.pid lock file from a previous server instance is blocking startup; PostgreSQL refuses to start until it can confirm no other postmaster is using the data directory and the lingering lock file is cleared.
On startup the postmaster creates and checks postmaster.pid to ensure only one instance owns the data directory. If a lock file already exists, it refuses to start with F0001 to avoid two servers corrupting the same files.
Common causes
- Another PostgreSQL instance is genuinely running on that data directory.
- A stale
postmaster.pidleft by an unclean shutdown/crash. - A leftover socket lock file in
/tmp.
How to fix it
- Verify no postmaster is running: check the PID in the hint (
ps -p <pid>). - If the process is gone, remove the stale
postmaster.pidand start again. - Never delete the lock file while a real postmaster is running on that directory.
Related & next steps
Reference: PostgreSQL 18 Section 19.3 “Shutting Down the Server”.
Thanks — noted. This helps keep the database accurate.