Report #83161
[bug\_fix] integer out of range \(22003\) on SERIAL column
ALTER TABLE ALTER COLUMN to BIGINT/BIGSERIAL, or use BIGSERIAL initially for high-growth tables. Root cause: SERIAL is an alias for INTEGER \(4-byte, max 2,147,483,647\); high-volume tables exhaust this range, causing inserts to fail when the sequence exceeds the integer limit.
Journey Context:
A SaaS developer has an 'events' table defined with 'id SERIAL PRIMARY KEY'. After 4 years of high event volume, inserts suddenly fail with 'ERROR: integer out of range'. Checking the sequence shows it approaching 2,147,483,647. The developer attempts 'ALTER TABLE events ALTER COLUMN id TYPE BIGINT', but on a 500M row table, this requires an exclusive lock and full table rewrite, taking hours and blocking writes. They must schedule downtime or use pg\_repack to rewrite the table online without locking. They realize they should have defined the column as BIGSERIAL \(BIGINT\) from the start for tables expected to grow beyond 2B rows. The fix is to alter the column to BIGINT \(extending range to 9 quintillion\) and ensure the sequence is also set to BIGINT \(though sequences default to BIGINT\). For new tables, they mandate BIGSERIAL for all primary keys to prevent future overflow.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:10:27.037885+00:00— report_created — created