pre-existing shared memory block (key n, ID n) is still in use

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 9 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

A statement failed with SQLSTATE F0001 (lock_file_exists), reported at severity FATAL. This is a Configuration File Error condition: PostgreSQL emits the message pre-existing shared memory block (key n, ID n) is still in use.

What the server log shows

FATAL:  pre-existing shared memory block (key n, ID n) is still in use
HINT:  Terminate any old server processes associated with data directory "…".

Why PostgreSQL raises this

Class F0 (Configuration File Error) is raised when a configuration file is malformed or a parameter value is invalid.

As described in PostgreSQL’s Section 19.1 Setting Parameters and Appendix A (PostgreSQL Error Codes), SQLSTATE F0001 carries the condition name lock_file_exists in class Configuration File Error. (Paraphrased — see the linked reference for the exact wording.)

Common causes

How to fix it

  1. Fix the offending line and reload (pg_ctl reload).
  2. Validate parameter values against the documented range.
  3. Check the log for the exact file and line reported.

Version applicability

This message is present in PostgreSQL 15, 16, 17, 18 and 19.

Related & next steps

Reference: PostgreSQL Section 19.1 Setting Parameters.