Range partition on created_at
CREATE TABLE adk_events (
id bigserial NOT NULL,
session_id uuid,
event_type text,
payload jsonb,
created_at timestamptz NOT NULL,
PRIMARY KEY (id, created_at)
) PARTITION BY RANGE (created_at);
CREATE TABLE adk_events_2026_07 PARTITION OF adk_events
FOR VALUES FROM ('2026-07-01') TO ('2026-08-01');Advertisement
Automate partition creation
Cron job (or pg_partman) creates next month's partition ahead of time. Never let a write hit a missing partition — that's an outage.
Advertisement
Detach + drop old partitions
Retention becomes cheap. ALTER TABLE ... DETACH PARTITION then DROP. Millisecond operation vs hours-long DELETE.