1

I'm trying to alter a pretty large table (25GB including index) by adding a column & modifying an index, but in addition to taking a very long time (> 1 hour), which is ok, it affects the whole system, making queries on other tables more than 100 times slower, which is a huge issue and forced me to cancel the operation.

The server is pretty solid (196GB RAM with only 70GB used, SSD RAID disks with 300GB free space). Storage engine is MyISAM.

Is there any way to give the ALTER TABLE very low priority so that it doesn't dramatically affect the rest of the operations (I don't care if it takes twice the time)? Is it even normal that it does?

asked Sep 27, 2016 at 8:02
4
  • Create a copy of the table and modify the copy. Then drop the original table and rename the copy to the same name as the table. Commented Sep 27, 2016 at 8:38
  • well alter table on MyISAM would held a table level lock, would recommend using table switching technique instead as suggested by @Andew Commented Sep 27, 2016 at 9:15
  • 1- During the altering process, do you write to this table, or only read? 2- Provide show create table table_name result please. Commented Sep 27, 2016 at 15:48
  • I was actually using the switching technique so that the table is not used at all (neither read nor written to) during the process, the problem is that it slows down the whole server, even queries to unrelated tables Commented Sep 28, 2016 at 11:52

2 Answers 2

1

Use pt-online-schema-change. It will monitor server load and throttle itself if necessary.

answered Sep 28, 2016 at 0:31
4
  • Or github.com/github/gh-ost, github.com/soundcloud/lhm Commented Sep 28, 2016 at 2:19
  • Never heard of ihn. Also pt-osc will refuse to alter if there are triggers in a table. Gh-ost is triggerless Commented Sep 28, 2016 at 2:23
  • LHM - it's ruby gem, uses triggers. Commented Sep 28, 2016 at 2:33
  • Seems like a pretty handy tool, will take a look at it, thanks! Commented Sep 28, 2016 at 11:57
2

Upgrade to InnoDB. Tips and caveats

Upgrade to at least 5.6

After those, you can do most ALTERs with almost no downtime. See ALGORITHM=INPLACE.

answered Sep 28, 2016 at 3:42
2
  • Thanks, useful link - unfortunately I can't switch engine for now, because of disk space among other things Commented Sep 28, 2016 at 12:13
  • A common space waster is using BIGINT (8 bytes) when TINYTINT (1 byte) would suffice. And there are others. Let's see SHOW CREATE TABLE`. How much RAM do you have? Commented Sep 28, 2016 at 15:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.