How to solve MySQL innodb “Waiting for table metadata lock” on TRUNCATE TABLE?

后端 未结 1 434
北荒
北荒 2021-01-31 09:56

Running a test suite with hundreds of application unit tests in a GitLab CI server. After ran 10 tests in, somehow it always gets stuck on Waiting for table metadata lock on TRU

相关标签:
1条回答
  • 2021-01-31 10:26

    The problem here seems straightforward enough.

    ---TRANSACTION 7490, ACTIVE 3047 sec
    MySQL thread id 189, OS thread handle 0x7f03be9fb700, query id 3840 10.0.2.1 root cleaning up
    Trx read view will not see trx with id >= 7491, sees < 7491
    ---
    

    Thread 189 (a client connection) is idle, and as been for a while, but it has left a transaction running. This is probably a bug in the code that's using the database, since it doesn't make sense to leave a running transaction going for almost an hour.

    mysql> KILL 189;
    

    That should release the metadata lock... but you need to find out why this is happening. Bad Things™ will happen if an application doesn't behave better than this.

    Also... your application should not be connecting as root. Not related to the problem, but not good, if that's what this is.

    0 讨论(0)
提交回复
热议问题