百科 / SQL 状态码 / Class 58 系统错误(PostgreSQL自身以外的错误)
58P01 undefined_file
58P01 — undefined_file
ERROR 源码确认 详解 未实测
- 条件名
undefined_file- 宏名称
ERRCODE_UNDEFINED_FILE- 最早已知存在
- 7.4
- 状态
- 有效
手册收录:8.1、8.2、8.3、8.4、9.0、9.1、9.2、9.3、9.4、9.5、9.6、10、11、12、13、14、15、16、17、18、19、20。此处仅表示同版本手册收录,运行证据仍以原核验构建为准。
版本覆盖
版本条依据已采样构建显示;灰色版本可能尚未采样,悬停可查看。手册链接随版本选择,源码和运行证据保持原核验构建。
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}
来源 {#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 路径和源码/运行边界。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 446 行
- 上游源码 src/backend/commands/tablespace.c 第 347 行
- 上游源码 src/backend/tcop/utility.c 第 713 行
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
58P01 is undefined_file in SQLSTATE Class 58.
-
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.
-
The locked catalogue records 58P01 from 7.4; it does not prove the exact introduction or every historical caller.
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
directory "%s" does not exist
Create this directory for the tablespace before restarting the server.
could not set permissions on directory "%s": %m
could not create directory "%s": %m
同类 SQL 状态码
| 状态码 | 条件名 | 宏名称 | 严重等级 | 版本 |
|---|---|---|---|---|
| 58000 | system_error | ERRCODE_SYSTEM_ERROR |
ERROR | 9.2.0 起已知 |
| 外部系统调用失败,如发送信号返回错误。 | 有效 | |||
| 58030 | io_error | ERRCODE_IO_ERROR |
ERROR | 7.4 起已知 |
| 文件读写发生 I/O 错误,如缓冲区写回失败。 | 有效 | |||
| 58P01 | undefined_file | ERRCODE_UNDEFINED_FILE |
ERROR | 7.4 起已知 |
| 所需的文件或目录不存在,如表空间路径缺失。 | 有效 | |||
| 58P02 | duplicate_file | ERRCODE_DUPLICATE_FILE |
ERROR | 7.4 起已知 |
| 目标文件或目录已存在且非空,无法创建。 | 有效 | |||
| 58P03 | file_name_too_long | ERRCODE_FILE_NAME_TOO_LONG |
ERROR | 18.0 起已知 |
| 文件访问因路径名过长失败,对应 ENAMETOOLONG。 | 有效 | |||