select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 58 · SYSTEM ERROR (ERRORS EXTERNAL TO POSTGRESQL ITSELF)

undefined_file

SQLSTATE
58P01
Condition name
undefined_file
Class
System Error (errors external to PostgreSQL itself)
Source macro
ERRCODE_UNDEFINED_FILE
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>58P01</h1>

At a glance

58P01 means that a required file or directory could not be found. In the fixed tablespace path, PostgreSQL distinguishes an ENOENT target during chmod from other permission or filesystem failures; the recovery hint is conditional on the server being in recovery.

Meaning

utility.c calls PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE") before entering CreateTableSpace, so the command is rejected inside an explicit transaction block; there is no explicit client transaction block to roll back for that command. create_tablespace_directories() is used after that command and from tablespace WAL replay. When the target is not an in-place directory and chmod(location, ...) returns ENOENT, the code emits SQLSTATE 58P01 with directory "%s" does not exist. It adds Create this directory for the tablespace before restarting the server. only when InRecovery is true. Other chmod failures use errcode_for_file_access() and the dynamic primary could not set permissions on directory "%s": %m; an in-place creation failure similarly uses could not create directory "%s": %m with an errno-selected code.

The condition is therefore broader than tablespace startup. The operation and %m detail decide whether the missing object is a tablespace, relation file, configuration file, or another file consumer.

Messages

  • ERROR, SQLSTATE 58P01: directory "%s" does not exist
  • Conditional hint during recovery: Create this directory for the tablespace before restarting the server.
  • ERROR, with errcode_for_file_access(): could not set permissions on directory "%s": %m.
  • ERROR, with errcode_for_file_access(): could not create directory "%s": %m (the in-place directory branch).

The latter two templates are not guaranteed to be 58P01: errcode_for_file_access() selects the SQLSTATE from the saved errno.

Diagnosis

Record the complete primary, %m detail, phase, path, database/tablespace identity, and whether the caller is SQL execution or WAL replay. Check that the expected volume is mounted at the exact path, then verify ownership, mode, symlink target, and the tablespace version directory. A missing mount and an intentionally removed directory need different recovery plans.

Response

Restore the expected mount or directory from the deployment and backup procedure; do not create an arbitrary empty path over an unknown tablespace location. CREATE TABLESPACE is guarded by PreventInTransactionBlock, so it cannot run inside an explicit client transaction block; there is no explicit block to roll back for that command itself. If a different file consumer reports a client ERROR inside an explicit transaction, issue ROLLBACK or use an already-established savepoint before continuing. When the message comes from WAL recovery, there is no client transaction to resume: restore the path and follow the server's restart/recovery procedure. Retry only after ownership, permissions, and the target's contents have been checked.

Versions

The locked catalogue records this condition from 7.4; fixed source coverage is PostgreSQL 18.6. The cited source is a source-only review; no tablespace fault was induced.

Sources

src/backend/commands/tablespace.c#L347-L359

src/backend/commands/tablespace.c#L565-L625

src/backend/commands/tablespace.c#L1515-L1525

src/backend/tcop/utility.c#L713-L717

The structured evidence record records conditional hints, dynamic errno paths, and the source/runtime boundary.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

58P01 is undefined_file in SQLSTATE Class 58.

Method: Read locked definition snapshot.

src.errcodes.18.6

The utility dispatcher rejects CREATE TABLESPACE inside a transaction block before entering CreateTableSpace; the tablespace directory helper uses explicit 58P01 for ENOENT from chmod, conditionally adds its recovery hint, and uses errno-selected file-access codes for other directory failures.

Method: Read the utility transaction guard, SQL caller, complete directory helper, and WAL-replay caller.

Limits: Source confirmation is not natural runtime.

src.path.0 src.path.1

The locked catalogue records 58P01 from 7.4; it does not prove the exact introduction or every historical caller.

Method: Use locked catalogue boundary.

src.errcodes.18.6

Message templates

ERROR · message.0

Primary

directory "%s" does not exist

Hint

Create this directory for the tablespace before restarting the server.
ERROR · message.1

Primary

could not set permissions on directory "%s": %m
ERROR · message.2

Primary

could not create directory "%s": %m

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:759e1ebe18d0032b4e13f896ef6… · English manual source