gitmyhub

gh-ost

Go ★ 13k updated 1d ago

GitHub's Online Schema-migration Tool for MySQL

gh-ost is a tool built by GitHub for changing the structure of a MySQL database table while the database is still live and serving traffic. Databases used by real applications need to be available constantly, but sometimes the table structure needs to change, for example to add a new column or remove an old index. Doing that naively would lock the table and block all users. gh-ost solves that problem.

The standard approach for this kind of live migration involves attaching database triggers, which are rules that fire automatically when data changes. gh-ost takes a different path: it reads the database's internal change log (called the binary log) to track every insert, update, and delete as it happens, and replays those changes onto a new copy of the table it is building in the background. This avoids triggers entirely, which removes a significant source of risk and unpredictable load.

Because gh-ost controls the entire migration process itself, it can truly pause the operation when the database is under heavy load, then resume it without losing any changes. You can also interact with a running migration to check its status, force a pause, or delay the final table swap until you are ready. The final swap, where the old table is replaced by the new one, is the most critical moment and can be scheduled or held back until a convenient time.

The tool supports running the migration against a read replica first as a testing mode. This lets you verify the result and build confidence before touching the main database. GitHub runs their own production tables through this test mode continuously.

gh-ost is open source under the MIT license, written in Go, and available as a pre-built binary for Linux and macOS.