doc/testing-on-replica.md
gh-ost's design allows for trusted and reliable tests of the migration without compromising production data integrity.
Test on replica if you:
gh-ost, have not gained confidence into its workingsTL;DR gh-ost will make all changes on a replica and leave both original and ghost tables for you to compare.
Apply --test-on-replica --host=<a.replica>.
gh-ost would connect to the indicated serverINFORMATION_SCHEMA and SELECT queries run on the replicagh-ost will sync the ghost table with the original table.
STOP SLAVE, stopping replicationYou are now left with the original table and the ghost table. When using a trivial alter statement, such as engine-innodb, both tables should be identical.
You now have the time to verify the tool works correctly. You may checksum the entire table data if you like.
mysql -e 'select * from mydb.mytable order by id' | md5sum
mysql -e 'select * from mydb._mytable_gst order by id' | md5sumengine=innodb for alter when testing. This way the resulting ghost table is identical in structure to the original table (including indexes) and we expect data to be completely identical. We use md5sum on the entire dataset to confirm the test result.gh-ost at the beginning of the migration.It's your job to:
DROP can be a lengthy operation)START SLAVE)Simple:
$ gh-ost --host=myhost.com --conf=/etc/gh-ost.cnf --database=test --table=sample_table --alter="engine=innodb" --chunk-size=2000 --max-load=Threads_connected=20 --initially-drop-ghost-table --initially-drop-old-table --test-on-replica --verbose --execute
Elaborate:
$ gh-ost --host=myhost.com --conf=/etc/gh-ost.cnf --database=test --table=sample_table --alter="engine=innodb" --chunk-size=2000 --max-load=Threads_connected=20 --switch-to-rbr --initially-drop-ghost-table --initially-drop-old-table --test-on-replica --postpone-cut-over-flag-file=/tmp/ghost-postpone.flag --exact-rowcount --concurrent-rowcount --allow-nullable-unique-key --verbose --execute
SELECT COUNT(*) on your table. We use this lovingly.RBR if replica is configured as SBR. See also: migrating with SBRUNIQUE KEY that has NULLable columns (at your own risk)Do not confuse --test-on-replica with --migrate-on-replica; the latter performs the migration and keeps it that way (does not revert the table swap nor stops replication)
As part of testing on replica, gh-ost issues a STOP SLAVE. This requires the SUPER privilege.
See related discussion on https://github.com/github/gh-ost/issues/162