2200H — sequence_generator_limit_exceeded
nextval 触及序列的最大值或最小值。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Data Exception
- condition name
- sequence_generator_limit_exceeded
- lang
- en
- sqlstate
- 2200H
版本定义 PG 18
2200H
速览 {#at-a-glance}
序列在尝试取得下一个值时遇到了配置的边界。PostgreSQL 18.6 的 sequence.c 路径同时有最大值和最小值的源码模板;端点值本身可以是合法返回值。数值使用 C 的 PRId64 格式宏,因此源码写法是 nextval: reached maximum value of sequence "%s" (%" PRId64 ")(最小值形式相应替换为 minimum),不能把它误写成字面量 (%s) 占位符。这里的限制属于序列属性,不是一般整数溢出。
含义 {#meaning}
本条件表示 nextval 的 fetch loop 无法在配置的最小值或最大值之外再分配下一个值。在递增路径中,源码检查最大值边界;在递减路径中,源码检查最小值边界。触及边界时,若 rescnt > 0,循环会先停止并返回已经取得的合法值;只有没有可返回结果时,未启用 CYCLE 的分支才报告 2200H。启用 CYCLE 时,固定源码会绕回另一个配置端点。这是序列边界策略,不是一般整数溢出。
报文 {#messages}
未启用循环的递增 guard 以 ERROR 报告 primary 源码模板 nextval: reached maximum value of sequence "%s" (%" PRId64 ");递减 guard 使用 nextval: reached minimum value of sequence "%s" (%" PRId64 ")。端点本身不是错误:如果 fetch loop 已取得合法结果,会先停止抓取而不进入错误分支。PRId64 是拼接进已编译数值占位符的 C 格式宏,最终显示的数字是运行时限制值。引用分支没有独立 DETAIL 或 HINT。
诊断 {#diagnosis}
检查报文点名的序列、步长、MINVALUE/MAXVALUE、CYCLE 设置以及调用是否为 nextval,先判断触及的是最大值还是最小值、是否仍有合法端点或缓存值可返回,以及循环是否是有意策略。CYCLE 只是序列策略,不是所有生成 ID 的通用修复:开启它可能与依赖键冲突,或违反应用的分配约束。若不应循环,应在核对依赖键后选择安全的新范围、调整序列或轮换到新序列。
处理 {#response}
有意修复序列策略:核对键语义后调整安全限制、决定是否启用 CYCLE,或迁移到新序列。重复同一个 nextval、转换其结果或把本码当成整数溢出,都不能越过固定端点。
该分支抛出 ERROR 时,显式事务应先用 ROLLBACK 恢复,或对语句前已建立的保存点执行 ROLLBACK TO SAVEPOINT,再重试;自动提交下只在失败语句结束后重试修正后的动作。事务边界规则见事务与重试指南。
版本 {#versions}
锁定目录从 10.0 起记录该条件;固定源码覆盖 PostgreSQL 18.6。
相关 {#related}
来源 {#sources}
固定源码:src/backend/commands/sequence.c#L731-769。结构化证据记录保留两种端点报文和范围边界。固定源码确认递增/递减 guard、CYCLE 回绕和 C 的 PRId64 格式宏;序列名和限制值是运行时字段。锁定目录从 10.0 起记录该条件,但不据此断言精确的实现引入提交。
比较版本
SQLSTATE 证据与已记录的运行版本
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read fixed definition.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "2200H is sequence_generator_limit_exceeded in SQLSTATE Class 22."
}claims · mechanism.sequence-limit
{
"claim_id": "mechanism.sequence-limit",
"limits": "The endpoint value can be a legal returned value, and CYCLE is a sequence policy choice rather than a universal repair for exhausted identifiers.",
"method": "Read the full fetch loop and both boundary branches.",
"position": 1,
"runtime": [],
"sources": [
"src.path.sequence-limit"
],
"statement": "The nextval fetch loop checks the configured maximum for ascending sequences and minimum for descending sequences; at a boundary, rescnt \u003e 0 stops fetching so already fetched legal values can be returned, while a non-cycling branch with no result left emits 2200H and cycle=true wraps to the opposite bound."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue boundary.",
"position": 2,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 2200H from 10.0 without proving an exact implementation introduction date."
}messages · message.sequence-max
{
"limits": "",
"message_id": "message.sequence-max",
"path": "",
"position": 0,
"raw": {
"id": "message.sequence-max",
"primary_template": "nextval: reached maximum value of sequence \"%s\" (%\" PRId64 \")",
"severity_source": "ERROR",
"sources": [
"src.path.sequence-limit"
],
"sqlstate": "2200H"
},
"severity": "ERROR",
"sources": [
"src.path.sequence-limit"
],
"templates": [
{
"kind": "primary",
"literal": "nextval: reached maximum value of sequence \" \" (%\" PRId64 \")",
"position": 0,
"role": "",
"template": "nextval: reached maximum value of sequence \"%s\" (%\" PRId64 \")"
}
]
}messages · message.sequence-min
{
"limits": "",
"message_id": "message.sequence-min",
"path": "",
"position": 1,
"raw": {
"id": "message.sequence-min",
"primary_template": "nextval: reached minimum value of sequence \"%s\" (%\" PRId64 \")",
"severity_source": "ERROR",
"sources": [
"src.path.sequence-limit"
],
"sqlstate": "2200H"
},
"severity": "ERROR",
"sources": [
"src.path.sequence-limit"
],
"templates": [
{
"kind": "primary",
"literal": "nextval: reached minimum value of sequence \" \" (%\" PRId64 \")",
"position": 0,
"role": "",
"template": "nextval: reached minimum value of sequence \"%s\" (%\" PRId64 \")"
}
]
}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#L198"
}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.path.sequence-limit
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/commands/sequence.c",
"position": 2,
"sha256": "3e5afe17d5a84862fae502a5481211220368f1d639e9d07ba6f96ee8be92a8d8",
"source_id": "src.path.sequence-limit",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/sequence.c#L731-L769"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:640cad37338e76c017d5d085a0536697c488996cabff80be92d0e9ba4a69113a
正文语言: zh-Hans · english-manuals:640cad37338e76c017d5d085a0536697c488996cabff80be92d0e9ba4a69113a