↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

58P01 — undefined_file

所需的文件或目录不存在,如表空间路径缺失。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

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

版本定义 PG 18

58P01

速览 {#at-a-glance}

58P01 表示所需文件或目录找不到。固定表空间路径会把 chmod 的 ENOENT 与其他权限/文件系统失败分开;只有服务器正在恢复时才加入重启前创建目录的提示。

含义 {#meaning}

utility.c 在进入 CreateTableSpace 前调用 PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE"),因此该命令必须在顶层执行,无需再手工回滚一个显式事务块。create_tablespace_directories() 在该命令之后以及表空间 WAL 重放中调用。目标不是原地目录时,如果 chmod(location, ...) 返回 ENOENT,源码以 SQLSTATE 58P01 报告 directory "%s" does not exist;仅在 InRecovery 为真时加入 Create this directory for the tablespace before restarting the server.。其他 chmod 失败通过 errcode_for_file_access() 报告动态主消息 could not set permissions on directory "%s": %m;原地创建失败也使用 could not create directory "%s": %m,其代码由 errno 选择。

因此此码不只属于表空间启动。实际操作和 %m 详细信息才能判断缺失的是表空间、关系文件、配置文件还是其他文件消费者。

消息 {#messages}

  • ERROR,SQLSTATE 58P01:directory "%s" does not exist
    • 恢复时的条件提示:Create this directory for the tablespace before restarting the server.
  • ERROR,使用 errcode_for_file_access():could not set permissions on directory "%s": %m。
  • ERROR,使用 errcode_for_file_access():could not create directory "%s": %m(原地目录分支)。

后两种模板不保证都是 58P01:errcode_for_file_access() 会根据保存的 errno 选择 SQLSTATE。

诊断 {#diagnosis}

记录完整主消息、%m 详细信息、阶段、路径、数据库/表空间身份,以及调用者是 SQL 执行还是 WAL 重放。确认目标卷挂载在精确路径,再检查所有者、权限、符号链接目标和表空间版本目录;卷未挂载与目录被删除需要不同处理。

处理 {#response}

按部署和备份流程恢复预期挂载或目录,不要在未知表空间位置覆盖创建空路径。CREATE TABLESPACE 受 PreventInTransactionBlock 保护,必须在显式事务之外运行;该命令本身无需再手工回滚一个显式事务块。若其他文件消费者在显式事务内报告客户端 ERROR,继续前先 ROLLBACK 或回到已建立的保存点。若消息来自 WAL 恢复,则没有可恢复的客户端事务:恢复路径并按服务器重启/恢复流程处理;确认所有者、权限和目录内容后再重试。

版本 {#versions}

锁定目录从 7.4 记录此条件;固定源码覆盖 PostgreSQL 18.6。本条为源码核验,没有诱发表空间故障。

相关 {#related}

58P02、58P03、58030

来源 {#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

结构化证据记录保存条件提示、动态 errno 路径和源码/运行边界。

比较版本

SQLSTATE 证据与已记录的运行版本

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"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:26711360b319ae4c5341a6791565e2b10ada39f6c6cc268e7f62bcc7843c2a2d

正文语言: zh-Hans · english-manuals:26711360b319ae4c5341a6791565e2b10ada39f6c6cc268e7f62bcc7843c2a2d