sluice

Staged (wave) migration — a few tables at a time

Move your biggest or most self-contained tables first, cut them over, then bring the rest across in later waves.

Not every migration wants to be one event. On a large database it is often safer to move the biggest or most self-contained tables first, cut the application over for just those, let them bake in production for a while, then bring the rest across in later waves. Each wave is small enough to reason about, and a problem in wave 3 doesn't implicate the tables that have been running fine since wave 1.

sluice supports this today. This guide covers the two mechanisms, which one to use on which source engine (they are not interchangeable), how foreign keys constrain your wave ordering, and the one thing sluice deliberately does not do: replicate writes back from the target to the source.

Two mechanisms #

One growing streamSeveral independent streams
Shapea single --stream-id whose table scope expandsone --stream-id per wave, running side by side
Add a wave withsluice schema add-tableanother sluice sync start
Cut overall tables together, at the endper wave, independently
Postgres sourcesupportedsupported — needs a per-stream --publication-name
MySQL / PlanetScale / Vitess sourcesupportedsupported

The distinction that matters is whether you need to cut waves over independently. If the point of staging is to de-risk the copy — everything lands eventually, in one cutover, but you'd rather not snapshot 4 TB in a single run — use one growing stream. If the point is to de-risk the cutover — wave 1 serving production traffic from the target while wave 2 is still copying — you need independent streams. Both source families support that; a Postgres source additionally needs a per-stream --publication-name (below).

Mechanism A — one growing stream #

Start a stream scoped to your first wave, then extend its scope as you go. The stream keeps one CDC position, one slot, one control-state row.

sluice sync start \
    --source-driver postgres --source "$SRC" \
    --target-driver postgres --target "$DST" \
    --include-table 'orders,order_items' \
    --stream-id appdb

Later, bring users into the same stream. Stop the stream, add the table, then start the stream again, keeping it stopped until schema add-table returns — on every source, Postgres included (see the note below):

sluice sync stop --stream-id appdb \
    --target-driver postgres --target "$DST" --wait

sluice schema add-table users \
    --source-driver postgres --source "$SRC" \
    --target-driver postgres --target "$DST" \
    --stream-id appdb

sluice sync start \
    --source-driver postgres --source "$SRC" \
    --target-driver postgres --target "$DST" \
    --include-table 'orders,order_items' \
    --stream-id appdb

schema add-table creates the table on the target, bulk-copies its rows from a consistent snapshot, extends the source publication, and records the table in the stream's scope; the restarted stream warm-resumes from its position and replays what changed during the add. At a terminal it prompts for typed confirmation (the table name) unless you pass --yes; on a non-terminal stdin it refuses SLUICE-E-CONFIRMATION-REQUIRED (exit 3) before touching anything.

--no-drain is refused on every source (v0.163.10). It exits 1 before anything is read or written, on a dry run too, and names the drained workflow: a Postgres source refuses with NO-DRAIN-POSTGRES-SOURCE, a MySQL or MariaDB binlog source with NO-DRAIN-BINLOG-SOURCE and a PlanetScale/Vitess (VStream) source with NO-DRAIN-VSTREAM-SOURCE (both since v0.163.8), and a trigger-CDC source takes the generic refusal. Correction (2026-10-23): this page used to present --no-drain on a Postgres source (the new table joins the source publication, ADR-0030) as a zero-loss way to add to a running stream. It was not: from v0.24.0 through v0.163.9 a Postgres --no-drain add lost or undid changes made to the new table during the add, at exit 0 (Bug 332, CRITICAL, silent; how to check and re-copy a table added that way is there). The binlog and VStream live paths lost changes too (v0.163.8). The drained workflow is sluice sync stop --wait, then schema add-table, then sluice sync start again (a re-run with the same --stream-id warm-resumes and replays what changed during the add; it does not re-snapshot), or for a sluice sync run fleet leg, the fleet's own restart, which starts the leg from its config. It is measured from MySQL, MariaDB, Vitess and, since v0.163.10, Postgres sources, including on Postgres the changes committed between the stop and the publication add and a transaction that straddles it: exact for inserts, updates and deletes; primary-key changes on the added table during the add are not covered (Bugs 333/336, open). Until the fix, avoid primary-key changes on the table being added from sluice sync stop until add-table returns. Keep the stream stopped until schema add-table returns, with no fleet reload and no supervisor or systemd restart in between: add-table does not detect a stream that is still running, and an add against one loses the same changes (DRAINED-ADD-TABLE-RUNNING-STREAM-UNCHECKED, open). Since v0.163.0 every add, on every source and path, records the table in the stream's live-added set, writing a pending entry with a 30-second heartbeat first; a failed add takes back its Postgres publication add, and an add superseded by --abandon or by another add-table run stops with PENDING-ADD-SUPERSEDED and cancels its copy. A SQLite or D1 target keeps no live-added set (the add WARNs), and an add of a table a running stream excludes, which only an add against a stream nobody stopped can be, makes the stream stop with LIVE-ADDED-TABLE-EXCLUDED.

users stays in the stream (v0.163.0). The add records users in the stream's live-added set (live_added_tables) on every source, and every later start admits it whatever --include-table says — so re-running the same sync start --include-table 'orders,order_items' keeps streaming users. Only sluice schema add-table --abandon users --yes takes it back out (or --reset-target-data, which discards the whole set); an --exclude-table naming it refuses with LIVE-ADDED-TABLE-EXCLUDED. Through v0.162.0 a restart on a Postgres source, or after any drained add, silently stopped applying users at the dispatch filter; if you ran this flow on an older release, compare users against the source (details and repair).

On a restart, --include-table cannot add a table: a warm resume copies nothing, so widening it to a table the stream never copied refuses with INCLUDE-TABLE-SCOPE-DRIFT. Use schema add-table. One table per invocation; repeat it per table or script the loop. On a Postgres source this is the mechanism that grows scope safely — it extends the publication additively, so it can't disturb tables already in scope.

Mechanism B — several independent streams #

Each wave gets its own --stream-id, its own CDC position, and — on engines with a replication-slot concept — its own --slot-name. The waves are fully independent: you cut wave 1 over and stop its stream while wave 2 is still snapshotting.

# Wave 1 — cut over first, weeks before the rest.
sluice sync start \
    --source-driver mysql    --source "$SRC" \
    --target-driver postgres --target "$DST" \
    --include-table 'orders,order_items' \
    --stream-id wave1

# Wave 2 — started later, runs alongside wave 1.
sluice sync start \
    --source-driver mysql    --source "$SRC" \
    --target-driver postgres --target "$DST" \
    --include-table 'users,sessions' \
    --stream-id wave2

--include-table is comma-separated, repeatable, and glob-aware (audit_*), and it scopes both legs — the cold-start snapshot and the live CDC apply. CDC state is keyed per stream, so waves never contend for position. On a MySQL-family source each stream opens its own binlog / VStream reader and there is no shared server-side object to collide over.

Why Postgres needs two per-stream names #

On a Postgres source each wave needs both --slot-name and --publication-name:

sluice sync start \
    --source-driver postgres --source "$SRC" \
    --target-driver postgres --target "$DST_WAVE1" \
    --include-table 'orders,order_items' \
    --stream-id wave1 --slot-name wave1 --publication-name wave1

--slot-name is the obvious one: without it every stream lands on the default sluice_slot and they collide immediately — a loud, hard-to-miss failure.

--publication-name is the one that matters more, because forgetting it used to fail silently. The replication slot is per-stream, but the publication — the table filter pgoutput applies — is a separate object, and streams that share one fight over it: each cold start scopes the publication to its own table list with ALTER PUBLICATION … SET TABLE …, which replaces the member set atomically. Two waves sharing the default sluice_pub would de-scope each other, leaving the first wave's slot healthy and advancing while it received nothing for its tables.

sluice will not let that happen quietly. A cold start that would remove tables from a publication while another sluice slot exists on the same database of that source refuses with SLUICE-E-CDC-PUBLICATION-SCOPE-CONFLICT, naming the at-risk tables and the conflicting slot (labeled active or inactive) — and refuses before mutating anything, so a refused attempt leaves every running stream untouched. Existence, not activity, is the signal (v0.99.289): an inactive slot is a stream someone stopped mid-migration that will resume expecting its scope, so merely stopping a wave doesn't release its claim — decommissioning it does: once a wave is finished for good, sluice sync decommission drops its slot and per-stream publication and clears its control row in one gated command. Widening or equal-scope rescopes remove nothing and never trigger it, so a fleet of same-scope streams and schema add-table are unaffected. Since v0.163.0 only slots on the publication's own database count: a slot on another database of the same server cannot read the publication, so a stream there no longer triggers the refusal.

Both flags share the sluice_ prefix convention — wave1 becomes sluice_wave1 — so every sluice-owned source object is findable the same way: pg_replication_slots WHERE slot_name LIKE 'sluice\_%' and pg_publication WHERE pubname LIKE 'sluice\_%'. MySQL, PlanetScale, and Vitess sources have neither object and ignore both flags.

Foreign keys decide your wave ordering #

This constrains wave composition more than table size does. A wave-1 table with a foreign key pointing at a wave-2 table cannot have that constraint created — the referenced table isn't on the target yet. Two ways through:

This is a different situation from row-level filtering, which orphans children of rows that were filtered out and refuses loudly. See Copy a subset of tables if you're staging by rows rather than by tables.

Cutting a wave over #

Per wave, the sequence is the standard cutover scoped to that wave's tables:

# 1. Prime the target's identity columns past the source's high-water mark.
sluice cutover \
    --source-driver mysql    --source "$SRC" \
    --target-driver postgres --target "$DST" \
    --include-table 'orders,order_items' \
    --sequence-margin=1000

# 2. Flip application traffic for these tables. (Your step, not sluice's.)

# 3. Drain and stop this wave's stream.
sluice sync stop \
    --target-driver postgres --target "$DST" \
    --stream-id wave1 --wait

# 4. Prove it landed (row counts; --depth=sample is same-engine only).
sluice verify \
    --source-driver mysql    --source "$SRC" \
    --target-driver postgres --target "$DST" \
    --include-table 'orders,order_items' --depth=count

cutover takes --include-table too, so a wave's sequences get primed without touching tables that are still source-authoritative. Skipping it is the classic staged-migration failure: application writes to the target start allocating IDs that collide with rows CDC is about to deliver.

Use --wait on sync stop. Without it the stop is asynchronous and late in-flight changes may not have landed.

Split-brain is yours to prevent #

sluice doesn't own the traffic switch — the cutover moment is application-specific. The consequence is that sluice cannot tell whether a wave's tables are still being written on the source.

If writes keep landing on the source after you've cut a wave over, CDC faithfully replicates them on top of the application's writes to the target. Per row, last writer wins, and nothing surfaces as an error — this is the one place in a staged migration where you can lose data quietly. The stream is doing exactly what you asked; the problem is upstream of it.

The only real protection is on the source side, at the moment of cutover: revoke INSERT/UPDATE/DELETE on the wave's tables from the application role, install a rejecting trigger, or take the source write path out of the application entirely for those tables. "We updated the config and believe nothing writes there any more" is not protection — make the source refuse.

What sluice does not do: write-back to the source #

Some managed-import products keep a reverse stream running after cutover, so writes landing on the new database replicate back to the old one and you can fail back if the new database can't take the load. sluice has no equivalent today, and it isn't a small gap.

The blocker is that sluice's CDC apply path carries no origin marker — nothing says "this change is one I applied, don't re-emit it." A reverse sync start running alongside a forward one is therefore a replication loop.

There is a narrower version the wave design makes tractable, worth understanding even though it is not a supported feature: once a wave is cut over and its forward stream is stopped, nothing is streaming those tables source to target any more, so a reverse stream scoped to exactly that wave's tables is table-disjoint from every live forward stream and isn't a loop. What still stands in the way: the source's identity columns would need priming past the target's; a cross-engine reverse needs a reverse-direction schema that round-trips, which the forward migration doesn't guarantee; and it has never been tested. It is a plausible composition of shipped primitives, not a validated path.

If you need genuine fail-back today, keep the source authoritative until you're confident: cut a wave's reads over first, leave writes on the source, and move writes only once the target has proven itself under real read load. That captures most of the risk reduction without a reverse stream.

Choosing waves: a checklist #

  1. Draw the FK graph. It constrains ordering more than size does. Parents before children; note the cycles that will need --skip-foreign-keys.
  2. Prefer self-contained clusters. A wave whose tables reference only each other cuts over cleanly and can be verified in isolation.
  3. Put the scariest table in wave 1, not last. The point of staging is to learn early, on the table most likely to surprise you, while the blast radius is smallest and rollback is still just "keep using the source."
  4. On a Postgres source, set --slot-name AND --publication-name per wave. Independent per-wave cutover needs Mechanism B, and on Postgres both per-stream names are required for it to be correct. sluice refuses loudly if you forget, but it is cheaper to pass them up front.
  5. Decide the write fence per wave before you start, not at the cutover window.
  6. Budget the stream count. Each concurrent wave is a full CDC reader (and on Postgres, a slot). A handful is fine; dozens is not a design, it's a load test.

Next steps #