Currently viewing the AI version
Switch to human version

gh-ost: MySQL Schema Migration Tool - AI-Optimized Reference

Overview

gh-ost is GitHub's MySQL schema migration tool that uses binary log reading instead of triggers to avoid production failures. Built after pt-online-schema-change caused repeated production outages.

Critical Requirements

  • MySQL Version: 5.7+ only
  • Replication: Row-Based Replication (RBR) required
  • Foreign Keys: Must drop before migration, recreate after
  • Primary Key: Single-column PK or unique index required (no composite keys)

Key Advantages Over pt-online-schema-change

Trigger Problems Solved

  • No Metadata Lock Contention: pt-osc triggers create 30-second operations that become 10-minute deadlocks
  • No Transaction Overhead: pt-osc adds 40-80% performance hit on tables with 10k writes/second
  • Actually Pausable: echo throttle | socat - /tmp/gh-ost.sock stops all writes instantly
  • Safe Failure: Clean artifacts with no data loss vs pt-osc corruption requiring backup restore

Performance Impact

  • gh-ost: 15-20% load on master during migration
  • pt-osc: 40-60% load on busy tables

Critical Failure Modes

Binary Log Position Failures

Error: "Error 1236: Could not find first log file name in binary log index file"
Cause: Binary logs rotated during migration
Prevention: Set expire_logs_days ≥ 7 for large migrations
Recovery: None - restart migration from beginning

MySQL 8.0.28 Connection Killing

Error: "Connection was killed"
Cause: Long-running SELECT queries killed during operations
Solution: Set --mysql-timeout=300

Primary Key Requirements

Error: "Cannot determine table's PRIMARY KEY"
Cause: No PK or composite keys only
Solution: Add surrogate PK column before migration

Performance Benchmarks (Percona 3GB sysbench table)

Load Level pt-osc Performance gh-ost Performance Winner
Idle ~2x faster Baseline pt-osc
Light ~2x faster Baseline pt-osc
Heavy (40% capacity) 12% impact, completed Could not complete pt-osc

Reality: gh-ost's single-threaded binlog processing hits walls on write-heavy workloads

Table Size Limits

  • < 100GB: 2-4 hours, reliable
  • 100GB - 1TB: 8-24 hours, plan carefully
  • > 1TB: Multi-day migrations, high failure risk
  • Largest Success: 5TB table in 3 days

Cloud Provider Gotchas

AWS RDS

  • Requires log_bin_trust_function_creators=1
  • Automated backups interfere with binlog reading
  • Some configurations restrict binlog access

Google Cloud SQL

  • Requires point-in-time recovery enabled
  • Aggressive binlog retention (3 days vs expected 7)

Azure MySQL

  • Requires specific binlog access permissions
  • Documentation insufficient for setup

Manual Cleanup Required

When migrations fail, manual cleanup needed:

DROP TABLE IF EXISTS your_table_gho;  -- Ghost table
DROP TABLE IF EXISTS your_table_ghc;  -- Changelog table

Interactive Commands

  • Pause: echo throttle | socat - /tmp/gh-ost.sock
  • Resume: echo no-throttle | socat - /tmp/gh-ost.sock
  • Status: Various status commands available via socket

When to Use gh-ost vs pt-osc

Use gh-ost When:

  • Safety is priority over speed
  • Need true pause/resume capability
  • Working with tables that have heavy write load
  • Can drop foreign keys
  • Have MySQL 5.7+ with RBR

Use pt-osc When:

  • Foreign keys cannot be dropped
  • Maximum speed required
  • Working with legacy MySQL versions
  • Simple schemas without complex constraints

Common Configuration Flags

  • --max-lag-millis=1500: Pause when replication lag exceeds threshold
  • --chunk-size=1000: Rows copied per operation (increase for better performance)
  • --exact-rowcount: Better progress tracking for large tables
  • --test-on-replica: Safe testing before production run
  • --serve-socket-file: Enable interactive commands

Migration Planning Checklist

Pre-Migration

  1. Verify RBR enabled
  2. Check binary log retention settings
  3. Drop foreign keys
  4. Test on replica first
  5. Plan maintenance window (2-3x estimated time)

During Migration

  1. Monitor replication lag
  2. Watch for binlog rotation
  3. Keep interactive commands ready
  4. Monitor application performance

Post-Migration

  1. Recreate foreign keys
  2. Clean up ghost tables if failed
  3. Verify data integrity
  4. Update application configurations

Resource Requirements

  • Time: 2-3x longer than pt-osc but safer
  • Expertise: Requires understanding of MySQL replication
  • Infrastructure: Replica access for binlog reading

Latest Version

v1.1.7 (December 20, 2024) with performance improvements and bug fixes

Adoption Indicators

  • 12.9k GitHub stars (indicates production battle-testing)
  • Used by GitHub, Shopify, and other high-scale companies
  • Active development and bug fixes

Useful Links for Further Investigation

Docs That Don't Suck

LinkDescription
GitHub RepositoryStart here. This repository has 12.9k stars, indicating that actual people use gh-ost in production and generally find it reliable and effective for their database migration needs.
Latest Release (v1.1.7)Download the binary for the latest release, v1.1.7, which was published on December 20, 2024, and includes important bug fixes that are crucial for stable operation.
Triggerless Design ExplanationUnderstand the unique triggerless design of gh-ost, which differentiates it from other migration tools and is essential knowledge to avoid confusion and debugging issues.
Interactive Commands ReferenceA comprehensive reference for interactive commands, crucial for managing and recovering from complex migration scenarios, as proven during the challenging migration disaster of 2024.
Requirements and LimitationsReview all the critical requirements and potential limitations of gh-ost to understand common pitfalls and avoid unexpected issues or surprises during implementation.
Command-Line FlagsA complete listing of all available command-line flags for gh-ost, essential for configuring and controlling its behavior, though be aware of the extensive number of options.
Testing on ReplicaGuidelines for safely testing gh-ost operations on a replica database, a crucial step to validate changes and prevent production outages before deployment.
AWS RDS ConfigurationSpecific setup instructions for configuring gh-ost with AWS RDS, detailing the necessary steps and outlining any particular limitations that may apply to this environment.
Azure Database for MySQLThis document provides Azure-specific configuration details for integrating gh-ost with Azure Database for MySQL, emphasizing the distinct setup requirements compared to AWS RDS.
Google Cloud SQL GuideThis guide details the process of setting up external replicas for Google Cloud SQL, a necessary step to ensure proper binlog access for gh-ost operations and successful schema migrations.
Percona's gh-ost vs pt-osc BenchmarksDetailed performance benchmarks from Percona comparing gh-ost against pt-online-schema-change, offering objective data to inform your choice of online schema migration tool.
Production Issues and SolutionsA curated list of GitHub issues specifically tagged with production problems, providing insights into common challenges and their solutions encountered by other users.
Common Problems FAQThis community-maintained FAQ provides a comprehensive list of frequent issues encountered with gh-ost, along with practical solutions and fixes to help users quickly resolve common problems.
Bytebase: gh-ost vs pt-osc ComparisonAn updated comparison from 2025 by Bytebase, evaluating gh-ost against pt-online-schema-change and offering practical advice on selecting the appropriate tool for different scenarios.
Vitess Online DDL ComparisonAn analysis of how Vitess's online DDL capabilities compare to gh-ost, specifically focusing on their suitability and performance for large-scale database deployments.
Bytebase gh-ost IntegrationInstructions on how to effectively integrate gh-ost into existing database CI/CD workflows, streamlining online schema migration processes for MySQL databases.
Database Schema Change ManagementThis resource outlines best practices for performing online schema changes in MySQL using gh-ost, providing guidance on establishing robust and reliable processes for production database environments.

Related Tools & Recommendations

tool
Recommended

pt-online-schema-change - The Tool That Prevents 3AM Disaster Calls

Change MySQL table schemas without locking everyone out for 6 hours.

pt-online-schema-change
/tool/pt-online-schema-change/overview
73%
howto
Popular choice

Migrate JavaScript to TypeScript Without Losing Your Mind

A battle-tested guide for teams migrating production JavaScript codebases to TypeScript

JavaScript
/howto/migrate-javascript-project-typescript/complete-migration-guide
57%
tool
Popular choice

jQuery - The Library That Won't Die

Explore jQuery's enduring legacy, its impact on web development, and the key changes in jQuery 4.0. Understand its relevance for new projects in 2025.

jQuery
/tool/jquery/overview
55%
pricing
Recommended

How These Database Platforms Will Fuck Your Budget

compatible with MongoDB Atlas

MongoDB Atlas
/pricing/mongodb-atlas-vs-planetscale-vs-supabase/total-cost-comparison
55%
tool
Recommended

PlanetScale - MySQL That Actually Scales Without The Pain

Database Platform That Handles The Nightmare So You Don't Have To

PlanetScale
/tool/planetscale/overview
55%
compare
Recommended

These 4 Databases All Claim They Don't Suck

I Spent 3 Months Breaking Production With Turso, Neon, PlanetScale, and Xata

Turso
/review/compare/turso/neon/planetscale/xata/performance-benchmarks-2025
55%
tool
Popular choice

OpenAI Browser Implementation Challenges

Every developer question about actually using this thing in production

OpenAI Browser
/tool/openai-browser/implementation-challenges
52%
review
Popular choice

Cursor Enterprise Security Assessment - What CTOs Actually Need to Know

Real Security Analysis: Code in the Cloud, Risk on Your Network

Cursor
/review/cursor-vs-vscode/enterprise-security-review
50%
tool
Popular choice

Istio - Service Mesh That'll Make You Question Your Life Choices

The most complex way to connect microservices, but it actually works (eventually)

Istio
/tool/istio/overview
47%
tool
Recommended

MySQL Replication - How to Keep Your Database Alive When Shit Goes Wrong

depends on MySQL Replication

MySQL Replication
/tool/mysql-replication/overview
45%
compare
Recommended

MongoDB vs PostgreSQL vs MySQL: Which One Won't Ruin Your Weekend

depends on mysql

mysql
/compare/mongodb/postgresql/mysql/performance-benchmarks-2025
45%
alternatives
Recommended

MySQL Alternatives That Don't Suck - A Migration Reality Check

Oracle's 2025 Licensing Squeeze and MySQL's Scaling Walls Are Forcing Your Hand

MySQL
/alternatives/mysql/migration-focused-alternatives
45%
integration
Recommended

GitOps Integration Hell: Docker + Kubernetes + ArgoCD + Prometheus

How to Wire Together the Modern DevOps Stack Without Losing Your Sanity

go
/integration/docker-kubernetes-argocd-prometheus/gitops-workflow-integration
45%
alternatives
Recommended

MongoDB Alternatives: Choose the Right Database for Your Specific Use Case

Stop paying MongoDB tax. Choose a database that actually works for your use case.

MongoDB
/alternatives/mongodb/use-case-driven-alternatives
45%
integration
Recommended

Kafka + MongoDB + Kubernetes + Prometheus Integration - When Event Streams Break

When your event-driven services die and you're staring at green dashboards while everything burns, you need real observability - not the vendor promises that go

Apache Kafka
/integration/kafka-mongodb-kubernetes-prometheus-event-driven/complete-observability-architecture
45%
tool
Recommended

GitHub Desktop - Git with Training Wheels That Actually Work

Point-and-click your way through Git without memorizing 47 different commands

GitHub Desktop
/tool/github-desktop/overview
45%
compare
Recommended

AI Coding Assistants 2025 Pricing Breakdown - What You'll Actually Pay

GitHub Copilot vs Cursor vs Claude Code vs Tabnine vs Amazon Q Developer: The Real Cost Analysis

GitHub Copilot
/compare/github-copilot/cursor/claude-code/tabnine/amazon-q-developer/ai-coding-assistants-2025-pricing-breakdown
45%
integration
Recommended

I've Been Juggling Copilot, Cursor, and Windsurf for 8 Months

Here's What Actually Works (And What Doesn't)

GitHub Copilot
/integration/github-copilot-cursor-windsurf/workflow-integration-patterns
45%
pricing
Popular choice

What Enterprise Platform Pricing Actually Looks Like When the Sales Gloves Come Off

Vercel, Netlify, and Cloudflare Pages: The Real Costs Behind the Marketing Bullshit

Vercel
/pricing/vercel-netlify-cloudflare-enterprise-comparison/enterprise-cost-analysis
45%
tool
Popular choice

MariaDB - What MySQL Should Have Been

Discover MariaDB, the powerful open-source alternative to MySQL. Learn why it was created, how to install it, and compare its benefits for your applications.

MariaDB
/tool/mariadb/overview
42%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization