Hangi işlemin "Tablo meta veri kilidi bekleniyor" durumuna neden olduğunu nasıl bulabilirim?


99

Bir tabloda bazı DDL gerçekleştirmeye çalışıyorum ve SHOW PROCESSLIST"Tablo meta veri kilidi bekleniyor" mesajıyla sonuçlanıyor.

Hangi işlemin henüz kapanmadığını nasıl öğrenebilirim?

MySQL v5.5.24 kullanıyorum.

Yanıtlar:


153
SHOW ENGINE INNODB STATUS \G

Bölümü arayın -

TRANSACTIONS

INFORMATION_SCHEMA Tablolarını kullanabiliriz .

Yararlı Sorgular

Bekleyen tüm kilit işlemlerini kontrol etmek için:

USE INFORMATION_SCHEMA;
SELECT * FROM INNODB_LOCK_WAITS;

A list of blocking transactions:

SELECT * 
FROM INNODB_LOCKS 
WHERE LOCK_TRX_ID IN (SELECT BLOCKING_TRX_ID FROM INNODB_LOCK_WAITS);

OR

SELECT INNODB_LOCKS.* 
FROM INNODB_LOCKS
JOIN INNODB_LOCK_WAITS
  ON (INNODB_LOCKS.LOCK_TRX_ID = INNODB_LOCK_WAITS.BLOCKING_TRX_ID);

A List of locks on particular table:

SELECT * FROM INNODB_LOCKS 
WHERE LOCK_TABLE = db_name.table_name;

A list of transactions waiting for locks:

SELECT TRX_ID, TRX_REQUESTED_LOCK_ID, TRX_MYSQL_THREAD_ID, TRX_QUERY
FROM INNODB_TRX
WHERE TRX_STATE = 'LOCK WAIT';

Reference - MySQL Troubleshooting: What To Do When Queries Don't Work, Chapter 6 - Page 96.


17
Just a note that all the tables referenced are in the INFORMATION_SCHEMA database.
Michael Mior

10
Do these InnoDB tables really hold information on metatdata locks? This blog post suggests otherwise: mysql.wisborg.dk/2014/01/13/…
Gareth

1
@Gareth : works till mysql -mysql-5-7-3- . Thanks for update.
Joddy

12
all of these had empty sets... yet there's still the lock being shown on processlist...
K2xL

1
Check out the comment below stackoverflow.com/a/36175882/362574
Joddy

52

If you cannot find the process locking the table (cause it is alreay dead), it may be a thread still cleaning up like this

section TRANSACTION of

show engine innodb status;

at the end

---TRANSACTION 1135701157, ACTIVE 6768 sec
MySQL thread id 5208136, OS thread handle 0x7f2982e91700, query id 882213399 xxxIPxxx 82.235.36.49 my_user cleaning up

as mentionned in a comment in Clear transaction deadlock?

you can try killing the transaction thread directly, here with

 KILL 5208136;

worked for me.


12

mysql 5.7 exposes metadata lock information through the performance_schema.metadata_locks table.

Documentation here


6

I had a similar issue with Datagrip and none of these solutions worked.

Once I restarted the Datagrip Client it was no longer an issue and I could drop tables again.


3
restart/reboot - the 100% working solution for any computer issues. However, in Prod, reboots aren't always possible
asgs

2
I had the same problem and closing DataGrip suddenly dropped all of the locks. That's a bunch of wasted time..
ScottBurfieldMills
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.