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

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

百科 / 错误代码 / Class 28 授权规范无效

28000 invalid_authorization_specification

授权规范无效

ERROR 已实测 详解 实测通过

类别
Class 28 授权规范无效
严重等级
ERROR
条件名
invalid_authorization_specification
宏名称
ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION
启用版本
7.4
状态
活跃

版本覆盖

速览

SQLSTATE 28000 是 Class 28 中的 invalid_authorization_specification28000 是被拒绝的启动或授权上下文所属的类别。选定的角色不存在启动路径在建立会话前发送 C=28000、S=FATAL 以及 role "<generated>" does not exist;固定认证路径还在证书、pg_hba 和 LOGIN 资格失败时使用本类的具体报文。

含义

本类覆盖建立或认证连接时被拒绝的授权上下文。选定分支是启动阶段的角色查找:服务器无法为请求角色创建会话,于是发送 FATAL ErrorResponse。证书、pg_hba 和 LOGIN 资格路径仍是同一类别下的不同 producer。

选定的角色查找发生在后端进入普通会话之前。这解释了 FATAL 级别以及失败尝试没有会话级事务。不要把它与 28P01(密码认证失败)、42501(会话建立后的权限不足)或 3D000(数据库选择)混在一起;应由启动阶段和服务器字段确定分支。

启动分支指引

检查内容 选定的角色缺失分支 Class 28 的其他可能性
服务器字段 C=28000S=FATALM=role "%s" does not exist 保留服务器实际返回的代码和主报文,不能只按类别推断。
会话状态 失败尝试没有可用会话,也没有事务 后续授权检查可能发生在已建立会话中,恢复边界不同。
修复 按意图创建/重命名角色,或修正启动用户,然后重新连接 根据实际诊断修正证书、pg_hba.conf、LOGIN 属性或映射。

诊断

以服务器 ErrorResponse 或认证日志作为 SQLSTATE 依据,并先判断阶段:角色查找、pg_hba 规则、证书,还是 LOGIN 权限。选定的 collector 是原始服务器 ErrorResponse 记录,不是 csvlog/jsonlog;原始启动尝试与 psycopg 尝试彼此独立。选定运行中 psycopg 报告的驱动 SQLSTATE 为 null,失败连接没有事务;两个独立的新鲜已知角色探针仍能执行 SELECT 1,这不是日志采集器关联结论。

对于角色不存在,使用独立管理会话对照请求的启动用户和角色目录,并检查引号或大小写折叠。保留原始 CSM 字段:psycopg 的 null 只说明它自己的失败启动尝试,不表示服务器没有 SQLSTATE。新鲜探针必须是另一条连接,不能把失败尝试变成可回滚的事务。

处理

按服务器指出的原因修正角色、LOGIN/映射、证书或 pg_hba 规则,再建立新连接。失败启动连接上没有可供 ROLLBACK 的会话;没有服务器字段时不能仅凭客户端异常认定 28000,也不要盲目重放非幂等启动工作。

角色或认证配置改变后,使用准确的目标用户和数据库重新连接,并在新会话中确认身份。如果应用已经在另一条连接上发送了工作,应单独核对那部分工作;启动前的 FATAL 本身没有可重试的业务事务。

可复现案例

在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。

invalid_authorization PG 10 / 18 有 SQL

前置条件

  • A runner-owned disposable target is provisioned.

触发

Attempt startup as a generated role that does not exist, then probe a known owner connection.

断言

  • The selected server diagnostic has the expected SQLSTATE
  • The selected recovery/probe assertions pass
  • Runner-owned resources are cleaned up

处置

Follow the case-specific repair statements and verify the resulting state.

清理

Drop the case schema with an owner connection.

实测诊断

选定的启动角色分支以 FATAL 发出主报文 role "%s" does not exist,角色名是动态值。Class 28 的其他授权失败可能使用不同主报文。由于客户端没有得到可用会话 SQLSTATE,应以服务器 ErrorResponse 为准。

选定服务器记录为 role "u28000_missing_fbc912bb7e6f" does not exist,角色名是本次运行生成的值。原始 ErrorResponse 与 psycopg 的 null 属于两次独立启动尝试,不能拼成同一会话的两种视图。

报文模板

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

代表案例

注册表包含服务器启动 ErrorResponse 后执行的探针。触发点是在新启动连接上使用随机角色,失败发生在会话建立前,不能用 SQL 语句重现。

SELECT 1;

18.6 服务器 ErrorResponse 为 C=28000、S=FATALrole "u28000_missing_fbc912bb7e6f" does not exist。驱动启动诊断的 SQLSTATE 为 null,失败连接没有事务;已知可用连接探针返回 1,状态 IDLE

可下载的案例与证据投影分别是 28000 案例 JSON作者证据。运行器清单为 verify/cases/28000/cases.json;发布前会将页面 SQL 与共享注册表比对。

版本

上面的生成事实表记录锁定的目录快照和最早观察到的定义。本页自然运行范围是 PostgreSQL 18.6 与 10.21,不能据此推断所有中间版本的行为。

来源

证据

断言

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

  • 28000 is the invalid_authorization_specification condition in Class 28.

    核实方式Read the fixed errcodes.txt definition and the locked catalogue metadata.

    不覆盖Directory identity does not identify every backend or client path.

    来源src/backend/utils/errcodes.txt

  • The fixed source paths associated with 28000 report the condition in the mechanism selected for this page.

    核实方式Trace the resolved source call records at the fixed release commits and compare their dynamic message fields.

    不覆盖Other calls can retain the same SQLSTATE with different context or text.

    来源src/backend/utils/init/miscinit.c · src/backend/utils/init/miscinit.c

  • The selected invalid_authorization case passed with the expected structured diagnostics, recovery assertions, and cleanup on PostgreSQL 18.6 and 10.21.

    核实方式Run the shared registry case on isolated runner-owned latest and PG10 targets; inspect the final summaries and raw results.

    不覆盖This covers the selected case and versions only; it does not generalize to every driver, proxy, or intermediate release.

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

  • The selected missing-role producer runs during startup, emits a FATAL ErrorResponse, and leaves no usable session or transaction; the server ErrorResponse is therefore authoritative over a client exception with SQLSTATE null.

    核实方式Compare the fixed miscinit.c source path with the selected raw server ErrorResponse and independent driver/probe observations.

    不覆盖This is the selected missing-role startup branch; other Class 28 producers can occur in different authentication phases and use different diagnostics.

    来源src/backend/utils/init/miscinit.c

  • The locked catalogue records 28000 in the listed snapshots; the runtime comparison here is limited to PostgreSQL 18.6 and 10.21.

    核实方式Read the generated facts block and locked manifest, then compare the selected target summaries.

    不覆盖Presence in a definition file is not an exact behavioral introduction; the two runtime targets do not prove all middle versions.

    来源src/backend/utils/errcodes.txt · raw/calls/REL_18_6.jsonl · raw/calls/REL_10_23.jsonl

运行记录

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

同类错误代码

Class 28 授权规范无效 下的其他成员。