百科 / SQL 状态码 / Class 55 对象未处于所需状态
55006 object_in_use
对象正在使用
ERROR 已实测 详解 实测通过
- 条件名
object_in_use- 宏名称
ERRCODE_OBJECT_IN_USE- 最早已知存在
- 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。此处仅表示同版本手册收录,运行证据仍以原核验构建为准。
版本覆盖
版本条依据已采样构建显示;灰色版本可能尚未采样,悬停可查看。手册链接随版本选择,源码和运行证据保持原核验构建。
55006 — 对象正在使用
速览 {#at-a-glance}
55006 表示请求的对象操作与正在进行的使用冲突。本页选择显式事务中同一会话的活动 cursor 占用表;数据库用户、逻辑复制和待处理触发器事件是不同路径。
含义 {#meaning}
选定的表命令模板为 cannot %s "%s" because it is being used by active queries in this session。关系引用计数指向同一 backend 的活动 portal 或扫描,不是一般权限问题。同一个表使用检查还有当前事务排队的 AFTER trigger 分支:cannot %s "%s" because it has pending trigger events。其他 55006 报文可能指明数据库用户或逻辑复制槽等不同阻塞者。
诊断 {#diagnosis}
确认对象和持有使用状态的具体会话或服务器状态。本案例检查显式事务与命名 cursor;若是待处理 trigger event,应完成或回滚排队它们的事务。遇到数据库或复制路径时,应在终止任何会话前检查 pg_stat_activity、复制槽、订阅和维护归属。当前 backend 的 cursor 与其他用户 backend 或逻辑复制槽不是同一种阻塞。
处理 {#response}
回滚失败的显式事务,让事务拥有的 cursor 和待处理 trigger event 释放,再在明确的维护边界重做 DDL。数据库用户阻塞要协调持有会话,逻辑复制槽则处理订阅/slot 生命周期。不要把 CASCADE 或终止无关会话当作通用处理。
实测诊断 {#messages}
选定源码组为 ERROR,操作和关系名是动态字段。实测主报文为 cannot DROP TABLE "cursor_drop_table" because it is being used by active queries in this session;事务进入 INERROR,回滚后恢复为 IDLE。
代表案例 {#case}
注册表创建一张空表,在同一后端开启事务、声明并 FETCH 命名 cursor,再尝试 DROP TABLE;即使没有行,活动 cursor 仍会触发同会话 active-query 分支。真实 55006 后,处理程序在同一连接回滚,再次删除表并确认关系已消失。本案例不代替其他数据库用户、逻辑复制槽或待处理 AFTER-trigger event 路径。
CREATE TABLE cursor_drop_table(id integer PRIMARY KEY);
BEGIN;
DECLARE active_cursor CURSOR FOR SELECT id FROM cursor_drop_table;
FETCH active_cursor;
DROP TABLE cursor_drop_table;
ROLLBACK;
DROP TABLE cursor_drop_table;
SELECT to_regclass('cursor_drop_table_regclass')
选定的 PostgreSQL 18.6 与 10.21 运行均通过 SQLSTATE、严重级别、状态或断开恢复、修复、清理和一次性实例停止断言。详见 案例 JSON 与 作者证据。
版本 {#versions}
锁定目录从 7.4 起记录 55006。18.6 与 10.21 的活动 cursor DDL 案例均通过;这不代表数据库、复制或待处理触发器路径。
相关 {#related}
来源 {#sources}
src.errcodes.18.6—src/backend/utils/errcodes.txtat724edf9bde9d356724ad384a2e196edc3c9f80f7; blob SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(source).src.active-cursor.18.6—src/backend/commands/tablecmds.cat724edf9bde9d356724ad384a2e196edc3c9f80f7; blob SHA-256422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9(source).src.pending-trigger.18.6— 同一tablecmds.c检查待处理 AFTER-trigger event,并在 4439-4444 发出cannot %s "%s" because it has pending trigger events(source)。src.active-cursor.10.23—src/backend/commands/tablecmds.cat02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; blob SHA-2566de441c88496c6cf57a836898388085ec08bf69afd70d07acdafd6089b9b5f8c(source).src.calls.REL_18_6/src.calls.REL_10_23— fixed call scans, SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf/00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.manifest.55006/snippet-registry.55006— hashes are recorded inevidence/55006.jsonand each selected runtime record.
来源
- 上游源码 src/backend/commands/tablecmds.c 第 3072–3077 行
- 上游源码 src/backend/commands/tablecmds.c 第 4431–4435 行
- 上游源码 src/backend/utils/errcodes.txt 第 425 行
- 上游源码 src/backend/commands/dbcommands.c 第 1407 行
- 上游源码 src/backend/commands/dbcommands.c 第 1752 行
- 上游源码 src/backend/commands/tablecmds.c 第 4431 行
- 核验材料 verify/cases/55006/cases.json
- 核验材料 verify/cases/55006/snippets.json
- 核验材料 raw/calls/REL_10_23.jsonl
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
55006 is object_in_use in SQLSTATE Class 55.
-
The cited PostgreSQL 18.6 source paths support the representative resource and object-state mechanisms described.
-
The locked catalogue records 55006 from 7.4; that boundary does not prove exact implementation introduction.
-
The selected table-command path reports 55006 when the same session attempts DROP while its transaction-owned cursor still uses the table.
-
The active_cursor_drop case passed on isolated PostgreSQL 18.6 and 10.21; rollback released the cursor transaction and the same session then dropped the table.
运行记录
| 目标 | 服务器版本 | 结果 | 覆盖案例 |
|---|---|---|---|
| latest | 18.6 (Homebrew) | passed | 案例:active_cursor_drop |
| pg10 | 10.21 (Debian 10.21-1.pgdg90+1) | passed | 案例:active_cursor_drop |
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
source database "%s" is being accessed by other users
database "%s" is used by an active logical replication slot
cannot %s "%s" because it is being used by active queries in this session
cannot %s "%s" because it has pending trigger events
来源: 来源:src/backend/commands/tablecmds.c @ REL_18_6
适用范围:This is a separate current-transaction branch from the active-query reference-count branch.
cannot %s "%s" because it is being used by active queries in this session
cannot %s "%s" because it is being used by active queries in this session
可复现案例
在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。
active_cursor_drop PG 10 / 18 有 SQL
前置条件
- A runner-owned empty table exists; a cursor can still hold the relation in active use.
- The table cursor and DROP run on one backend session.
触发
Declare and use a cursor on a table in an explicit transaction, then attempt to DROP that table from the same session.
断言
- SQLSTATE is 55006 with ERROR severity
- The diagnostic says the table is used by active queries in this session
- The failed DROP leaves the explicit transaction INERROR
- ROLLBACK releases the transaction-owned cursor and the same session can DROP the table
处置
Rollback the failed transaction to release its cursor and then repeat the DDL; do not hide an active-session dependency with CASCADE.
清理
Close all runner connections and drop the case schema with an owner connection.
同类 SQL 状态码
| 状态码 | 条件名 | 宏名称 | 严重等级 | 版本 |
|---|---|---|---|---|
| 55000 | object_not_in_prerequisite_state | ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE |
ERROR | 7.4 起已知 |
| 对象或服务器未处于操作所需的前置状态。 | 有效 | |||
| 55006 | object_in_use | ERRCODE_OBJECT_IN_USE |
ERROR | 7.4 起已知 |
| 对象正被使用,操作与进行中的占用冲突。 | 有效 | |||
| 55P02 | cant_change_runtime_param | ERRCODE_CANT_CHANGE_RUNTIME_PARAM |
ERROR | 7.4 起已知 |
| 当前上下文或阶段不允许修改该运行时参数。 | 有效 | |||
| 55P03 | lock_not_available | ERRCODE_LOCK_NOT_AVAILABLE |
ERROR | 8.0.0 起已知 |
| 当前等待策略下取不到锁,含 lock_timeout 到期。 | 有效 | |||
| 55P04 | unsafe_new_enum_value_usage | ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE |
ERROR | 12.0 起已知 |
| 同一事务中使用了尚未提交的新增 enum 值。 | 有效 | |||