Primary key collision during postgres_fdw migration in Supabase
21.5K reputation · 03 Oct 2025, 09:56 UTC
When migrating data from an external PostgreSQL instance to a Supabase project using the postgres_fdw extension, the transfer of table rows does not automatically synchronize the state of sequence generators.
In a zero-downtime migration strategy, data is pulled into the target Supabase instance while the source continues to accept writes. If the target sequences are not aligned with the maximum values of the imported primary keys, subsequent inserts into the Supabase database may trigger unique constraint violations.
Given the behavior of foreign data wrappers and the managed nature of Supabase PostgreSQL instances, what is the most reliable method to synchronize sequences across all migrated tables without manual per-table scripting? Does Supabase provide a built-in mechanism to update sequence values during an FDW-based import?