SQLSTATE 2200HSeverity mediumLab verified

Incident brief

Sequence reached its maximum value

nextval() fails once a non-cycling sequence hits its MAXVALUE; a sequence capped at 2 raised the limit error on the third call.

What lands in your log

ERROR: nextval: reached maximum value of sequence "order_seq" (2)

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What triggers it
Create or reach a sequence with a low MAXVALUE and no CYCLE.
Fix
Raise the sequence's MAXVALUE (or move the column and sequence to bigint) so it has room to grow.
Proof
Reproduced on PostgreSQL 18.4 → The reproduction exhausts a MAXVALUE-2 sequence: nextval returns 1 then 2, and the third call raises SQLSTATE 2200H.

Fix

What to do right now

Application-level steps for this error.

  • Raise the sequence's MAXVALUE (or move the column and sequence to bigint) so it has room to grow.
  • Add CYCLE only if wrapping is acceptable and duplicate keys are impossible.
Fix SQL
-- Raise the ceiling so the sequence can advance again.
ALTER SEQUENCE order_seq MAXVALUE 1000000;
SELECT nextval('order_seq');

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Verification scope
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops