Glossary

sequence resync

Sequence resync sets a table's Postgres sequence to the maximum existing id after an import, so the next auto-generated id does not collide with a row you inserted.

sequence resync is the step that sets a table's Postgres sequence to the current maximum id after rows are imported with explicit ids, so the next INSERT does not reuse a value that already exists.

When you copy data with the id column included, Postgres writes those literal values but never advances the backing sequence. The sequence still points at wherever the empty destination left it (often 1). The next insert that relies on the default calls nextval(), gets a value already present, and fails against the primary key:

ERROR: duplicate key value violates unique constraint "buckets_pkey"

See /errors/duplicate-key-buckets-pkey for the full shape of that unique violation.

The fix is one statement per table with a serial or IDENTITY column. pg_get_serial_sequence resolves the sequence name so you do not hard-code it, and setval moves it past the largest id in the table:

SELECT setval(
  pg_get_serial_sequence('public.buckets', 'id'),
  (SELECT max(id) FROM public.buckets)
);

Run this after the data load, once per table, before the destination takes live traffic. It is part of finishing a clean schema replay — the DDL is not enough on its own. SupaMigrate runs the resync automatically after the data step, iterating every table that owns a sequence.

Related terms