directory “…” exists but is not empty

SQLSTATE 58P02 condition duplicate_file class 58 — System Error (errors external to PostgreSQL itself) severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 7 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

A statement failed with SQLSTATE 58P02 (duplicate_file), reported at severity ERROR. This is a System Error (errors external to PostgreSQL itself) condition: PostgreSQL emits the message directory "…" exists but is not empty.

What the server log shows

ERROR:  directory "…" exists but is not empty

Why PostgreSQL raises this

Class 58 (System Error) reports failures external to PostgreSQL itself — operating-system level I/O, file, or similar errors surfaced through the server.

As described in PostgreSQL’s Appendix A PostgreSQL Error Codes, SQLSTATE 58P02 carries the condition name duplicate_file in class System Error (errors external to PostgreSQL itself). (Paraphrased — see the linked reference for the exact wording.)

Common causes

How to fix it

  1. Check OS logs, disk health, and filesystem permissions.
  2. Ensure the data directory is intact and writable.
  3. Address the underlying hardware/OS condition, then retry.

Version applicability

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

Related & next steps

Reference: PostgreSQL Appendix A PostgreSQL Error Codes.