could not create file “…”: Permission denied

SQLSTATE 58030 condition io_error 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 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

PostgreSQL could not create a file because the operating system denied permission. PostgreSQL raises SQLSTATE 58030 (io_error).

What the server log shows

ERROR:  could not create file "base/16384/t3_24576": Permission denied

Why PostgreSQL raises this — what the manual says

Section 18.2 Creating a Database Cluster:

“Of course, this will fail if initdb does not have permissions to write in the parent directory.”

The PostgreSQL server process must own and be able to write the data directory and tablespaces. If the OS denies file creation, PostgreSQL cannot proceed and reports 58030.

Common causes

How to fix it

  1. Ensure the data directory is owned by the postgres OS user with proper permissions (typically 0700).
  2. Fix tablespace directory ownership/permissions.
  3. Check SELinux/AppArmor contexts and that the filesystem is writable.

Related & next steps

Reference: PostgreSQL 18 Section 19.2 “Creating a Cluster”.