MySQL Online Schema Change Plan Prompt
Plan a zero-downtime schema change on a large table using gh-ost or pt-online-schema-change.
- Target user
- DBAs and engineers running ALTERs on large production tables
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior MySQL/MariaDB DBA who runs online schema changes on large tables without downtime. You know gh-ost (binlog-based, triggerless) and pt-online-schema-change (trigger-based), their ghost/shadow-table-plus-cut-over model, foreign-key handling, throttling on replica lag, and the failure modes of each. I will provide: - The desired change: [PASTE ALTER TABLE STATEMENT] - `SHOW CREATE TABLE` for the target (size, indexes, foreign keys, triggers): [PASTE SCHEMA] - Approximate row count / table size on disk and current write rate: [PASTE] - Topology: replicas, whether the app tolerates a brief metadata-lock cut-over, and any existing triggers/FKs: [DESCRIBE] Produce a migration plan: 1. **Pick the tool.** Recommend gh-ost or pt-online-schema-change for this table and justify it — gh-ost if you want triggerless binlog-based copy and pausable migrations; pt-osc if gh-ost can't run here. Call out foreign keys and existing triggers explicitly, since they constrain both tools. 2. **Assess the change's safety.** Is it instant/in-place (some ALTERs are metadata-only) or a full table rebuild? Does it risk data loss (narrowing a column, NOT NULL on existing nulls, charset change)? 3. **Define throttling.** Set max replica lag and load thresholds so the copy backs off automatically and never starves the primary or blows out replication lag. 4. **Write the exact command** (gh-ost or pt-osc) with flags: dry-run first, throttle controls, chunk size, and cut-over behaviour. Include the --execute step separately so the dry-run is reviewed first. 5. **Plan the cut-over and rollback.** Describe the brief lock at swap time, how to abort mid-migration, and how to keep/drop the old table for a safe rollback window. Output: (a) Tool choice with rationale, (b) Safety assessment of the ALTER, (c) Dry-run command, (d) Execute command with throttling, (e) Cut-over and rollback plan, (f) Risks. Guardrails: always run a dry-run / --no-swap first and review it; back up the table before executing; throttle on replica lag so replicas never fall dangerously behind; foreign keys and triggers can make these tools unsafe — verify before running; keep the old table until you have confirmed success; never execute a real cut-over on prod without review.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
A naive ALTER TABLE on a large InnoDB table can lock writes for minutes or hours, so production schema changes go through gh-ost or pt-online-schema-change. But those tools are not magic — they each have sharp edges around foreign keys, triggers, and lossy column changes. This prompt makes the model choose the right tool for the specific table and justify it, rather than defaulting to whichever one it saw most in training data.
It separates two things people conflate: the safety of the tool and the safety of the change. An online migration executed flawlessly can still destroy data if the ALTER itself narrows a column or converts a charset. By demanding an independent safety assessment of the ALTER — instant vs full rebuild, lossy vs not — the prompt catches the failure mode that the tooling cannot protect you from.
The operational guardrails mirror how careful DBAs actually run these: dry-run first, throttle on replica lag so the copy never starves the primary or stalls replication, and keep the old table around for a rollback window. Splitting the dry-run and execute commands into separate reviewable steps, plus an explicit cut-over and abort plan, keeps a human in control at the exact moment — the swap — where a mistake is hardest to undo.
Related prompts
-
MySQL utf8mb4 Charset Migration Prompt
Plan a safe migration from utf8/latin1 to utf8mb4 across server, databases, tables, columns, and connections.
-
MySQL 5.7 to 8.0 Upgrade Readiness Prompt
Build a safe, staged plan to upgrade MySQL 5.7 to 8.0 (or MariaDB across majors): run the upgrade checker, surface removed/changed defaults, reserved words and collation pitfalls, and sequence the cutover with a rollback path.
-
MySQL InnoDB Buffer Pool Warmup Prompt
Configure buffer-pool dump/restore so a restarted or failed-over MySQL instance serves warm-cache latency immediately instead of a cold-cache stall.
-
MySQL caching_sha2_password Auth Migration Prompt
Plan migrating accounts from mysql_native_password to caching_sha2_password without locking out legacy drivers or non-TLS clients.
More MySQL prompts & error guides
Browse every MySQL prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.