F0001
PostgreSQLFATALNotableConfiguration File ErrorHIGH confidence

lock file exists

What this means

SQLSTATE F0001 is raised when Postgres cannot start because a postmaster.pid lock file already exists in the data directory, indicating either another Postgres instance is already running or a stale lock file was left from a previous crash.

Why it happens
  1. 1Another Postgres instance is already running using the same data directory
  2. 2A stale postmaster.pid file was left from a previous crash or unclean shutdown
How to reproduce

Starting Postgres when postmaster.pid already exists.

trigger — this will error
trigger — this will error
-- pg_ctl start when another instance is running on the same data dir

expected output

FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 12345) running in data directory "/var/lib/postgresql/data"?

Fix 1

Check if another Postgres instance is running on the same data directory

WHEN Before deleting the lock file.

Why this works

Check the PID in postmaster.pid: if the process is alive, it owns the data directory. Do not start another instance on the same directory.

Fix 2

Remove the stale lock file if no Postgres process is running

WHEN After confirming no other Postgres process uses the data directory.

Why this works

If the PID in postmaster.pid does not correspond to a running process, the file is stale. Remove it: rm /var/lib/postgresql/data/postmaster.pid. Then start Postgres.

What not to do

Delete postmaster.pid without verifying no Postgres is running

Deleting the lock file while another Postgres instance is running can corrupt the data directory.

Sources
Official documentation ↗

Class F0 — Configuration File Error

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors