简体   繁体   English

MySQL 24x7-InnoDB ALTER TABLE块(TABLE LOCK)

[英]MySQL 24x7 - InnoDB ALTER TABLE blocks (TABLE LOCK)

we are trying to minimize (maintenance) downtimes of our mysql based application. 我们正在尝试最小化(维护)基于mysql的应用程序的停机时间。

It seems that InnoDB hotbackup will give us the possibility to do regular backups without stopping the server; 看来,InnoDB热备份将使我们能够不停止服务器而进行常规备份。 Master/Slave replication will give us failover capabilities (loosing a few seconds of data due to replication lag is not great, but not a showstopper also). 主/从复制将为我们提供故障转移功能(由于复制滞后而丢失几秒钟的数据虽然不大,但也不是问题)。

So far for backup and unexpected downtimes. 到目前为止,用于备份和意外停机。 Now to expected downtimes - 现在到预期的停机时间-

As far as I understand from reading online documentation and books an ALTER TABLE on an InnoDB table will require a TABLE LOCK thus blocking all reads and writes to this table. 据我阅读在线文档和书籍了解,在InnoDB表上的ALTER TABLE将需要一个TABLE LOCK,从而阻止对该表的所有读写。 Effectively this will mean downtime to the application. 实际上,这将意味着应用程序停机。 Some large tables may take hours to be updated. 一些大表可能需要几个小时才能更新。

Are there any known workarounds to this? 有任何已知的解决方法吗? The perfect workaroudn would be of course a non-blocking ALTER TABLE. 完美的工作方式当然是一个无阻塞的ALTER TABLE。 But anything to make ALTER TABLE faster is also interesting. 但是,使ALTER TABLE更快的任何事情也很有趣。

Thanks in advance! 提前致谢!

PS - commercial (non-free) tools would be ok also, free solutions are of course also welcome PS-商业(非免费)工具也可以,当然也欢迎免费解决方案

Since you have replication setup, it is normally possible to do some trickery with ALTER TABLE on the slave, let the slave catchup after it is done, swap roles, and then ALTER on the former master. 由于您具有复制设置,通常可以对从属服务器上的ALTER TABLE进行一些技巧,让从属服务器在完成后进行追赶,交换角色,然后在前一个主服务器上进行ALTER。 This doesn't work for all ALTER TABLE commands, but it can handle the majority of them. 这不适用于所有ALTER TABLE命令,但可以处理其中的大多数命令。

There is also a third-party tool at here , but I'm not sure how commonly it is used, how well it works, etc... 还有一个第三方工具在这里 ,但我不知道它是如何普遍使用,以及它如何工作的,等...

The best workaround would be to not alter your tables. 最好的解决方法是不更改表。

The only time a schema change should be required is if you're adding functionality, or somehow forgot an index. 只有当您要添加功能或以某种方式忘记了索引时,才需要更改架构。

If you're adding functionality, you'll likely have downtime anyway, to stage your production server. 如果要添加功能,则无论如何都可能会停机,以准备生产服务器。

If you forgot an index, then the database is likely slow anyway, so your users shouldn't mind downtime to fix the performance issue. 如果您忘记了索引,那么数据库无论如何都可能变慢,因此您的用户不应该介意停机以解决性能问题。 You should run all you queries through an EXPLAIN to make sure you have the proper indexes declared already. 您应该通过EXPLAIN运行所有查询,以确保已经声明了正确的索引。

If you're afraid that you'll be altering tables frequently you might want to re-examine your schema. 如果您担心会经常更改表,则可能需要重新检查架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM