PG
PRO
F0001FATALTier 2 — Caution✅ HIGH confidence

lock file exists

Category: Configuration File ErrorVersions: All Postgres versions

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
-- pg_ctl start when another instance is running on the same data dir
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

Before deleting the lock file.

fix

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

After confirming no other Postgres process uses the data directory.

fix

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

Why it's wrong: Deleting the lock file while another Postgres instance is running can corrupt the data directory.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class F0 — Configuration File Error

Confidence assessment

✅ HIGH confidence

Postgres-specific. Stable across all versions.

See also

🔗 Related errors

📄 Reference pages

postmaster.pidpg_ctlData Directory
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →