PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL 2200H: nextval: reached maximum value of sequence

The sequence behind the column already returned its MAXVALUE, so nextval() cannot give a new number.

PostgreSQL 17.12
2200H: nextval: reached maximum value of sequence "logs_id_seq" (2147483647)

Jump to a cause

  1. 01serial (int) column ran out of numbers
  2. 02A sequence created with a small MAXVALUE
  3. 03int GENERATED AS IDENTITY column reached 2147483647

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
Setuprun as lab_a
CREATE TABLE logs (id serial PRIMARY KEY, msg text);
SELECT setval('logs_id_seq', 2147483646);
INSERT INTO logs (msg) VALUES ('last one');
OUTPUT
CREATE TABLE
   setval
------------
 2147483646
(1 row)

INSERT 0 1
Reproducerun as lab_a
INSERT INTO logs (msg) VALUES ('next');
✕ ERROR
ERROR:  2200H: nextval: reached maximum value of sequence "logs_id_seq" (2147483647)
Checkrun as lab_a
SELECT seqtypid::regtype, seqmax FROM pg_sequence WHERE seqrelid = 'logs_id_seq'::regclass;
OUTPUT
 seqtypid |   seqmax
----------+------------
 integer  | 2147483647
(1 row)
Fixrun as lab_a
ALTER TABLE logs ALTER COLUMN id TYPE bigint;
ALTER SEQUENCE logs_id_seq AS bigint;
OUTPUT
ALTER TABLE
ALTER SEQUENCE

Changing the column type rewrites the whole table and locks it while running. Plan it for a maintenance window on large tables.

After the fixrun as lab_a
INSERT INTO logs (msg) VALUES ('next') RETURNING id;
✓ SUCCESS
     id
------------
 2147483648
(1 row)

INSERT 0 1

02A 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
Setuprun as lab_a
CREATE SEQUENCE invoice_no_seq START 998 MAXVALUE 999;
SELECT nextval('invoice_no_seq');
SELECT nextval('invoice_no_seq');
OUTPUT
CREATE SEQUENCE
 nextval
---------
     998
(1 row)

 nextval
---------
     999
(1 row)
Reproducerun as lab_a
SELECT nextval('invoice_no_seq');
✕ ERROR
ERROR:  2200H: nextval: reached maximum value of sequence "invoice_no_seq" (999)
Checkrun as lab_a
SELECT last_value, max_value, cycle FROM pg_sequences WHERE sequencename = 'invoice_no_seq';
OUTPUT
 last_value | max_value | cycle
------------+-----------+-------
        999 |       999 | f
(1 row)
Fixrun as lab_a
ALTER SEQUENCE invoice_no_seq MAXVALUE 9999;
OUTPUT
ALTER SEQUENCE

CYCLE would restart from the minimum instead, but then old numbers are reused. Do not use it for IDs or invoice numbers.

After the fixrun as lab_a
SELECT nextval('invoice_no_seq');
✓ SUCCESS
 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
Setuprun as lab_a
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');
OUTPUT
CREATE TABLE
ALTER TABLE
INSERT 0 1
Reproducerun as lab_a
INSERT INTO events (kind) VALUES ('logout');
✕ ERROR
ERROR:  2200H: nextval: reached maximum value of sequence "events_id_seq" (2147483647)
Fixrun as lab_a
ALTER TABLE events ALTER COLUMN id TYPE bigint;
ALTER TABLE events ALTER COLUMN id SET MAXVALUE 9223372036854775807;
OUTPUT
ALTER TABLE
ALTER TABLE
After the fixrun as lab_a
INSERT INTO events (kind) VALUES ('logout') RETURNING id;
✓ SUCCESS
     id
------------
 2147483648
(1 row)

INSERT 0 1

FAQ

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