How to fix Sequence generator limit exceeded in PostgreSQL

PostgreSQLINTERMEDIATECRITICALUpdated Dec 28, 2025· 148 views

A PostgreSQL sequence has reached its maximum value, preventing new ID generation. This occurs when SERIAL columns exhaust their 4-byte integer range (~2.1 billion). Fix by altering the sequence to BIGINT or using CYCLE mode.

Quick fix

Fixes 2200H

SELECT sequencename, data_type, last_value, max_value
FROM pg_sequences
WHERE schemaname = 'public';
  1. Check the current sequence state
  2. Alter the sequence to BIGINT
  3. Check the column data type
  4. Test the sequence after alteration
postgresql — error
SELECT sequencename, data_type, last_value, max_value
FROM pg_sequences
WHERE schemaname = 'public';
Sequence generator limit exceeded

What this error means

In PostgreSQL, sequences are database objects that generate unique sequential numbers, commonly used for auto-incrementing primary keys. When a sequence reaches its maximum value limit (determined by its data type), it cannot generate new values and throws the "Sequence generator limit exceeded" error with code 2200H. This typically happens with 4-byte INTEGER sequences that hit their maximum of 2,147,483,647. The sequence is a separate generator object from the column itself, so the error occurs at the sequence level, not necessarily the table column.

Typical symptoms

  • INSERT statements fail with "ERROR: nextval: reached maximum value of sequence"
  • Application cannot create new records with auto-incrementing primary keys
  • Error appears after millions of row insertions in high-volume systems
  • Sequence monitoring shows value near or at maximum for its data type

Common causes

  1. SERIAL column defined with default 4-byte INTEGER instead of BIGINT
  2. Sequence created with smallint or integer data type instead of bigint
  3. High-volume inserts depleting the ~2.1 billion limit of a 4-byte integer sequence
  4. Table resets or identity restarts that did not account for existing max values
  5. Legacy schemas using SERIAL without considering long-term growth

How to fix "Sequence generator limit exceeded"

1Check the current sequence state

Run this query to see sequence details and current value:

sql
SELECT sequencename, data_type, last_value, max_value
FROM pg_sequences
WHERE schemaname = 'public';

Note the data_type and max_value. If data_type is 'integer' or 'smallint', that is your bottleneck.

2Alter the sequence to BIGINT

Convert the sequence to use 64-bit BIGINT (max value ~9.2 quintillion):

sql
ALTER SEQUENCE sequence_name AS BIGINT;

Then verify the change:

sql
SELECT sequencename, data_type, max_value
FROM pg_sequences
WHERE sequencename = 'sequence_name';
3Check the column data type

If the sequence is now BIGINT but the column is still INTEGER, the column must also be widened:

sql
ALTER TABLE table_name
ALTER COLUMN column_name TYPE BIGINT;

This ensures both the sequence and column can handle large values.

4Test the sequence after alteration

Verify that the sequence can now generate new values:

sql
SELECT nextval('sequence_name');

If no error occurs, the issue is resolved. Try inserting a test record to confirm end-to-end functionality.

5Prevent this in the future

For new tables, use BIGSERIAL instead of SERIAL:

sql
-- OLD (limited to 2.1B rows)
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name TEXT
);

-- NEW (supports 9.2 quintillion rows)
CREATE TABLE users (
  id BIGSERIAL PRIMARY KEY,
  name TEXT
);

Alternatively, use SQL standard GENERATED ALWAYS AS IDENTITY:

sql
CREATE TABLE users (
  id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name TEXT
);

Advanced notes

The CYCLE option can be set on sequences to wrap around to the minimum value once maximum is reached (ALTER SEQUENCE sequence_name CYCLE), but this is rarely recommended for primary keys as it can create duplicate values. For tables expecting extremely high row counts (>2.1 billion), BIGINT should be used from inception. The sequence and column data types are independent; a BIGINT sequence can serve an INTEGER column and vice versa, but this mismatch is a source of bugs. Note that sequences are not transactional—once nextval() increments a sequence, that value is consumed even if the transaction rolls back. Monitor sequence exhaustion using: SELECT (last_value::float / max_value::float) * 100 as pct_used FROM pg_sequences WHERE sequencename = "sequence_name";

Frequently asked questions

What does "2200H" mean?
In PostgreSQL, sequences are database objects that generate unique sequential numbers, commonly used for auto-incrementing primary keys. When a sequence reaches its maximum value limit (determined by its data type), it cannot generate new values and throws the "Sequence generator limit exceeded" error with code 2200H. This typically happens with 4-byte INTEGER sequences that hit their maximum of 2,147,483,647.
How do I fix "2200H"?
A PostgreSQL sequence has reached its maximum value, preventing new ID generation. This occurs when SERIAL columns exhaust their 4-byte integer range (~2.1 billion). Fix by altering the sequence to BIGINT or using CYCLE mode.
What causes "2200H"?
SERIAL column defined with default 4-byte INTEGER instead of BIGINT Sequence created with smallint or integer data type instead of bigint High-volume inserts depleting the ~2.1 billion limit of a 4-byte integer sequence
Is the "2200H" error serious?
Yes. This is a critical-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading