↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

2200H — sequence_generator_limit_exceeded

A sequence allocation reached its configured limit while trying to obtain the next value. PostgreSQL 18.6’s sequence.c path reports source templates for both maximum and minimum limits. The endpoint value itself can be legal, and the numeric value uses the C PRId64 format macro, so the source spelling is nextval: reached maximum value of sequence "%s" (%" PRId64 ") (and the corresponding minimum form), not a literal (%s) placeholder. The limit is a sequence property, not a generic integer overflow.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Data Exception
condition name
sequence_generator_limit_exceeded
lang
en
sqlstate
2200H

Definition PG 18

2200H

At a glance {#at-a-glance}

A sequence allocation reached its configured limit while trying to obtain the next value. PostgreSQL 18.6’s sequence.c path reports source templates for both maximum and minimum limits. The endpoint value itself can be legal, and the numeric value uses the C PRId64 format macro, so the source spelling is nextval: reached maximum value of sequence "%s" (%" PRId64 ") (and the corresponding minimum form), not a literal (%s) placeholder. The limit is a sequence property, not a generic integer overflow.

Meaning {#meaning}

This condition means the nextval fetch loop cannot allocate the next value past a configured sequence minimum or maximum. In the ascending path, PostgreSQL checks the maximum boundary; in the descending path, it checks the minimum. At a boundary, rescnt > 0 stops the fetch loop so already fetched legal values can be returned; only when no result remains does the non-cycling branch raise 2200H. With CYCLE, the fixed source wraps to the opposite configured endpoint. This is sequence boundary policy, not a generic integer overflow.

Messages {#messages}

The non-cycling ascending guard raises ERROR with primary source template nextval: reached maximum value of sequence "%s" (%" PRId64 "); the descending guard uses nextval: reached minimum value of sequence "%s" (%" PRId64 "). The endpoint itself is not inherently an error: if the fetch loop already has a legal result, it stops fetching before the error branch. PRId64 is a C format macro concatenated into the compiled numeric placeholder, so the displayed number is a runtime limit value. The cited branches have no separate DETAIL or HINT.

Diagnosis {#diagnosis}

Inspect the named sequence, increment, MINVALUE/MAXVALUE, CYCLE setting, and whether the call was nextval. Determine whether the endpoint is maximum or minimum, whether a legal endpoint or cached value was still available, and whether cycling deliberately wraps. CYCLE is a sequence policy, not a universal repair for generated identifiers: changing it can create values that collide with dependent keys or violate an application’s allocation contract. If cycling is not intended, choose a new range, alter the sequence, or rotate to a new sequence after checking dependent keys.

Response {#response}

Repair the sequence policy deliberately: adjust a safe limit, enable or disable CYCLE only after checking key semantics, or migrate allocation to a new sequence. Repeating the same nextval, casting its result, or treating this as an integer overflow cannot advance past a fixed endpoint.

When this branch raises ERROR, an explicit transaction must first be recovered with ROLLBACK or ROLLBACK TO SAVEPOINT for a savepoint established before the statement; in autocommit, retry only the corrected action after the failed statement completes. See the transaction and retry guide for this boundary rule.

Versions {#versions}

The locked catalogue records this condition from 10.0; fixed source coverage is PostgreSQL 18.6.

Related {#related}

22003, 22000

Sources {#sources}

Fixed source: src/backend/commands/sequence.c#L731-769. The structured evidence record retains both limit messages and scope boundaries. The fixed source confirms the ascending and descending guards, CYCLE wrap, and C PRId64 format macro; the exact sequence name and limit are runtime values. Source presence begins at 10.0 in the locked catalogue, without asserting the precise implementation introduction commit.

Compare versions

SQLSTATE evidence and recorded runtime versions

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"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:640cad37338e76c017d5d085a0536697c488996cabff80be92d0e9ba4a69113a

Text language: en · english-manuals:640cad37338e76c017d5d085a0536697c488996cabff80be92d0e9ba4a69113a