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

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

百科 / 错误代码 / Class 55 前置状态不满足

55006 object_in_use

对象正在使用

ERROR 已实测 详解 实测通过

类别
Class 55 前置状态不满足
严重等级
ERROR
条件名
object_in_use
宏名称
ERRCODE_OBJECT_IN_USE
启用版本
7.4
状态
活跃

版本覆盖

速览

55006 表示请求的对象操作与正在进行的使用冲突。本页选择显式事务中同一会话的活动 cursor 占用表;数据库用户、逻辑复制和待处理触发器事件是不同路径。

含义

选定的表命令模板为 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 报文可能指明数据库用户或逻辑复制槽等不同阻塞者。

诊断

确认对象和持有使用状态的具体会话或服务器状态。本案例检查显式事务与命名 cursor;若是待处理 trigger event,应完成或回滚排队它们的事务。遇到数据库或复制路径时,应在终止任何会话前检查 pg_stat_activity、复制槽、订阅和维护归属。当前 backend 的 cursor 与其他用户 backend 或逻辑复制槽不是同一种阻塞。

处理

回滚失败的显式事务,让事务拥有的 cursor 和待处理 trigger event 释放,再在明确的维护边界重做 DDL。数据库用户阻塞要协调持有会话,逻辑复制槽则处理订阅/slot 生命周期。不要把 CASCADE 或终止无关会话当作通用处理。

可复现案例

在一次性实例上执行过的场景。其中 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.

实测诊断

选定源码组为 ERROR,操作和关系名是动态字段。实测主报文为 cannot DROP TABLE "cursor_drop_table" because it is being used by active queries in this session;事务进入 INERROR,回滚后恢复为 IDLE

报文模板

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

主消息 source database "%s" is being accessed by other users

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

主消息 database "%s" is used by an active logical replication slot

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

主消息 cannot %s "%s" because it is being used by active queries in this session

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

主消息 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

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

主消息 cannot %s "%s" because it is being used by active queries in this session

来源:src/backend/commands/tablecmds.c @ REL_10_23

代表案例

注册表创建一张空表,在同一后端开启事务、声明并 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作者证据

版本

锁定目录从 7.4 起记录 55006。18.6 与 10.21 的活动 cursor DDL 案例均通过;这不代表数据库、复制或待处理触发器路径。

来源

证据

断言

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

  • 55006 is object_in_use in SQLSTATE Class 55.

    核实方式Read fixed definition.

    来源src/backend/utils/errcodes.txt

  • The cited PostgreSQL 18.6 source paths support the representative resource and object-state mechanisms described.

    核实方式Read complete fixed source contexts.

    不覆盖Source confirmation is not natural runtime.

    来源src/backend/commands/dbcommands.c · src/backend/commands/dbcommands.c · src/backend/commands/tablecmds.c

  • The locked catalogue records 55006 from 7.4; that boundary does not prove exact implementation introduction.

    核实方式Use catalogue boundary.

    来源src/backend/utils/errcodes.txt

  • The selected table-command path reports 55006 when the same session attempts DROP while its transaction-owned cursor still uses the table.

    核实方式Read fixed tablecmds.c source-call records and compare the explicit transaction/cursor case.

    不覆盖Other 55006 branches cover databases, logical replication, and pending trigger events.

    来源src/backend/commands/tablecmds.c · src/backend/commands/tablecmds.c

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

    核实方式Execute the shared registry and inspect SQLSTATE, severity, INERROR to IDLE recovery, DDL repair, cleanup, and target stop.

    不覆盖Scope is one same-session cursor/table path; it does not establish behavior for unrelated database or replication blockers.

    来源verify/cases/55006/cases.json · verify/cases/55006/snippets.json

运行记录

目标服务器版本结果覆盖案例
latest 18.6 (Homebrew) passed active_cursor_drop
pg10 10.21 (Debian 10.21-1.pgdg90+1) passed active_cursor_drop

同类错误代码

Class 55 前置状态不满足 下的其他成员。