---
title: "Postgres Serials Should be BIGINT (and How to..."
url: https://daily.dev/posts/postgres-serials-should-be-bigint-and-how-to--ojm7jfccg
source_url: https://www.crunchydata.com/blog/postgres-serials-should-be-bigint-and-how-to-migrate
type: article
source: "Crunchy Data"
published: 2026-01-20T13:01:24.441Z
updated: 2026-01-20T13:01:44.420Z
tags: ["database", "sql", "postgresql"]
reading_time: 12
upvotes: 11
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Postgres Serials Should be BIGINT (and How to...

**[Crunchy Data](https://daily.dev/sources/crunchydata)** · 12 min read · 11 upvotes · 0 comments

## Summary

PostgreSQL's SERIAL (INT) primary keys risk integer overflow at 2.1 billion rows, but migrating to BIGINT costs virtually nothing due to 8-byte memory alignment. The article provides a complete zero-downtime migration strategy using an atomic swap technique: add a new BIGINT column, backfill data in batches with regular vacuuming, create indexes concurrently, handle foreign key dependencies with NOT VALID constraints, then perform a millisecond metadata swap in a single transaction. Includes production-tested code examples and troubleshooting guidance.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.crunchydata.com/blog/postgres-serials-should-be-bigint-and-how-to-migrate>

## Similar posts on daily.dev

- [Avoid UUID Version 4 Primary Keys](https://daily.dev/posts/avoid-uuid-version-4-primary-keys-5pot7xhqf) · Hacker News · 79 upvotes · 10 comments

---

Tags: [#database](https://daily.dev/tags/database), [#sql](https://daily.dev/tags/sql), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/postgres-serials-should-be-bigint-and-how-to--ojm7jfccg)
