Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17
2200H (sequence_generator_limit_exceeded) means nextval() was called on a sequence that already reached its maximum. The message shows the sequence name and limit, e.g. reached maximum value of sequence "logs_id_seq" (2147483647). 2147483647 is the int limit, which serial and int identity columns use.
Check the sequence type and max with pg_sequence or pg_sequences. Below are three cases reproduced on PostgreSQL 17 with the fixes that were actually run.
01serial (int) column ran out of numbers
logs.id is serial, so its sequence is integer with seqmax 2147483647. After the last value was used, the next INSERT failed with 2200H.
Changing both the column and the sequence to bigint fixed it: ALTER TABLE logs ALTER COLUMN id TYPE bigint; and ALTER SEQUENCE logs_id_seq AS bigint;. The same INSERT then returned id 2147483648.
Setup
CREATE TABLE logs (id serial PRIMARY KEY, msg text);
SELECT setval('logs_id_seq', 2147483646);
INSERT INTO logs (msg) VALUES ('last one');CREATE TABLE
setval
------------
2147483646
(1 row)
INSERT 0 1INSERT INTO logs (msg) VALUES ('next');ERROR: 2200H: nextval: reached maximum value of sequence "logs_id_seq" (2147483647)SELECT seqtypid::regtype, seqmax FROM pg_sequence WHERE seqrelid = 'logs_id_seq'::regclass; seqtypid | seqmax
----------+------------
integer | 2147483647
(1 row)ALTER TABLE logs ALTER COLUMN id TYPE bigint;
ALTER SEQUENCE logs_id_seq AS bigint;ALTER TABLE
ALTER SEQUENCEChanging the column type rewrites the whole table and locks it while running. Plan it for a maintenance window on large tables.
INSERT INTO logs (msg) VALUES ('next') RETURNING id; id
------------
2147483648
(1 row)
INSERT 0 102A sequence created with a small MAXVALUE
invoice_no_seq was created with MAXVALUE 999. After 998 and 999 were used, nextval failed with 2200H. pg_sequences showed last_value 999, max_value 999, cycle f.
ALTER SEQUENCE invoice_no_seq MAXVALUE 9999; raised the limit and the next call returned 1000.
Setup
CREATE SEQUENCE invoice_no_seq START 998 MAXVALUE 999;
SELECT nextval('invoice_no_seq');
SELECT nextval('invoice_no_seq');CREATE SEQUENCE
nextval
---------
998
(1 row)
nextval
---------
999
(1 row)SELECT nextval('invoice_no_seq');ERROR: 2200H: nextval: reached maximum value of sequence "invoice_no_seq" (999)SELECT last_value, max_value, cycle FROM pg_sequences WHERE sequencename = 'invoice_no_seq'; last_value | max_value | cycle
------------+-----------+-------
999 | 999 | f
(1 row)ALTER SEQUENCE invoice_no_seq MAXVALUE 9999;ALTER SEQUENCECYCLE would restart from the minimum instead, but then old numbers are reused. Do not use it for IDs or invoice numbers.
SELECT nextval('invoice_no_seq'); nextval
---------
1000
(1 row)03int GENERATED AS IDENTITY column reached 2147483647
An identity column has its own sequence (events_id_seq here). The int column reached 2147483647 and the next INSERT failed with the same 2200H.
ALTER TABLE events ALTER COLUMN id TYPE bigint; and ALTER TABLE events ALTER COLUMN id SET MAXVALUE 9223372036854775807; let the INSERT continue with id 2147483648.
Setup
CREATE TABLE events (id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, kind text);
ALTER TABLE events ALTER COLUMN id RESTART WITH 2147483647;
INSERT INTO events (kind) VALUES ('login');CREATE TABLE
ALTER TABLE
INSERT 0 1INSERT INTO events (kind) VALUES ('logout');ERROR: 2200H: nextval: reached maximum value of sequence "events_id_seq" (2147483647)ALTER TABLE events ALTER COLUMN id TYPE bigint;
ALTER TABLE events ALTER COLUMN id SET MAXVALUE 9223372036854775807;ALTER TABLE
ALTER TABLEINSERT INTO events (kind) VALUES ('logout') RETURNING id; id
------------
2147483648
(1 row)
INSERT 0 1FAQ
What does reached maximum value of sequence mean in PostgreSQL?
nextval() was called after the sequence already returned its MAXVALUE. For serial and int identity columns the limit is 2147483647.
How do I change a serial column to bigint?
Run ALTER TABLE t ALTER COLUMN id TYPE bigint; and ALTER SEQUENCE t_id_seq AS bigint;. In the first case the next id was 2147483648.
How do I check how close a sequence is to its limit?
Query pg_sequences (last_value, max_value) or pg_sequence (seqtypid, seqmax). The second case showed last_value 999 and max_value 999.
Should I use CYCLE to avoid 2200H?
Only when reusing numbers is fine. For primary keys it leads to duplicate key errors later; raise MAXVALUE or move to bigint instead.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12