Diagnostic Queries
Symptoms
The server could not start (or create a resource) because a lock file already exists, suggesting another instance may be running. PostgreSQL raises SQLSTATE F0001 (lock_file_exists).
- A
postmaster.pid/lock file is already present. - Common when a previous instance didn’t shut down cleanly.
- Prevents two postmasters on the same data directory.
What the server log shows
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 4242) running in data directory "/var/lib/pgsql/data"?
Why PostgreSQL raises this — what the manual says
Section 18.3 Starting the Database Server:
“While the server is running, its PID is stored in the file postmaster.pid in the data directory.”
PostgreSQL writes postmaster.pid to guard a data directory against concurrent postmasters. If the file exists at startup, it assumes another instance may be running and refuses to start, reporting F0001.
Common causes
- Another PostgreSQL instance is already running on this data directory.
- A crash left a stale
postmaster.pid. - Manual mismanagement of the data directory.
How to fix it
- Confirm no live postmaster is running (check the PID in the hint).
- If truly stale (no running process), remove
postmaster.pidand start again. - Never delete the lock file while a server is actually running.
Related & next steps
Reference: PostgreSQL 18 Section 19.3 “Starting the Server”.
Thanks — noted. This helps keep the database accurate.