# Error while optimize table

**URL:** <https://forums.percona.com/t/error-while-optimize-table/1469>\
**Category:** Other MySQL® Questions\
**Created:** [August 5, 2010, 9:46pm UTC](https://forums.percona.com/t/error-while-optimize-table/1469 "2010-08-05T21:46:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gjuan](https://avatars.discourse-cdn.com/v4/letter/g/53a042/32.png) [@gjuan](https://forums.percona.com/u/gjuan)\
**Post date:** [August 5, 2010, 9:46pm UTC](https://forums.percona.com/t/error-while-optimize-table/1469/1 "2010-08-05T21:46:51Z")

</div>

Hi,

I have a innodb table with around 60000000 of rows, when i execute optimize table, i obtain the next error:

±----------------------±---------±---------±------------ -------------------------------------------+  
| Table | Op | Msg\_type | Msg\_text |  
±----------------------±---------±---------±------------ -------------------------------------------+  
| table | optimize | error | Lock wait timeout exceeded; try restarting transaction |  
| table | optimize | status | Operation failed |  
±----------------------±---------±---------±------------ -------------------------------------------+  
2 rows in set, 1 warning (23 min 56.01 sec)

While the optimize was executing some other transactions try to insert in the table and they became locked because table was in use.

is there any variable to tuning to avoid this problem?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![yogesh77](https://avatars.discourse-cdn.com/v4/letter/y/f08c70/32.png) [@yogesh77](https://forums.percona.com/u/yogesh77)\
**Post date:** [August 12, 2010, 2:24pm UTC](https://forums.percona.com/t/error-while-optimize-table/1469/2 "2010-08-12T14:24:11Z")

</div>

optimize operation needs a lock on table, so you cant optimize tables in real time application.  
You can setup a slave and execute optimization on slave and promote optimized slave as master.

---

<div class="post-metadata">

**Author:** ![brooksie](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@brooksie](https://forums.percona.com/u/brooksie)\
**Post date:** [August 25, 2010, 5:40am UTC](https://forums.percona.com/t/error-while-optimize-table/1469/3 "2010-08-25T05:40:01Z")

</div>

We were experiencing an issue with one of our tables where every update resulted in a lock wait timeout. One option we tried in order to resolve this was to optimize the table, however this also resulted in a lock wait time out despite no other operations being made on the table at the same time.

My next attempts where to flush and check the table, which seemed fine, and may have resolved the issue but we went straight on to create a copy of the table, via dump and import and rename the tables effectively replacing the old one with the new one.

This seems to have resolved the issue for the time being and updates are being made in a timely fashion again.

version: 5.0.85-community  
tx\_isolation read committed
