Duplicate File — SQLSTATE 58P02

SQLSTATE 58P02 condition duplicate_file class 58 — System Error severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 29 May 2025 · Reproduced live with the SQL on this page.

! Symptoms Free

The server reports SQLSTATE 58P02 (duplicate_file), a condition in the System Error class.

  • The error is written to the server log and returned to the client carrying SQLSTATE 58P02.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN duplicate_file THEN.

1 Environment & reproduce Free

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Indicates a system- or storage-level problem; inspect OS logs, disk health, and any recent hardware or filesystem changes.

? Root cause Free

58P02 belongs to Class 58 — System Error. In this class, an operating-system level error occurred (I/O or missing file).

The first two characters (58) identify the error class, so application code can match the whole class via 58000 when the specific code is not needed.

3 Recovery & verify Free

Check disk health (SMART), filesystem integrity, data-directory permissions, and free space; inspect OS logs and stop running on failing hardware — restore from backup if files are damaged.

Reference: PostgreSQL error codes — Class 58 (System Error).