← all rules

prefer-bigint-primary-key

warning

Small-integer primary key

Why it's unsafe

A small-integer PRIMARY KEY overflows its id space (int4 at ~2.1 billion rows, int2 at ~32 thousand) — a hard outage once ids run out, with no online fix.

Safe rewrite

Use bigint/bigserial, or GENERATED ALWAYS AS IDENTITY. Migrating a live int primary key to bigint later is a major, painful operation — start with bigint.

Example

Try it in the playground →

Unsafe

CREATE TABLE events (id serial PRIMARY KEY);

Safe

CREATE TABLE events (id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY);

Related