lock file “…” already exists

SQLSTATE F0001 condition lock_file_exists class F0 — Configuration File Error severity FATAL
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

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).

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

How to fix it

  1. Verify no postmaster is running: check the PID in the hint (ps -p <pid>).
  2. If the process is gone, remove the stale postmaster.pid and start again.
  3. 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”.