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

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

Wiki / SQLSTATE

2BP01 — dependent_objects_still_exist(依赖对象仍存在)

DROP 的对象仍被其他数据库对象依赖。

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

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

aliases
未知
class name
Dependent Privilege Descriptors Still Exist
condition name
dependent_objects_still_exist
lang
en
sqlstate
2BP01

版本定义 PG 18

2BP01 — dependent_objects_still_exist(依赖对象仍存在)

速览 {#at-a-glance}

2BP01 表示 DROP 或相关目录操作要移除的对象仍被其他数据库对象依赖。正确处理是先理解依赖关系,决定依赖对象应保留还是删除,再重试原操作。

含义 {#meaning}

依赖遍历器会在对象仍被其他对象需要时发出 2BP01。代表路径中视图依赖表,因此 DROP TABLE 不能执行。主报文、DETAIL 和 CASCADE 提示都根据对象描述和依赖图动态组装。2BP01 讨论的是依赖对象;依赖权限描述符的 2B000 是另一种条件。

诊断 {#diagnosis}

同时保存 SQLSTATE、主报文、DETAIL 和 HINT。选定路径的 DETAIL 会指出依赖视图。选择修复前检查视图定义和依赖元数据;pg_depend 与 pg_get_viewdef() 可以说明对象为什么仍被保留。在选定的显式 BEGIN 块中,收到该 ERROR 后连接会在 ROLLBACK 前处于 INERROR;自动提交语句没有需要保留的外层事务。不能在失败的显式块中继续查询目录来完成可靠诊断。

处理 {#response}

先回滚失败的显式事务。如果视图确实可以删除,先删视图,再删表;如果视图属于模式契约,就保留它并改写迁移方案。CASCADE 是删除依赖对象的明确请求,可能超过预期变更,因此不能把 HINT 自动当成执行指令。完成有边界的修复后,重新执行完整 DDL 计划并核对仍应存在的对象。

报文 {#messages}

选定源码分支的模板为 cannot drop %s because other objects depend on it,DETAIL 是动态内部文本,HINT 为 Use DROP ... CASCADE to drop the dependent objects too.。对象描述和依赖列表都是运行时值,不要把 DETAIL 当成固定的单对象模板,也不要假设所有 2BP01 路径都使用同一措辞。

代表案例 {#case}

运行器从 verify/cases/2BP01/snippets.json(SHA-256 899e4fd9fb002fc293bd9efee0204e4f2622968c6d9460ad05eb9a0ebd3bac69)读取下面的依赖序列;失败 DROP 使用显式 BEGIN/ROLLBACK,修复先删已知视图再删表,完全不使用 CASCADE。见公开案例导出和结构化证据。

CREATE TABLE base_items(id integer PRIMARY KEY, payload text NOT NULL);
CREATE VIEW dependent_view AS SELECT id, payload FROM base_items;
BEGIN;
DROP TABLE base_items;
ROLLBACK;
DROP VIEW dependent_view;
DROP TABLE base_items;
SELECT to_regclass('base_items'), to_regclass('dependent_view');

运行器会在私有 schema 中为 registry 名称加限定名。最后两个 to_regclass 都返回 null,证明删除的是预期对象,而不是对未知依赖图静默级联。

选定案例在 PostgreSQL 18.6 和 10.21 观察到 2BP01。DROP TABLE 的 DETAIL 指出依赖视图并给出 CASCADE 提示;显式事务进入 INERROR,ROLLBACK 恢复为 IDLE,随后先删视图再删表完成修复。

版本 {#versions}

目录从早期历史边界到正式快照都记录了该条件。18.6 固定源码还包括依赖、共享依赖、角色、权限、类型表和表空间等分支;运行案例只覆盖 18.6 与 10.21 的普通视图到表依赖。不能据此推断所有分支的 CASCADE 都安全。

相关 {#related}

可对照2B000 依赖权限描述符仍存在和42P01 表不存在。

来源 {#sources}

  • src.errcodes.18.6(SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)
  • src.dependency.18.6(SHA-256 1878f848dae03e08424a47a09508f3443227ad67c4bc5e0aba3ec9655d015b74)
  • DROP TABLE 官方文档 · 本地调用扫描 src.calls.REL_18_6(SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)

比较版本

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

cases · dependent_object_drop_recovery
{
  "assertions": [
    "SQLSTATE is 2BP01",
    "The diagnostic names dependent objects",
    "The failed transaction is INERROR until ROLLBACK",
    "Dropping the dependent view first removes both objects without CASCADE"
  ],
  "case_id": "dependent_object_drop_recovery",
  "cleanup": "Drop the case schema with an owner connection.",
  "has_snippet": true,
  "position": 0,
  "preconditions": [
    "A runner-owned disposable target is provisioned."
  ],
  "repair": "Rollback the failed DROP, inspect the named dependent objects, and remove them in an intentional dependency order.",
  "trigger": "Create a view that depends on a table, attempt DROP TABLE inside an explicit transaction, then drop the view first and the table.",
  "versions": [
    "10",
    "18"
  ]
}
claims · identity
{
  "claim_id": "identity",
  "limits": "Other dependent-privilege and typed-object paths use the same condition with different dynamic messages.",
  "method": "Read the fixed errcodes.txt row and macro mapping.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "2BP01 is the dependent_objects_still_exist condition in Class 2B."
}
claims · dependency-path
{
  "claim_id": "dependency-path",
  "limits": "DETAIL names the dependency graph dynamically; it is not a fixed format for every object kind.",
  "method": "Trace reportDependentObjects and its dynamic DETAIL/HINT assembly.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.dependency.18.6",
    "src.calls.REL_18_6"
  ],
  "statement": "The dependency walker reports that an object cannot be dropped while other objects depend on it and supplies a CASCADE hint."
}
claims · repair-order
{
  "claim_id": "repair-order",
  "limits": "Other dependency types and ownership/privilege checks may require a different order or privileges.",
  "method": "Use a view-to-table dependency and the shared registry repair sequence.",
  "position": 2,
  "runtime": [],
  "sources": [
    "doc.drop.18.6"
  ],
  "statement": "A safe repair identifies the dependent view and drops it intentionally before dropping its base table; CASCADE is an explicit policy choice, not a universal repair."
}
claims · runtime
{
  "claim_id": "runtime",
  "limits": "The INERROR then IDLE assertion belongs to the selected explicit BEGIN/ROLLBACK block; autocommit statements have no surrounding block to preserve.",
  "method": "Read the selected runner summaries and raw outputs tied to the shared snippet registry.",
  "position": 3,
  "runtime": [],
  "sources": [
    "runtime.2BP01-batch34-final-20260909.latest",
    "runtime.2BP01-batch34-final-20260909.pg10"
  ],
  "statement": "The selected 2BP01 case passed on PostgreSQL 18.6 and 10.21 with the structured SQLSTATE, transaction-state, and repair assertions recorded in the runtime entries."
}
messages · message.dependent-object
{
  "limits": "Object descriptions and dependency detail are dynamically assembled.",
  "message_id": "message.dependent-object",
  "path": "",
  "position": 0,
  "raw": {
    "detail_template": "%s (dynamic internal detail)",
    "hint_template": "Use DROP ... CASCADE to drop the dependent objects too.",
    "id": "message.dependent-object",
    "limits": "Object descriptions and dependency detail are dynamically assembled.",
    "primary_template": "cannot drop %s because other objects depend on it",
    "severity_source": "ERROR",
    "sources": [
      "src.dependency.18.6"
    ],
    "sqlstate": "2BP01"
  },
  "severity": "ERROR",
  "sources": [
    "src.dependency.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot drop because other objects depend on it",
      "position": 0,
      "role": "",
      "template": "cannot drop %s because other objects depend on it"
    },
    {
      "kind": "detail",
      "literal": "(dynamic internal detail)",
      "position": 1,
      "role": "",
      "template": "%s (dynamic internal detail)"
    },
    {
      "kind": "hint",
      "literal": "Use DROP ... CASCADE to drop the dependent objects too.",
      "position": 2,
      "role": "",
      "template": "Use DROP ... CASCADE to drop the dependent objects too."
    }
  ]
}
runtimes · runtime.2BP01-batch34-final-20260909.latest · 18.6 (Homebrew) · passed
{
  "cases": [
    "dependent_object_drop_recovery"
  ],
  "limits": "",
  "position": 0,
  "raw": {
    "case_manifest": {
      "path": "verify/cases/2BP01/cases.json",
      "sha256": "4e428d2ab267974589385038a637b43d3493b60fd0dd5243fd71862b9a7e7ccc"
    },
    "cases": [
      "dependent_object_drop_recovery"
    ],
    "id": "runtime.2BP01-batch34-final-20260909.latest",
    "observed": {
      "connection_autocommit": true,
      "primary": "cannot drop table c2bp01_dependent_object_drop_recovery.base_items because other objects depend on it",
      "repair": {
        "remaining_relations": [
          null,
          null
        ]
      },
      "severity": "ERROR",
      "sqlstate": "2BP01",
      "statuses": {
        "after_error": "INERROR",
        "after_repair": "IDLE",
        "after_rollback": "IDLE"
      }
    },
    "raw": "verify/results/2BP01-batch34-final-20260909/latest/raw.jsonl",
    "raw_sha256": "e4de5657bb564cb931134ce3bd149106f3c7f4df3287665e70ab6711a63d682d",
    "run_id": "2BP01-batch34-final-20260909",
    "server_version": "18.6 (Homebrew)",
    "snippet_registry": {
      "path": "verify/cases/2BP01/snippets.json",
      "sha256": "899e4fd9fb002fc293bd9efee0204e4f2622968c6d9460ad05eb9a0ebd3bac69"
    },
    "status": "passed",
    "summary": "verify/results/2BP01-batch34-final-20260909/latest/summary.json",
    "summary_sha256": "5152619160085d99208030f2935dd2621449df65b7927c1a4fff9d2230577d85",
    "target": "latest"
  },
  "run_id": "2BP01-batch34-final-20260909",
  "runtime_id": "runtime.2BP01-batch34-final-20260909.latest",
  "server_version": "18.6 (Homebrew)",
  "status": "passed",
  "target": "latest"
}
runtimes · runtime.2BP01-batch34-final-20260909.pg10 · 10.21 (Debian 10.21-1.pgdg90+1) · passed
{
  "cases": [
    "dependent_object_drop_recovery"
  ],
  "limits": "",
  "position": 1,
  "raw": {
    "case_manifest": {
      "path": "verify/cases/2BP01/cases.json",
      "sha256": "4e428d2ab267974589385038a637b43d3493b60fd0dd5243fd71862b9a7e7ccc"
    },
    "cases": [
      "dependent_object_drop_recovery"
    ],
    "id": "runtime.2BP01-batch34-final-20260909.pg10",
    "observed": {
      "connection_autocommit": true,
      "primary": "cannot drop table c2bp01_dependent_object_drop_recovery.base_items because other objects depend on it",
      "repair": {
        "remaining_relations": [
          null,
          null
        ]
      },
      "severity": "ERROR",
      "sqlstate": "2BP01",
      "statuses": {
        "after_error": "INERROR",
        "after_repair": "IDLE",
        "after_rollback": "IDLE"
      }
    },
    "raw": "verify/results/2BP01-batch34-final-20260909/pg10/raw.jsonl",
    "raw_sha256": "660365c646eec69fceb84b6390329b96b18db870ca7e1b7c8d0d5da9989a631a",
    "run_id": "2BP01-batch34-final-20260909",
    "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
    "snippet_registry": {
      "path": "verify/cases/2BP01/snippets.json",
      "sha256": "899e4fd9fb002fc293bd9efee0204e4f2622968c6d9460ad05eb9a0ebd3bac69"
    },
    "status": "passed",
    "summary": "verify/results/2BP01-batch34-final-20260909/pg10/summary.json",
    "summary_sha256": "51adc1a279429396fad88b577f2b794ef29c4875d07d26e5b9cd2eddae5fd451",
    "target": "pg10"
  },
  "run_id": "2BP01-batch34-final-20260909",
  "runtime_id": "runtime.2BP01-batch34-final-20260909.pg10",
  "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
  "status": "passed",
  "target": "pg10"
}
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"
}
sources · src.calls.REL_18_6
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 1,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6",
  "tag": "",
  "url": ""
}
sources · src.dependency.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/catalog/dependency.c",
  "position": 2,
  "sha256": "1878f848dae03e08424a47a09508f3443227ad67c4bc5e0aba3ec9655d015b74",
  "source_id": "src.dependency.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/dependency.c#L1148-L1154"
}
sources · doc.drop.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "https://www.postgresql.org/docs/18/sql-droptable.html",
  "kind": "upstream_source",
  "location": "",
  "path": "doc/src/sgml/ref/drop_table.sgml",
  "position": 3,
  "sha256": "0eddfa552ed02df4fda6409692198756e616afb805e52cc4caefa84f928354e8",
  "source_id": "doc.drop.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/drop_table.sgml"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:72f7d74fa212c1bd558c4238be49a978b5d1f42b829d6c59f6fb26830f3918ae

正文语言: zh-Hans · english-manuals:72f7d74fa212c1bd558c4238be49a978b5d1f42b829d6c59f6fb26830f3918ae