2200HERRORTier 1 — Safe✅ HIGH confidencesequence generator limit exceeded
🔴 Production Risk Error
High: once the sequence is exhausted every INSERT to the table fails until the sequence is altered or the key type is widened.
What this means
SQLSTATE 2200H is raised when a sequence generator has reached its maximum (or minimum for descending sequences) value and cannot produce another value without cycling, and the sequence was created with NO CYCLE.
Why it happens
- 1A SERIAL, BIGSERIAL, or manually created SEQUENCE has exhausted all values in its range
- 2nextval() called on a sequence with MAXVALUE already reached and NO CYCLE set
How to reproduce
Sequence exhausted — all values consumed.
CREATE SEQUENCE tiny_seq MINVALUE 1 MAXVALUE 3 NO CYCLE;
SELECT nextval('tiny_seq'); -- 1
SELECT nextval('tiny_seq'); -- 2
SELECT nextval('tiny_seq'); -- 3
SELECT nextval('tiny_seq'); -- ERROR: 2200HFix 1: Migrate the primary key column from INTEGER/SERIAL to BIGINT/BIGSERIAL
When an integer PK sequence is nearing exhaustion.
ALTER TABLE orders ALTER COLUMN id TYPE BIGINT;
ALTER SEQUENCE orders_id_seq MAXVALUE 9223372036854775807;Why this works
BIGINT sequences have a range of ~9.2 quintillion and are practically inexhaustible for typical workloads.
Fix 2: Reset or recycle the sequence with CYCLE
When sequence values are not used as unique identifiers and cycling is acceptable.
ALTER SEQUENCE my_seq CYCLE RESTART;Why this works
WITH CYCLE causes the sequence to wrap back to MINVALUE after reaching MAXVALUE. Use only when duplicate values are safe.
What not to do
Enable CYCLE on a primary key sequence
Why it's wrong: Cycling causes sequence values to repeat, which violates uniqueness on primary key columns and causes 23505 errors.
Dangerous variant
⚠️ Warning
2200H on a production SERIAL primary key is a live outage — all INSERTs fail
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
📚 Feature docs: https://www.postgresql.org/docs/current/sql-createsequence.html
🔧 Source ref: Class 22 — Data Exception
📖 Further reading: PostgreSQL Sequences
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE for sequence exhaustion. A well-known production pitfall for integer SERIAL primary keys on high-write tables.
See also
📄 Reference pages