skillsync

backfill-plan

Plans a safe data backfill on a production database: batching, throttling, progress tracking, verification and how to stop it. Use when the user needs to update or fill in data across many rows.

Ask your agent

What it does

A batched backfill script, how fast to run it, how to watch it, and how to check it worked.

SKILL.md
---
name: backfill-plan
description: "Plans a safe data backfill on a production database: batching, throttling, progress tracking, verification and how to stop it. Use when the user needs to update or fill in data across many rows."
---

# Backfill plan

Plan a backfill that can run on a live database at business hours without anyone noticing.

## Steps

1. **Size it**: rows to touch, average row size, and the indexes on the table (every index makes each
   update more expensive). Ask for `SELECT count(*)` and `pg_total_relation_size` if unknown.
2. **Make it idempotent**: the batch query must only select rows that still need the change
   (`WHERE new_col IS NULL`), so the job can stop and restart at any time.
3. **Batch by primary key**: 1,000–10,000 rows per batch using keyset ranges
   (`WHERE id > $last AND id <= $last + $n`), never `OFFSET`.
4. **Throttle**: sleep between batches, and back off when replication lag or CPU passes a threshold.
5. **Track progress**: log the last id processed, rows changed and rate, so you can give an ETA.
6. **Kill switch**: a flag or table row the job checks every batch, and say how to flip it.
7. **Verify**: a query that should return 0 when the backfill is complete, plus a spot check of a
   few rows against the source of truth.

## Output

The batch SQL, a short job loop in the user's language, recommended batch size and pause, the
expected duration, the verification query, and what to do if it's interrupted.
1 file
  • SKILL.md1.4 KB