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

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

Wiki / SQLSTATE

58P02 — duplicate_file

目标文件或目录已存在且非空,无法创建。

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

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

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

版本定义 PG 18

58P02

速览 {#at-a-glance}

58P02 是固定服务器端基础备份输出路径中的 duplicate-file 条件。缺失目录会尝试创建,已有空目录可以使用,已有非空目录则报告此码。

含义 {#meaning}

bbsink_server_new() 先检查并提交权限校验事务,然后拒绝相对路径并调用 pg_check_dir(pathname):结果 0 创建目录,结果 1 接受空目录,结果 2–4 进入固定的 ERRCODE_DUPLICATE_FILE 分支;访问错误走另一条 errcode_for_file_access() 分支。这是基础备份输出保护,不证明 PostgreSQL 中所有 EEXIST 或非空目录都使用 58P02。

消息 {#messages}

  • ERROR,SQLSTATE 58P02:directory "%s" exists but is not empty。
  • ERROR,使用 errcode_for_file_access():could not access directory "%s": %m。
  • ERROR,目标不存在但创建失败时,使用 errcode_for_file_access():could not create directory "%s": %m。

后两个模板的 SQLSTATE 由保存的 OS errno 决定,不能因为它们在同一函数中就都标成 58P02。

诊断 {#diagnosis}

确认路径确实是预期的基础备份目标,检查所有者、挂载和内容,并判断是完整旧备份还是中断产物;变更前保留目录清单。源码在内部权限校验事务提交后才准备输出目录,因此这里表示备份建立失败,不能假设可以靠继续执行 SQL 修复用户 DML 事务。

处理 {#response}

按备份策略使用已确认为空的目标,或先归档旧输出。创建后验证完整备份和 manifest;不要递归删除或强制覆盖未知目录。若外层客户端报告 ERROR,按实际会话状态回滚到已有保存点或事务;ROLLBACK 不能把非空备份目录变安全。只有所属服务器进程被终止时才需要新连接。

版本 {#versions}

锁定目录从 7.4 记录此条件;固定基础备份路径来自 PostgreSQL 18.6。本源码条目没有修改或测试备份目标。

相关 {#related}

58P01、58P03、53100

来源 {#sources}

src/backend/backup/basebackup_server.c#L59-L125

结构化证据记录保存目录状态分支、动态 errno 路径和源码/运行边界。

比较版本

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

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read locked definition snapshot.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "58P02 is duplicate_file in SQLSTATE Class 58."
}
claims · resolved-paths
{
  "claim_id": "resolved-paths",
  "limits": "Source confirmation is not natural runtime.",
  "method": "Read the complete sink constructor and directory-state switch.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.0"
  ],
  "statement": "The server-side base-backup sink commits its privilege-check transaction before checking the output directory, accepts empty targets, and emits 58P02 only for an existing non-empty target; other branches use errno-selected codes."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use locked catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 58P02 from 7.4; it does not prove every historical duplicate-file caller."
}
messages · message.0
{
  "limits": "",
  "message_id": "message.0",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.0",
    "primary_template": "directory \"%s\" exists but is not empty",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "58P02"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "directory \" \" exists but is not empty",
      "position": 0,
      "role": "",
      "template": "directory \"%s\" exists but is not empty"
    }
  ]
}
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 access directory \"%s\": %m",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "58P02"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "could not access directory \" \":",
      "position": 0,
      "role": "",
      "template": "could not access 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": "58P02"
  },
  "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#L447"
}
sources · src.path.0
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/backup/basebackup_server.c",
  "position": 1,
  "sha256": "1447d7223926f903d27744605f9caec8a610d78a9f7a7864bb3afb6b3073ac19",
  "source_id": "src.path.0",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/backup/basebackup_server.c#L59"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:9e350d7653c989a2faae19e2a4a72bac8a5882a494b89cb1c3c910efa990a41f

正文语言: zh-Hans · english-manuals:9e350d7653c989a2faae19e2a4a72bac8a5882a494b89cb1c3c910efa990a41f