tags:

views:

149

answers:

2

Hello,

we are trying to minimize (maintenance) downtimes of our mysql based application.

It seems that InnoDB hotbackup will give us the possibility to do regular backups without stopping the server; 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. 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. But anything to make ALTER TABLE faster is also interesting.

Thanks in advance!

PS - commercial (non-free) tools would be ok also, free solutions are of course also welcome

+1  A: 

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.

If you're afraid that you'll be altering tables frequently you might want to re-examine your schema.

Ben S
The application servers are not an issue since they are already clustered. So a schema update would actually precede the application update and no maintenance downtime is required for the application side.It's all about adding functionality. I think it's fair to require ALTER TABLEs for new functions.
filibuster
To be precise - I'm only talking about ALTER TABLE .. add column
filibuster
+1  A: 

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. This doesn't work for all ALTER TABLE commands, but it can handle the majority of them.

There is also a third-party tool at here, but I'm not sure how commonly it is used, how well it works, etc...

Harrison Fisk
Thanks, we've been thinking about that, and as of now, this seems the only option. But the system would still be in a read-only state during the ALTER TABLE, or am I missing something?
filibuster
Hello, I've just noticed that you've provided a link to a tool/script which does indeed allow "Online ALTER TABLE" as they call it - thanks a lot !
filibuster