tablespace “…” does not exist

SQLSTATE 42704 condition undefined_object class 42 — Syntax Error or Access Rule Violation 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

A statement referenced a tablespace that does not exist. PostgreSQL raises SQLSTATE 42704 (undefined_object).

What the server log shows

ERROR:  tablespace "fastdisk" does not exist

Why PostgreSQL raises this — what the manual says

the CREATE TABLESPACE reference (Description):

“A tablespace allows superusers to define an alternative location on the file system where the data files containing database objects (such as tables and indexes) can reside.”

Tablespaces are named, cluster-wide storage locations. Referencing one that was never created (or a typo) cannot be resolved, so PostgreSQL reports 42704.

Common causes

How to fix it

  1. Create it: CREATE TABLESPACE fastdisk LOCATION '/mnt/fast'; (superuser).
  2. List tablespaces: \db or query pg_tablespace.
  3. When restoring, pre-create needed tablespaces or remap with --no-tablespaces.

Related & next steps

Reference: PostgreSQL 18 — CREATE TABLESPACE.