lock file exists
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.
- 1Another Postgres instance is already running using the same data directory
- 2A stale postmaster.pid file was left from a previous crash or unclean shutdown
Starting Postgres when postmaster.pid already exists.
-- 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.
✕ Delete postmaster.pid without verifying no Postgres is running
Deleting the lock file while another Postgres instance is running can corrupt the data directory.
Class F0 — Configuration File Error
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev