Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.5Mb
PDF (A4) - 37.5Mb
PDF (RPM) - 37.1Mb
EPUB - 10.5Mb
HTML Download (TGZ) - 10.3Mb
HTML Download (Zip) - 10.4Mb
HTML Download (RPM) - 9.0Mb
Eclipse Doc Plugin (TGZ) - 11.2Mb
Eclipse Doc Plugin (Zip) - 13.4Mb
Man Pages (TGZ) - 204.0Kb
Man Pages (Zip) - 309.3Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual The metadata_locks Table

As of MySQL 5.7.3, the Performance Schema exposes metadata lock information through the metadata_locks table:

  • Locks that have been granted (shows which sessions own which current metadata locks)

  • Locks that have been requested but not yet granted (shows which sessions are waiting for which metadata locks).

  • Lock requests that have been killed by the deadlock detector or timed out and are waiting for the requesting session's lock request to be discarded

This information enables you to understand metadata lock dependencies between sessions. You can see not only which lock a session is waiting for, but which session currently holds that lock.

The metadata_locks table is read only and cannot be updated. It is autosized by default; to configure the table size, set the performance_schema_max_metadata_locks system variable at server startup.

Metadata lock instrumentation is disabled by default. To enable it, enable the wait/lock/metadata/sql/mdl instrument in the setup_instruments table.

The Performance Schema maintains metadata_locks table content as follows, using the LOCK_STATUS column to indicate the status of each lock:

  • When a metadata lock is requested and obtained immediately, a row with a status of GRANTED is inserted.

  • When a metadata lock is requested and not obtained immediately, a row with a status of PENDING is inserted.

  • When a metadata lock previously requested is granted, its row status is updated to GRANTED.

  • When a metadata lock is released, its row is deleted.

  • When a pending lock request is canceled by the deadlock detector to break a deadlock (ER_LOCK_DEADLOCK), its row status is updated from PENDING to VICTIM.

  • When a pending lock request times out (ER_LOCK_WAIT_TIMEOUT), its row status is updated from PENDING to TIMEOUT.

  • When granted lock or pending lock request is killed, its row status is updated from GRANTED or PENDING to KILLED.

  • The VICTIM, TIMEOUT, and KILLED status values are brief and signify that the lock row is about to be deleted.

  • The PRE_ACQUIRE_NOTIFY and POST_RELEASE_NOTIFY status values are brief and signify that the metadata locking subsubsystem is notifying interested storage engines while entering lock acquisition or leaving lock release operations. These status values were added in MySQL 5.7.11.

The metadata_locks table has these columns:


    The type of lock used in the metadata lock subsystem: The value is one of GLOBAL, SCHEMA, TABLE, FUNCTION, PROCEDURE, TRIGGER (currently unused), EVENT, COMMIT, USER LEVEL LOCK, TABLESPACE, or LOCKING SERVICE.

    A value of USER LEVEL LOCK indicates a lock acquired with GET_LOCK(). A value of LOCKING SERVICE indicates a lock acquired using the locking service described in Section 27.3.1, “The Locking Service”.


    The schema that contains the object.


    The name of the instrumented object.


    The address in memory of the instrumented object.




    The lock duration from the metadata lock subsystem. The value is one of STATEMENT, TRANSACTION, or EXPLICIT. The STATEMENT and TRANSACTION values are for locks that are released at statement or transaction end, respectively. The EXPLICIT value is for locks that survive statement or transaction end and are released explicitly, such as global locks acquired with FLUSH TABLES WITH READ LOCK.


    The lock status from the metadata lock subsystem. The value is one of PENDING, GRANTED, VICTIM, TIMEOUT, KILLED, PRE_ACQUIRE_NOTIFY, or POST_RELEASE_NOTIFY. The Performance Schema assigns these values as described earlier in this section.


    The name of the source file containing the instrumented code that produced the event and the line number in the file at which the instrumentation occurs. This enables you to check the source to determine exactly what code is involved.


    The thread requesting a metadata lock.


    The event requesting a metadata lock.

TRUNCATE TABLE is not permitted for the metadata_locks table.

User Comments
Sign Up Login You must be logged in to post a comment.