选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 58 系统错误

58P01 undefined_file

ERROR 源码确认 详解 未实测

类别
Class 58 系统错误
严重等级
ERROR
条件名
undefined_file
宏名称
ERRCODE_UNDEFINED_FILE
启用版本
7.4
状态
活跃

版本覆盖

速览

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

含义

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 详细信息才能判断缺失的是表空间、关系文件、配置文件还是其他文件消费者。

消息

  • ERROR,SQLSTATE 58P01directory "%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(原地目录分支)。

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

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 directory "%s" does not exist
HINT Create this directory for the tablespace before restarting the server.

来源:src/backend/commands/tablespace.c @ REL_18_6

主消息 could not set permissions on directory "%s": %m

来源:src/backend/commands/tablespace.c @ REL_18_6

主消息 could not create directory "%s": %m

来源:src/backend/commands/tablespace.c @ REL_18_6

诊断

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

处理

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

版本

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

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 58P01 is undefined_file in SQLSTATE Class 58.

    核实方式Read locked definition snapshot.

    来源src/backend/utils/errcodes.txt

  • 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.

    核实方式Read the utility transaction guard, SQL caller, complete directory helper, and WAL-replay caller.

    不覆盖Source confirmation is not natural runtime.

    来源src/backend/commands/tablespace.c · src/backend/tcop/utility.c

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

    核实方式Use locked catalogue boundary.

    来源src/backend/utils/errcodes.txt

同类错误代码

Class 58 系统错误 下的其他成员。