↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / SQLSTATE

58P01 — undefined_file

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.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
System Error (errors external to PostgreSQL itself)
condition name
undefined_file
lang
en
sqlstate
58P01

Definition PG 18

58P01

At a glance {#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 {#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 {#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 {#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 {#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 {#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.

Related {#related}

58P02, 58P03, 58030

Sources {#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.

Compare versions

SQLSTATE evidence and recorded runtime versions

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read locked definition snapshot.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "58P01 is undefined_file in SQLSTATE Class 58."
}
claims · resolved-paths
{
  "claim_id": "resolved-paths",
  "limits": "Source confirmation is not natural runtime.",
  "method": "Read the utility transaction guard, SQL caller, complete directory helper, and WAL-replay caller.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.0",
    "src.path.1"
  ],
  "statement": "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."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use locked catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 58P01 from 7.4; it does not prove the exact introduction or every historical caller."
}
messages · message.0
{
  "limits": "",
  "message_id": "message.0",
  "path": "",
  "position": 0,
  "raw": {
    "hint_condition": "InRecovery",
    "hint_template": "Create this directory for the tablespace before restarting the server.",
    "id": "message.0",
    "primary_template": "directory \"%s\" does not exist",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "58P01"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "directory \" \" does not exist",
      "position": 0,
      "role": "",
      "template": "directory \"%s\" does not exist"
    },
    {
      "kind": "hint",
      "literal": "Create this directory for the tablespace before restarting the server.",
      "position": 1,
      "role": "",
      "template": "Create this directory for the tablespace before restarting the server."
    }
  ]
}
messages · message.1
{
  "limits": "",
  "message_id": "message.1",
  "path": "",
  "position": 1,
  "raw": {
    "code_selection": "errcode_for_file_access()",
    "id": "message.1",
    "primary_template": "could not set permissions on directory \"%s\": %m",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "58P01"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "could not set permissions on directory \" \":",
      "position": 0,
      "role": "",
      "template": "could not set permissions on directory \"%s\": %m"
    }
  ]
}
messages · message.2
{
  "limits": "",
  "message_id": "message.2",
  "path": "",
  "position": 2,
  "raw": {
    "code_selection": "errcode_for_file_access()",
    "id": "message.2",
    "primary_template": "could not create directory \"%s\": %m",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "58P01"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "could not create directory \" \":",
      "position": 0,
      "role": "",
      "template": "could not create directory \"%s\": %m"
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L446"
}
sources · src.path.0
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/commands/tablespace.c",
  "position": 1,
  "sha256": "f0369bece6339d18cd7d4a29b5fa3010447c3b8ece235c64b0d4fbf5f96a5317",
  "source_id": "src.path.0",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/tablespace.c#L347"
}
sources · src.path.1
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/tcop/utility.c",
  "position": 2,
  "sha256": "7aae5d07628b6debf8456d1d4ea96f28912232192e56ea25773b4c4b61235a00",
  "source_id": "src.path.1",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/utility.c#L713"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:26711360b319ae4c5341a6791565e2b10ada39f6c6cc268e7f62bcc7843c2a2d

Text language: en · english-manuals:26711360b319ae4c5341a6791565e2b10ada39f6c6cc268e7f62bcc7843c2a2d